Skip to content
Snippets Groups Projects
Commit c85e08ee authored by Erik Nygren's avatar Erik Nygren :bullettrain_front:
Browse files

Refactoring: Intdocued fix_agents function.

At each step we first check for possible malfunctions.
THen we apply them and do all the agent steps
At the end we look at what agents should be fixed. This lead so to:

Current malfunction value says how many step calls are necessary till agent can move again

e.g. malfunction = 2, we have to call step() twice untill the agent can move again.

Code cleanup
parent ed12d9c1
No related branches found
No related tags found
No related merge requests found
......@@ -27,7 +27,7 @@ from flatland.utils.rendertools import RenderTool, AgentRenderVariant
width = 16*7 # With of map
height = 9*7 # Height of map
nr_trains = 10 # Number of trains that have an assigned task in the env
nr_trains = 20 # Number of trains that have an assigned task in the env
cities_in_map = 20 # Number of cities where agents can start or end
seed = 14 # Random seed
grid_distribution_of_cities = False # Type of city distribution, if False cities are randomly placed
......@@ -58,7 +58,7 @@ schedule_generator = sparse_schedule_generator(speed_ration_map)
# We can furthermore pass stochastic data to the RailEnv constructor which will allow for stochastic malfunctions
# during an episode.
stochastic_data = {'malfunction_rate': 1000, # Rate of malfunction occurence of single agent
stochastic_data = {'malfunction_rate': 5, # Rate of malfunction occurence of single agent
'min_duration': 3, # Minimal duration of malfunction
'max_duration': 20 # Max duration of malfunction
}
......
......@@ -427,7 +427,6 @@ class RailEnv(Environment):
"""
if self.np_random.rand() < self._malfunction_prob(rate, len(self.active_agents)):
print("Malfunction")
# Select only from agents that are not done yet
breaking_agent_idx = self.np_random.choice(self.active_agents)
breaking_agent = self.agents[breaking_agent_idx]
......
......@@ -121,7 +121,7 @@ def run_replay_config(env: RailEnv, test_configs: List[ReplayConfig], rendering:
agent.malfunction_data['moving_before_malfunction'] = agent.moving
agent.malfunction_data['fixed'] = False
_assert(a, agent.malfunction_data['malfunction'], replay.malfunction, 'malfunction')
print(step, agent.moving, agent.malfunction_data['fixed'], agent.malfunction_data['malfunction'])
print(step)
_, rewards_dict, _, info_dict = env.step(action_dict)
if rendering:
renderer.render_env(show=True, show_observations=True)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment