gym-examples 3.0.729__py3-none-any.whl → 3.0.730__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 +1 -1
- gym_examples/envs/wsn_env.py +6 -9
- {gym_examples-3.0.729.dist-info → gym_examples-3.0.730.dist-info}/METADATA +1 -1
- gym_examples-3.0.730.dist-info/RECORD +7 -0
- gym_examples-3.0.729.dist-info/RECORD +0 -7
- {gym_examples-3.0.729.dist-info → gym_examples-3.0.730.dist-info}/WHEEL +0 -0
- {gym_examples-3.0.729.dist-info → gym_examples-3.0.730.dist-info}/top_level.txt +0 -0
gym_examples/__init__.py
CHANGED
gym_examples/envs/wsn_env.py
CHANGED
@@ -150,7 +150,8 @@ 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
|
-
|
153
|
+
reward_init = np.array([0] * input_dim)
|
154
|
+
rewards = [reward_init] * self.n_sensors
|
154
155
|
dones = [False] * self.n_sensors
|
155
156
|
for i, action in enumerate(actions):
|
156
157
|
if self.remaining_energy[i] <= 0 or self.number_of_packets[i] <= 0:
|
@@ -381,7 +382,7 @@ class WSNRoutingEnv(gym.Env):
|
|
381
382
|
reward_dispersion_remaining_energy = self.compute_reward_dispersion_remaining_energy()
|
382
383
|
reward_number_of_packets = self.compute_reward_number_of_packets(action)
|
383
384
|
|
384
|
-
rewards_energy = [reward_angle, reward_consumption_energy, reward_dispersion_remaining_energy, reward_number_of_packets]
|
385
|
+
rewards_energy = np.array([reward_angle, reward_consumption_energy, reward_dispersion_remaining_energy, reward_number_of_packets])
|
385
386
|
|
386
387
|
#-- rewards related to the performance metrics
|
387
388
|
reward_latency = self.compute_reward_latency()
|
@@ -389,10 +390,8 @@ class WSNRoutingEnv(gym.Env):
|
|
389
390
|
reward_network_throughput = self.compute_reward_network_throughput()
|
390
391
|
reward_packet_delivery_ratio = self.compute_reward_packet_delivery_ratio()
|
391
392
|
|
392
|
-
rewards_performance = [reward_latency, reward_network_throughput, reward_packet_delivery_ratio]
|
393
|
+
rewards_performance = np.array([reward_latency, reward_network_throughput, reward_packet_delivery_ratio])
|
393
394
|
|
394
|
-
# return np.concatenate((rewards_energy, rewards_performance))
|
395
|
-
# return np.array([reward_consumption_energy, reward_dispersion_remaining_energy])
|
396
395
|
return rewards_energy
|
397
396
|
|
398
397
|
|
@@ -488,7 +487,7 @@ class WSNRoutingEnv(gym.Env):
|
|
488
487
|
d = len(rewards[0])
|
489
488
|
|
490
489
|
# All sensors are represented by their raw rewards
|
491
|
-
query_vector = [max_reward] * d # Basically, the target is the base station
|
490
|
+
query_vector = np.array([max_reward] * d) # Basically, the target is the base station
|
492
491
|
|
493
492
|
# Similarities between the query vector and the rewards
|
494
493
|
similarities = [np.dot(query_vector, reward) for reward in rewards]
|
@@ -499,9 +498,7 @@ class WSNRoutingEnv(gym.Env):
|
|
499
498
|
# Softmax operation
|
500
499
|
denominator = sum([np.exp(similarity) for similarity in similarities])
|
501
500
|
attention_weights = [np.exp(similarity) / denominator for similarity in similarities]
|
502
|
-
|
503
|
-
print("Attention weights: ", attention_weights)
|
504
|
-
print(f"========================================================================================\n")
|
501
|
+
|
505
502
|
# Weighted sum of the rewards
|
506
503
|
final_reward = sum([attention_weight * reward for attention_weight, reward in zip(attention_weights, rewards)])
|
507
504
|
|
@@ -0,0 +1,7 @@
|
|
1
|
+
gym_examples/__init__.py,sha256=YZH_5LVBNsE51SZdDi3rZXTcfPU5Bpw1OBqSHx6rnGo,166
|
2
|
+
gym_examples/envs/__init__.py,sha256=lgMe4pyOuUTgTBUddM0iwMlETsYTwFShny6ifm8PGM8,53
|
3
|
+
gym_examples/envs/wsn_env.py,sha256=UiqeDmuDwZ96Qv91-eI8GzbTdpMeXlcbNqhVG5Ndt0U,26590
|
4
|
+
gym_examples-3.0.730.dist-info/METADATA,sha256=5AKtgtPyq_6y3sWJjlym4zuqHbPMOCSNV6vhp0hsE-s,412
|
5
|
+
gym_examples-3.0.730.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
|
6
|
+
gym_examples-3.0.730.dist-info/top_level.txt,sha256=rJRksoAF32M6lTLBEwYzRdo4PgtejceaNnnZ3HeY_Rk,13
|
7
|
+
gym_examples-3.0.730.dist-info/RECORD,,
|
@@ -1,7 +0,0 @@
|
|
1
|
-
gym_examples/__init__.py,sha256=kthabVfu_M3x5cgmCdRpVrNJQRTdgJvheunzBETS8Yo,166
|
2
|
-
gym_examples/envs/__init__.py,sha256=lgMe4pyOuUTgTBUddM0iwMlETsYTwFShny6ifm8PGM8,53
|
3
|
-
gym_examples/envs/wsn_env.py,sha256=FOkeETp0cSqxiGlZSE_XcwIgJ607Aw0UhBnpM9DjX0g,26954
|
4
|
-
gym_examples-3.0.729.dist-info/METADATA,sha256=InZnXCPqHDHsxtXz8gZBaYpdADmlsplhF-t5XM4tYM8,412
|
5
|
-
gym_examples-3.0.729.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
|
6
|
-
gym_examples-3.0.729.dist-info/top_level.txt,sha256=rJRksoAF32M6lTLBEwYzRdo4PgtejceaNnnZ3HeY_Rk,13
|
7
|
-
gym_examples-3.0.729.dist-info/RECORD,,
|
File without changes
|
File without changes
|