gym-examples 3.0.178__py3-none-any.whl → 3.0.180__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 +10 -21
- {gym_examples-3.0.178.dist-info → gym_examples-3.0.180.dist-info}/METADATA +1 -1
- gym_examples-3.0.180.dist-info/RECORD +7 -0
- gym_examples-3.0.178.dist-info/RECORD +0 -7
- {gym_examples-3.0.178.dist-info → gym_examples-3.0.180.dist-info}/WHEEL +0 -0
- {gym_examples-3.0.178.dist-info → gym_examples-3.0.180.dist-info}/top_level.txt +0 -0
gym_examples/__init__.py
CHANGED
gym_examples/envs/wsn_env.py
CHANGED
@@ -55,12 +55,8 @@ class WSNRoutingEnv(gym.Env):
|
|
55
55
|
def __init__(self, n_sensors = 20, coverage_radius=(upper_bound - lower_bound)/4):
|
56
56
|
|
57
57
|
super(WSNRoutingEnv, self).__init__()
|
58
|
-
self.log_done = None # Log the done status of the environment
|
59
|
-
self.log_action = None # Log the action taken by the agent
|
60
|
-
self.log_steps = None # Log the number of steps taken by the agent
|
61
58
|
|
62
59
|
# Initialize list of episode metrics
|
63
|
-
episode_return = None
|
64
60
|
self.number_of_steps = 0 # Total number of steps taken by the agent since the beginning of the training
|
65
61
|
self.episode_returns = []
|
66
62
|
self.episode_std_remaining_energy = []
|
@@ -91,10 +87,8 @@ class WSNRoutingEnv(gym.Env):
|
|
91
87
|
|
92
88
|
def reset(self):
|
93
89
|
|
94
|
-
episode_return = 0
|
95
|
-
|
96
90
|
if self.episode_count > 1 and os.getenv('PRINT_STATS') == 'True':
|
97
|
-
self.episode_returns.append(episode_return)
|
91
|
+
self.episode_returns.append(self.episode_return)
|
98
92
|
self.episode_std_remaining_energy.append(np.std(self.remaining_energy))
|
99
93
|
self.episode_mean_remaining_energy.append(np.mean(self.remaining_energy))
|
100
94
|
self.episode_total_consumption_energy.append(np.sum(initial_energy - self.remaining_energy))
|
@@ -102,11 +96,10 @@ class WSNRoutingEnv(gym.Env):
|
|
102
96
|
self.episode_packet_delivery_ratio.append(self.packet_delivery_ratio)
|
103
97
|
self.episode_network_lifetime.append(self.network_lifetime)
|
104
98
|
self.episode_average_latency.append(self.average_latency)
|
105
|
-
print(f"Episode: {self.episode_count}")
|
106
|
-
print(
|
107
|
-
|
108
|
-
|
109
|
-
print(self.get_metrics())
|
99
|
+
print(f"Episode: {self.episode_count}")
|
100
|
+
print(self.get_metrics())
|
101
|
+
|
102
|
+
self.episode_return = 0
|
110
103
|
self.sensor_positions = np.random.rand(self.n_sensors, 2) * (upper_bound - lower_bound) + lower_bound
|
111
104
|
self.distance_to_base = np.linalg.norm(self.sensor_positions - base_station_position, axis=1)
|
112
105
|
self.remaining_energy = np.ones(self.n_sensors) * initial_energy
|
@@ -131,9 +124,7 @@ class WSNRoutingEnv(gym.Env):
|
|
131
124
|
|
132
125
|
def step(self, actions):
|
133
126
|
actions = [actions[i] for i in range(self.n_agents)] # We want to go back from the MultiDiscrete action space to a tuple of tuple of Discrete action spaces
|
134
|
-
self.steps += 1
|
135
|
-
if os.getenv('PRINT_STATS') == 'True':
|
136
|
-
self.number_of_steps += 1
|
127
|
+
self.steps += 1
|
137
128
|
rewards = [0] * self.n_sensors
|
138
129
|
dones = [False] * self.n_sensors
|
139
130
|
for i, action in enumerate(actions):
|
@@ -217,14 +208,12 @@ class WSNRoutingEnv(gym.Env):
|
|
217
208
|
rewards = np.mean(rewards) # Average the rewards of all agents
|
218
209
|
# print(f"Step: {self.steps}, Rewards: {rewards}, Done: {dones}")
|
219
210
|
dones = all(dones) # Done if all agents are done
|
220
|
-
|
221
|
-
self.log_action = actions
|
222
|
-
self.log_steps = self.steps
|
223
|
-
episode_return += rewards
|
224
|
-
|
211
|
+
|
225
212
|
if os.getenv('PRINT_STATS') == 'True': # We are trying to extract only the statistics for the PPO algorithm
|
213
|
+
self.number_of_steps += 1
|
214
|
+
self.episode_return += rewards
|
226
215
|
if self.number_of_steps >= num_timesteps:
|
227
|
-
self.episode_returns.append(episode_return)
|
216
|
+
self.episode_returns.append(self.episode_return)
|
228
217
|
self.episode_std_remaining_energy.append(np.std(self.remaining_energy))
|
229
218
|
self.episode_mean_remaining_energy.append(np.mean(self.remaining_energy))
|
230
219
|
self.episode_total_consumption_energy.append(np.sum(initial_energy - self.remaining_energy))
|
@@ -0,0 +1,7 @@
|
|
1
|
+
gym_examples/__init__.py,sha256=u596NUGuugLKs4xG38CdXc1ChDTjdSFE4qwRq07dSco,194
|
2
|
+
gym_examples/envs/__init__.py,sha256=lgMe4pyOuUTgTBUddM0iwMlETsYTwFShny6ifm8PGM8,53
|
3
|
+
gym_examples/envs/wsn_env.py,sha256=xXwNW7X-pFQT0T_vJwI7WIkoAhUhtmz7nTEokL9d30Q,25660
|
4
|
+
gym_examples-3.0.180.dist-info/METADATA,sha256=esLOv32LCP3zP5pOa-zczAQTsz0ZSha7VqVAL0pcsNg,412
|
5
|
+
gym_examples-3.0.180.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
|
6
|
+
gym_examples-3.0.180.dist-info/top_level.txt,sha256=rJRksoAF32M6lTLBEwYzRdo4PgtejceaNnnZ3HeY_Rk,13
|
7
|
+
gym_examples-3.0.180.dist-info/RECORD,,
|
@@ -1,7 +0,0 @@
|
|
1
|
-
gym_examples/__init__.py,sha256=dKB7fxf-b5wOgFhNlcNdhFqGY0_sagdM3FVbJyd2xBM,194
|
2
|
-
gym_examples/envs/__init__.py,sha256=lgMe4pyOuUTgTBUddM0iwMlETsYTwFShny6ifm8PGM8,53
|
3
|
-
gym_examples/envs/wsn_env.py,sha256=MsDYLY0-6ngqgziKcJ5BET701GWX6OU1qoh3FMTezcs,26238
|
4
|
-
gym_examples-3.0.178.dist-info/METADATA,sha256=zRHR4aBsr9tc5dwMeqysMfhLm8823FOnSCj7tph9DaM,412
|
5
|
-
gym_examples-3.0.178.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
|
6
|
-
gym_examples-3.0.178.dist-info/top_level.txt,sha256=rJRksoAF32M6lTLBEwYzRdo4PgtejceaNnnZ3HeY_Rk,13
|
7
|
-
gym_examples-3.0.178.dist-info/RECORD,,
|
File without changes
|
File without changes
|