gym-examples 3.0.42__py3-none-any.whl → 3.0.43__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 +17 -5
- {gym_examples-3.0.42.dist-info → gym_examples-3.0.43.dist-info}/METADATA +1 -1
- gym_examples-3.0.43.dist-info/RECORD +7 -0
- gym_examples-3.0.42.dist-info/RECORD +0 -7
- {gym_examples-3.0.42.dist-info → gym_examples-3.0.43.dist-info}/WHEEL +0 -0
- {gym_examples-3.0.42.dist-info → gym_examples-3.0.43.dist-info}/top_level.txt +0 -0
gym_examples/__init__.py
CHANGED
gym_examples/envs/wsn_env.py
CHANGED
@@ -10,7 +10,7 @@ import torch.nn as nn
|
|
10
10
|
import torch.nn.functional as F
|
11
11
|
|
12
12
|
# Define the network parameters for the final reward function
|
13
|
-
input_dim =
|
13
|
+
input_dim = 7 # lenght of the individual rewards vector
|
14
14
|
output_dim = 1 # final reward
|
15
15
|
|
16
16
|
Eelec = 50e-9 # energy consumption per bit in joules
|
@@ -146,9 +146,12 @@ class WSNRoutingEnv(gym.Env):
|
|
146
146
|
|
147
147
|
# Compute individual rewards
|
148
148
|
rewards[i] = self.compute_individual_rewards(i, action)
|
149
|
-
reward_packet_delivery_ratio = self.compute_reward_packet_delivery_ratio()
|
150
149
|
reward_latency = self.compute_reward_latency()
|
151
|
-
|
150
|
+
reward_network_throughput = self.compute_reward_network_throughput()
|
151
|
+
reward_packet_delivery_ratio = self.compute_reward_packet_delivery_ratio()
|
152
|
+
|
153
|
+
rewards[i] = np.append(rewards[i], [reward_latency, reward_network_throughput, reward_packet_delivery_ratio])
|
154
|
+
print(f"Rewards for sensor {i}: {rewards[i]}")
|
152
155
|
# Update the number of packets
|
153
156
|
self.number_of_packets[action] += self.number_of_packets[i]
|
154
157
|
self.number_of_packets[i] = 0 # Reset the number of packets of the sensor i
|
@@ -301,8 +304,8 @@ class WSNRoutingEnv(gym.Env):
|
|
301
304
|
reward_dispersion_remaining_energy = self.compute_reward_dispersion_remaining_energy()
|
302
305
|
reward_number_of_packets = self.compute_reward_number_of_packets(action)
|
303
306
|
|
304
|
-
|
305
|
-
return [reward_consumption_energy, reward_dispersion_remaining_energy]
|
307
|
+
return [reward_angle, reward_consumption_energy, reward_dispersion_remaining_energy, reward_number_of_packets]
|
308
|
+
# return [reward_consumption_energy, reward_dispersion_remaining_energy]
|
306
309
|
|
307
310
|
def network_reward_dispersion_remaining_energy(self):
|
308
311
|
'''
|
@@ -343,6 +346,15 @@ class WSNRoutingEnv(gym.Env):
|
|
343
346
|
|
344
347
|
return np.clip(1 - normalized_latency, 0, 1)
|
345
348
|
|
349
|
+
def compute_reward_network_throughput(self):
|
350
|
+
'''
|
351
|
+
Compute the reward based on the network throughput
|
352
|
+
'''
|
353
|
+
network_throughput = self.packets_delivered / self.steps if self.steps > 0 else 0
|
354
|
+
maximum_throughput = self.n_sensors * initial_number_of_packets
|
355
|
+
normalized_throughput = network_throughput / maximum_throughput
|
356
|
+
return np.clip(normalized_throughput, 0, 1)
|
357
|
+
|
346
358
|
|
347
359
|
def compute_sum_rewards(self, rewards):
|
348
360
|
'''
|
@@ -0,0 +1,7 @@
|
|
1
|
+
gym_examples/__init__.py,sha256=v16UW-Z-uwXvUYm4QHBNqhWNXR60wfJm4p2JkJlUz78,193
|
2
|
+
gym_examples/envs/__init__.py,sha256=lgMe4pyOuUTgTBUddM0iwMlETsYTwFShny6ifm8PGM8,53
|
3
|
+
gym_examples/envs/wsn_env.py,sha256=MXuHoi82JRleOBG5aXpUjlf58L_QeXCBeWNSceyBcGA,20145
|
4
|
+
gym_examples-3.0.43.dist-info/METADATA,sha256=zyEgD6YW1AooTqez0qIsvvApqcqswdHfMtzQJ0V0TAQ,411
|
5
|
+
gym_examples-3.0.43.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
|
6
|
+
gym_examples-3.0.43.dist-info/top_level.txt,sha256=rJRksoAF32M6lTLBEwYzRdo4PgtejceaNnnZ3HeY_Rk,13
|
7
|
+
gym_examples-3.0.43.dist-info/RECORD,,
|
@@ -1,7 +0,0 @@
|
|
1
|
-
gym_examples/__init__.py,sha256=kLTFJhJe48NKPRenv6nTfwR9FbFVrCMz4hzeIhHTrgI,193
|
2
|
-
gym_examples/envs/__init__.py,sha256=lgMe4pyOuUTgTBUddM0iwMlETsYTwFShny6ifm8PGM8,53
|
3
|
-
gym_examples/envs/wsn_env.py,sha256=P3-MHflhQ29pLwrDb2oY7NjJvbpDXuTz6bPX2_mbqPQ,19522
|
4
|
-
gym_examples-3.0.42.dist-info/METADATA,sha256=T4wmhIiKxlhX7Mccah7D-kCaZap2pgJPtrVgyo0rMPI,411
|
5
|
-
gym_examples-3.0.42.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
|
6
|
-
gym_examples-3.0.42.dist-info/top_level.txt,sha256=rJRksoAF32M6lTLBEwYzRdo4PgtejceaNnnZ3HeY_Rk,13
|
7
|
-
gym_examples-3.0.42.dist-info/RECORD,,
|
File without changes
|
File without changes
|