gym-examples 3.0.766__py3-none-any.whl → 3.0.768__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
@@ -5,4 +5,4 @@ register(
5
5
  entry_point="gym_examples.envs:WSNRoutingEnv",
6
6
  )
7
7
 
8
- __version__ = "3.0.766"
8
+ __version__ = "3.0.768"
@@ -150,7 +150,7 @@ class WSNRoutingEnv(gym.Env):
150
150
  self.number_of_steps += 1
151
151
  self.steps += 1
152
152
  # rewards = [-max_reward] * self.n_sensors
153
- reward_init = np.array([0] * input_dim)
153
+ reward_init = [0] * input_dim
154
154
  rewards = [reward_init] * self.n_sensors
155
155
  dones = [False] * self.n_sensors
156
156
  for i, action in enumerate(actions):
@@ -159,7 +159,7 @@ class WSNRoutingEnv(gym.Env):
159
159
 
160
160
  if (action == i):
161
161
  continue # Skip if sensor tries to transmit data to itself
162
-
162
+
163
163
  if action == self.n_sensors:
164
164
  if self.distance_to_base[i] > self.coverage_radius:
165
165
  continue # Skip if the distance to the base station is greater than the coverage radius
@@ -195,16 +195,20 @@ class WSNRoutingEnv(gym.Env):
195
195
  continue # Skip if the sensor does not have enough energy to transmit data to the next hop
196
196
 
197
197
  self.update_sensor_energies(i, transmission_energy)
198
+ # Update the metrics
199
+ self.total_energy_consumed += transmission_energy
200
+ self.total_packets_sent_by_sensors += self.number_of_packets[i]
198
201
 
199
202
  if self.remaining_energy[action] < reception_energy:
200
203
  # self.remaining_energy[action] = 0
204
+ self.packet_latency[i] = 0 # Reset the latency of the packet
205
+ self.number_of_packets[i] = 0 # Reset the number of packets of the sensor i
201
206
  continue # Skip if the next hop does not have enough energy to receive data
202
207
 
203
208
  self.update_sensor_energies(action, reception_energy)
204
209
 
205
210
  # Update the metrics
206
- self.total_energy_consumed += transmission_energy + reception_energy
207
- self.total_packets_sent_by_sensors += self.number_of_packets[i]
211
+ self.total_energy_consumed += reception_energy
208
212
  self.packet_latency[action] += self.packet_latency[i] + latency_per_hop
209
213
  self.packet_latency[i] = 0
210
214
 
@@ -488,7 +492,7 @@ class WSNRoutingEnv(gym.Env):
488
492
  query_vector = np.array([max_reward] * d) # Basically, the target is the base station
489
493
 
490
494
  # Similarities between the query vector and the rewards
491
- similarities = [np.dot(query_vector, reward) for reward in rewards]
495
+ similarities = [np.dot(query_vector, reward) for reward in rewards if isinstance(reward, np.ndarray)]
492
496
 
493
497
  # Similarities scaling
494
498
  similarities = [similarity / np.sqrt(d) for similarity in similarities]
@@ -498,7 +502,7 @@ class WSNRoutingEnv(gym.Env):
498
502
  attention_weights = [np.exp(similarity) / denominator for similarity in similarities]
499
503
 
500
504
  # Weighted sum of the rewards
501
- final_reward = sum([attention_weight * reward for attention_weight, reward in zip(attention_weights, rewards)])
505
+ final_reward = sum([attention_weight * reward for attention_weight, reward in zip(attention_weights, rewards) if isinstance(reward, np.ndarray)])
502
506
 
503
507
  return np.sum(final_reward)
504
508
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: gym-examples
3
- Version: 3.0.766
3
+ Version: 3.0.768
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=ErBo6hRVSUgQvxu0zaJqLRmZM9LTYXQ_1HIgV4bg01o,166
2
+ gym_examples/envs/__init__.py,sha256=lgMe4pyOuUTgTBUddM0iwMlETsYTwFShny6ifm8PGM8,53
3
+ gym_examples/envs/wsn_env.py,sha256=baJSRHpxNnasenWc-lGGjeHvXkJQaSLSpr_pSP9SrmQ,26864
4
+ gym_examples-3.0.768.dist-info/METADATA,sha256=U9TYdpAF3BmSEktZwNYaDSjCV3bjKezIUbAMsQBgfGs,412
5
+ gym_examples-3.0.768.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
6
+ gym_examples-3.0.768.dist-info/top_level.txt,sha256=rJRksoAF32M6lTLBEwYzRdo4PgtejceaNnnZ3HeY_Rk,13
7
+ gym_examples-3.0.768.dist-info/RECORD,,
@@ -1,7 +0,0 @@
1
- gym_examples/__init__.py,sha256=oGBLNhUkMsxNUxrD6aMbIe9qHF4IwLFTzFobdBSE9pM,166
2
- gym_examples/envs/__init__.py,sha256=lgMe4pyOuUTgTBUddM0iwMlETsYTwFShny6ifm8PGM8,53
3
- gym_examples/envs/wsn_env.py,sha256=YyPRExlOFIEDI0NLhaAX6LwOmJgGLw5WU8G-pvD8wVc,26532
4
- gym_examples-3.0.766.dist-info/METADATA,sha256=QMrQjl8_UfOylLp1Aw0TvEtriDzm576Rji5sTS2gtZk,412
5
- gym_examples-3.0.766.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
6
- gym_examples-3.0.766.dist-info/top_level.txt,sha256=rJRksoAF32M6lTLBEwYzRdo4PgtejceaNnnZ3HeY_Rk,13
7
- gym_examples-3.0.766.dist-info/RECORD,,