gym-examples 2.0.23__py3-none-any.whl → 2.0.25__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 +21 -4
- {gym_examples-2.0.23.dist-info → gym_examples-2.0.25.dist-info}/METADATA +1 -1
- gym_examples-2.0.25.dist-info/RECORD +7 -0
- gym_examples-2.0.23.dist-info/RECORD +0 -7
- {gym_examples-2.0.23.dist-info → gym_examples-2.0.25.dist-info}/WHEEL +0 -0
- {gym_examples-2.0.23.dist-info → gym_examples-2.0.25.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 = 5 # number of individual rewards
|
14
14
|
output_dim = 1 # final reward
|
15
15
|
|
16
16
|
|
@@ -116,9 +116,10 @@ class WSNRoutingEnv(gym.Env):
|
|
116
116
|
rewards[i] = self.compute_individual_rewards(i, action, neighbors_i, remaining_energy_before)
|
117
117
|
self.number_of_packets[i] = 0 # Reset the number of packets of the sensor i
|
118
118
|
# Calculate final reward
|
119
|
-
rewards_individual = torch.tensor(rewards[i], dtype=torch.double)
|
120
|
-
final_reward = net(rewards_individual)
|
119
|
+
# rewards_individual = torch.tensor(rewards[i], dtype=torch.double)
|
120
|
+
# final_reward = net(rewards_individual)
|
121
121
|
# final_reward = sum(rewards[i])
|
122
|
+
final_reward = np.mean(rewards[i])
|
122
123
|
rewards[i] = final_reward
|
123
124
|
|
124
125
|
for i in range(self.n_sensors):
|
@@ -247,6 +248,20 @@ class WSNRoutingEnv(gym.Env):
|
|
247
248
|
|
248
249
|
return 1 - normalized_dispersion_remaining_energy
|
249
250
|
|
251
|
+
def compute_reward_number_of_packets(self, i, action, neighbors_i):
|
252
|
+
'''
|
253
|
+
Compute the reward based on the number of packets of each sensor in the neighborhood
|
254
|
+
'''
|
255
|
+
if len(neighbors_i) == 1 or action == self.n_sensors:
|
256
|
+
return 1
|
257
|
+
elif self.n_sensors in neighbors_i.keys():
|
258
|
+
return 0
|
259
|
+
else:
|
260
|
+
total_number_of_packets = np.sum([self.number_of_packets[x] for x in neighbors_i])
|
261
|
+
normalized_number_of_packets = self.number_of_packets[action] / total_number_of_packets
|
262
|
+
|
263
|
+
return 1 - normalized_number_of_packets
|
264
|
+
|
250
265
|
def compute_individual_rewards(self, i, action, neighbors_i, remaining_energy_before):
|
251
266
|
'''
|
252
267
|
Compute the individual rewards
|
@@ -255,9 +270,11 @@ class WSNRoutingEnv(gym.Env):
|
|
255
270
|
reward_distance = self.compute_reward_distance(action, neighbors_i)
|
256
271
|
reward_consumption_energy = self.compute_reward_consumption_energy(action, neighbors_i)
|
257
272
|
reward_dispersion_remaining_energy = self.compute_reward_dispersion_remaining_energy(i, action, neighbors_i, remaining_energy_before)
|
273
|
+
reward_number_of_packets = self.compute_reward_number_of_packets(i, action, neighbors_i)
|
258
274
|
|
275
|
+
# return [reward_angle, reward_distance, reward_consumption_energy, reward_dispersion_remaining_energy, reward_number_of_packets]
|
259
276
|
return [reward_angle, reward_distance, reward_consumption_energy, reward_dispersion_remaining_energy]
|
260
|
-
|
277
|
+
|
261
278
|
def integrate_mobility(self):
|
262
279
|
'''
|
263
280
|
Integrate the mobility of the sensors after each step
|
@@ -0,0 +1,7 @@
|
|
1
|
+
gym_examples/__init__.py,sha256=M32_6YSJZauKwn2-uBxRdUz47YkLA2k9Kba-ATqlmjY,193
|
2
|
+
gym_examples/envs/__init__.py,sha256=lgMe4pyOuUTgTBUddM0iwMlETsYTwFShny6ifm8PGM8,53
|
3
|
+
gym_examples/envs/wsn_env.py,sha256=ZyQ0DZ0SUVV8yj2TE0_8pbwPVfuzKzidcsymlQvLpU8,16041
|
4
|
+
gym_examples-2.0.25.dist-info/METADATA,sha256=bJhOsljL-MgvqCHj9v74RQ0_6qQCr7hTCsxLOjiebFM,411
|
5
|
+
gym_examples-2.0.25.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
|
6
|
+
gym_examples-2.0.25.dist-info/top_level.txt,sha256=rJRksoAF32M6lTLBEwYzRdo4PgtejceaNnnZ3HeY_Rk,13
|
7
|
+
gym_examples-2.0.25.dist-info/RECORD,,
|
@@ -1,7 +0,0 @@
|
|
1
|
-
gym_examples/__init__.py,sha256=jx0XO8I1avcMbJsh7BVmAGpYzIAkkRP0DDTR3aQxyRE,193
|
2
|
-
gym_examples/envs/__init__.py,sha256=lgMe4pyOuUTgTBUddM0iwMlETsYTwFShny6ifm8PGM8,53
|
3
|
-
gym_examples/envs/wsn_env.py,sha256=RuLxE06OdmbSmc0m5fnCqQUY1KCbJi7w8JeDJ3Hr-Zc,15135
|
4
|
-
gym_examples-2.0.23.dist-info/METADATA,sha256=zCJTDwK0zUTvFR__gP98UNDycf84DOpTERdX6ykDJSg,411
|
5
|
-
gym_examples-2.0.23.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
|
6
|
-
gym_examples-2.0.23.dist-info/top_level.txt,sha256=rJRksoAF32M6lTLBEwYzRdo4PgtejceaNnnZ3HeY_Rk,13
|
7
|
-
gym_examples-2.0.23.dist-info/RECORD,,
|
File without changes
|
File without changes
|