gym-examples 3.0.42__py3-none-any.whl → 3.0.44__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 +25 -18
- {gym_examples-3.0.42.dist-info → gym_examples-3.0.44.dist-info}/METADATA +1 -1
- gym_examples-3.0.44.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.44.dist-info}/WHEEL +0 -0
- {gym_examples-3.0.42.dist-info → gym_examples-3.0.44.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 # length 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
|
@@ -90,8 +90,6 @@ class WSNRoutingEnv(gym.Env):
|
|
90
90
|
self.steps += 1
|
91
91
|
rewards = [0] * self.n_sensors
|
92
92
|
dones = [False] * self.n_sensors
|
93
|
-
# if self.episode_count >= 599:
|
94
|
-
# print(f"Step {self.steps} with actions = {actions}")
|
95
93
|
for i, action in enumerate(actions):
|
96
94
|
if action not in range(self.n_sensors + 1):
|
97
95
|
raise ValueError("Invalid action!")
|
@@ -123,7 +121,7 @@ class WSNRoutingEnv(gym.Env):
|
|
123
121
|
self.total_latency += self.packet_latency[i] + latency_per_hop
|
124
122
|
self.packet_latency[i] = 0
|
125
123
|
|
126
|
-
rewards[i] =
|
124
|
+
rewards[i] = self.compute_individual_rewards(i, action)
|
127
125
|
dones[i] = True
|
128
126
|
else:
|
129
127
|
distance = np.linalg.norm(self.sensor_positions[i] - self.sensor_positions[action])
|
@@ -144,11 +142,8 @@ class WSNRoutingEnv(gym.Env):
|
|
144
142
|
self.packet_latency[action] += self.packet_latency[i] + latency_per_hop
|
145
143
|
self.packet_latency[i] = 0
|
146
144
|
|
147
|
-
|
148
|
-
|
149
|
-
reward_packet_delivery_ratio = self.compute_reward_packet_delivery_ratio()
|
150
|
-
reward_latency = self.compute_reward_latency()
|
151
|
-
rewards[i] = np.append(rewards[i], [reward_packet_delivery_ratio, reward_latency])
|
145
|
+
rewards[i] = self.compute_individual_rewards(i, action)
|
146
|
+
|
152
147
|
# Update the number of packets
|
153
148
|
self.number_of_packets[action] += self.number_of_packets[i]
|
154
149
|
self.number_of_packets[i] = 0 # Reset the number of packets of the sensor i
|
@@ -169,12 +164,6 @@ class WSNRoutingEnv(gym.Env):
|
|
169
164
|
|
170
165
|
self.get_metrics()
|
171
166
|
|
172
|
-
# reward_packet_delivery_ratio = self.compute_reward_packet_delivery_ratio()
|
173
|
-
# reward_latency = self.compute_reward_latency()
|
174
|
-
# rewards_metrics = [reward_packet_delivery_ratio, reward_latency]
|
175
|
-
# rewards_metrics = self.compute_attention_rewards(rewards_metrics)
|
176
|
-
# rewards = [torch.tensor(r, dtype=torch.float64) + rewards_metrics if isinstance(r, int) else r + rewards_metrics for r in rewards]
|
177
|
-
|
178
167
|
return self._get_obs(), rewards, dones, {}
|
179
168
|
|
180
169
|
def _get_obs(self):
|
@@ -295,15 +284,24 @@ class WSNRoutingEnv(gym.Env):
|
|
295
284
|
'''
|
296
285
|
Compute the individual rewards
|
297
286
|
'''
|
287
|
+
#-- rewards related to the energy consumption minimization and energy balance
|
298
288
|
reward_angle = self.compute_reward_angle(i, action)
|
299
289
|
# reward_distance = self.compute_reward_distance(i, action)
|
300
290
|
reward_consumption_energy = self.compute_reward_consumption_energy(i, action)
|
301
291
|
reward_dispersion_remaining_energy = self.compute_reward_dispersion_remaining_energy()
|
302
292
|
reward_number_of_packets = self.compute_reward_number_of_packets(action)
|
303
293
|
|
304
|
-
|
305
|
-
|
306
|
-
|
294
|
+
rewards_energy = np.array([reward_angle, reward_consumption_energy, reward_dispersion_remaining_energy, reward_number_of_packets])
|
295
|
+
|
296
|
+
#-- rewards related to the performance metrics
|
297
|
+
reward_latency = self.compute_reward_latency()
|
298
|
+
reward_network_throughput = self.compute_reward_network_throughput()
|
299
|
+
reward_packet_delivery_ratio = self.compute_reward_packet_delivery_ratio()
|
300
|
+
|
301
|
+
rewards_performance = np.array([reward_latency, reward_network_throughput, reward_packet_delivery_ratio])
|
302
|
+
|
303
|
+
return np.concatenate((rewards_energy, rewards_performance))
|
304
|
+
|
307
305
|
def network_reward_dispersion_remaining_energy(self):
|
308
306
|
'''
|
309
307
|
Compute the reward based on the standard deviation of the remaining energy at the network level
|
@@ -343,6 +341,15 @@ class WSNRoutingEnv(gym.Env):
|
|
343
341
|
|
344
342
|
return np.clip(1 - normalized_latency, 0, 1)
|
345
343
|
|
344
|
+
def compute_reward_network_throughput(self):
|
345
|
+
'''
|
346
|
+
Compute the reward based on the network throughput
|
347
|
+
'''
|
348
|
+
network_throughput = self.packets_delivered / self.steps if self.steps > 0 else 0
|
349
|
+
maximum_throughput = self.n_sensors * initial_number_of_packets
|
350
|
+
normalized_throughput = network_throughput / maximum_throughput
|
351
|
+
return np.clip(normalized_throughput, 0, 1)
|
352
|
+
|
346
353
|
|
347
354
|
def compute_sum_rewards(self, rewards):
|
348
355
|
'''
|
@@ -0,0 +1,7 @@
|
|
1
|
+
gym_examples/__init__.py,sha256=qIKbuc3FY1hkHzkw8FzbDPnI1CoXn6KiYNCe0zG0MQo,193
|
2
|
+
gym_examples/envs/__init__.py,sha256=lgMe4pyOuUTgTBUddM0iwMlETsYTwFShny6ifm8PGM8,53
|
3
|
+
gym_examples/envs/wsn_env.py,sha256=BA0zRUuNy104AHvJIcSV68AxZ9BC-gouJJGWYpbC_Jo,19592
|
4
|
+
gym_examples-3.0.44.dist-info/METADATA,sha256=0MoxuoqIDqB_-OPW9qSPtKvzT-r60xF8txnG_tHkxcg,411
|
5
|
+
gym_examples-3.0.44.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
|
6
|
+
gym_examples-3.0.44.dist-info/top_level.txt,sha256=rJRksoAF32M6lTLBEwYzRdo4PgtejceaNnnZ3HeY_Rk,13
|
7
|
+
gym_examples-3.0.44.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
|