gym-examples 3.0.222__py3-none-any.whl → 3.0.224__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
gym_examples/__init__.py CHANGED
@@ -6,4 +6,4 @@ register(
6
6
  max_episode_steps=50,
7
7
  )
8
8
 
9
- __version__ = "3.0.222"
9
+ __version__ = "3.0.224"
@@ -16,7 +16,7 @@ output_dim = 1 # final reward
16
16
 
17
17
  Eelec = 50e-9 # energy consumption per bit in joules
18
18
  Eamp = 100e-12 # energy consumption per bit per square meter in joules
19
- info_amount = 3072 # data size in bits
19
+ info_amount = 512 # data size in bits
20
20
  initial_energy = 1 # initial energy of each sensor (in joules)
21
21
  lower_bound = 0 # lower bound of the sensor positions
22
22
  upper_bound = 100 # upper bound of the sensor positions
@@ -24,9 +24,6 @@ base_station_position = np.array([(upper_bound - lower_bound)/2, (upper_bound -
24
24
  initial_number_of_packets = 1 # initial number of packets to transmit
25
25
  latency_per_hop = 1 # latency per hop in seconds
26
26
 
27
- coef_network_throughput = 2.6 # coefficient for the network throughput reward
28
- coef_packet_delivery_ratio = 1.6 # coefficient for the packet delivery ratio reward
29
-
30
27
  base_back_up_dir = "results/data/"
31
28
  max_reward = 5 # maximum reward value when the sensors sent data to the base station. The opposite value is when the sensors perform an unauthorized action
32
29
 
@@ -134,13 +131,14 @@ class WSNRoutingEnv(gym.Env):
134
131
  actions = [actions[i] for i in range(self.n_agents)] # We want to go back from the MultiDiscrete action space to a tuple of tuple of Discrete action spaces
135
132
  self.steps += 1
136
133
  rewards = [-max_reward] * self.n_sensors
134
+ # rewards = [0] * self.n_sensors
137
135
  dones = [False] * self.n_sensors
138
136
  for i, action in enumerate(actions):
139
137
  if action not in range(self.n_sensors + 1):
140
138
  raise ValueError("Invalid action!")
141
139
 
142
140
  if i >= self.n_sensors:
143
- continue # Skip if the number of actions is greater than the number of sensors
141
+ raise ValueError("Invalid sensor index!") # the number of actions is greater than the number of sensors
144
142
 
145
143
  if self.remaining_energy[i] <= 0 or self.number_of_packets[i] <= 0:
146
144
  continue # Skip if sensor has no energy left or no packets to transmit
@@ -155,6 +153,7 @@ class WSNRoutingEnv(gym.Env):
155
153
  # Calculate the energy consumption for transmitting data to the base station
156
154
  transmission_energy = self.transmission_energy(self.number_of_packets[i], self.distance_to_base[i])
157
155
  if self.remaining_energy[i] < transmission_energy:
156
+ self.remaining_energy[i] = 0
158
157
  continue # Skip if the sensor does not have enough energy to transmit data to the base station
159
158
 
160
159
  self.update_sensor_energies(i, transmission_energy)
@@ -167,7 +166,8 @@ class WSNRoutingEnv(gym.Env):
167
166
  self.packet_latency[i] = 0
168
167
 
169
168
  # rewards[i] = self.compute_individual_rewards(i, action)
170
- rewards[i] = np.ones(input_dim) * max_reward # Reward for transmitting data to the base station
169
+ # rewards[i] = np.ones(input_dim) * max_reward # Reward for transmitting data to the base station
170
+ rewards[i] = np.ones(input_dim) # Reward for transmitting data to the base station
171
171
  dones[i] = True
172
172
  else:
173
173
  distance = np.linalg.norm(self.sensor_positions[i] - self.sensor_positions[action])
@@ -176,8 +176,13 @@ class WSNRoutingEnv(gym.Env):
176
176
 
177
177
  transmission_energy = self.transmission_energy(self.number_of_packets[i], distance)
178
178
  reception_energy = self.reception_energy(self.number_of_packets[i])
179
- if self.remaining_energy[i] < transmission_energy or self.remaining_energy[action] < reception_energy:
180
- continue
179
+ if self.remaining_energy[i] < transmission_energy:
180
+ self.remaining_energy[i] = 0
181
+ continue # Skip if the sensor does not have enough energy to transmit data to the next hop
182
+ if self.remaining_energy[action] < reception_energy:
183
+ self.number_of_packets[i] = 0
184
+ self.remaining_energy[action] = 0
185
+ continue # Skip if the next hop does not have enough energy to receive data
181
186
 
182
187
  self.update_sensor_energies(i, transmission_energy)
183
188
  self.update_sensor_energies(action, reception_energy)
@@ -453,14 +458,6 @@ class WSNRoutingEnv(gym.Env):
453
458
  maximum_throughput = self.n_sensors * initial_number_of_packets
454
459
  normalized_throughput = network_throughput / (maximum_throughput + self.epsilon)
455
460
  return np.clip(normalized_throughput, 0, 1)
456
-
457
- def compute_weighted_sum_rewards(self, rewards):
458
- '''
459
- Compute the weigthed sum of the rewards
460
- '''
461
- weights = np.array([1, 1, 1, 1, 1, coef_network_throughput, coef_packet_delivery_ratio])
462
- return np.dot(rewards, weights) / np.sum(weights)
463
- # return np.sum(rewards)
464
461
 
465
462
  def compute_attention_rewards(self, rewards):
466
463
  '''
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: gym-examples
3
- Version: 3.0.222
3
+ Version: 3.0.224
4
4
  Summary: A custom environment for multi-agent reinforcement learning focused on WSN routing.
5
5
  Home-page: https://github.com/gedji/CODES.git
6
6
  Author: Georges Djimefo
@@ -0,0 +1,7 @@
1
+ gym_examples/__init__.py,sha256=O3Do7Y6dV9a8VGxnVg0jOzmDPuyv0ISI_7DQcCG8Ihs,194
2
+ gym_examples/envs/__init__.py,sha256=lgMe4pyOuUTgTBUddM0iwMlETsYTwFShny6ifm8PGM8,53
3
+ gym_examples/envs/wsn_env.py,sha256=ykllANFl8ORgtX7T9HgcIgsnsAW-2bH0wxk-5tWu0Ng,26381
4
+ gym_examples-3.0.224.dist-info/METADATA,sha256=2TY7rpy6ZJpqn7-jkVnfLsPekbtOoTmJdk1miX5Ckk8,412
5
+ gym_examples-3.0.224.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
6
+ gym_examples-3.0.224.dist-info/top_level.txt,sha256=rJRksoAF32M6lTLBEwYzRdo4PgtejceaNnnZ3HeY_Rk,13
7
+ gym_examples-3.0.224.dist-info/RECORD,,
@@ -1,7 +0,0 @@
1
- gym_examples/__init__.py,sha256=ZfjhPAT6w-L2SDjh1MPbA--styy5hpQquFcUXJygFLQ,194
2
- gym_examples/envs/__init__.py,sha256=lgMe4pyOuUTgTBUddM0iwMlETsYTwFShny6ifm8PGM8,53
3
- gym_examples/envs/wsn_env.py,sha256=HwisiCG_Q6xWufQnA-M_UjhLJdrPGAjkgV-C--84J90,26298
4
- gym_examples-3.0.222.dist-info/METADATA,sha256=4jNKl6QaBZqaDszpNsBkXil0NmdQpBnh0WE6hfIntbg,412
5
- gym_examples-3.0.222.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
6
- gym_examples-3.0.222.dist-info/top_level.txt,sha256=rJRksoAF32M6lTLBEwYzRdo4PgtejceaNnnZ3HeY_Rk,13
7
- gym_examples-3.0.222.dist-info/RECORD,,