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

minor updates

parent 37b53f23
No related branches found
No related tags found
No related merge requests found
...@@ -14,11 +14,12 @@ np.random.seed(1) ...@@ -14,11 +14,12 @@ np.random.seed(1)
TreeObservation = TreeObsForRailEnv(max_depth=2, predictor=ShortestPathPredictorForRailEnv()) TreeObservation = TreeObsForRailEnv(max_depth=2, predictor=ShortestPathPredictorForRailEnv())
LocalGridObs = LocalObsForRailEnv(view_height=10, view_width=2, center=2) LocalGridObs = LocalObsForRailEnv(view_height=10, view_width=2, center=2)
env = RailEnv(width=50, env = RailEnv(width=50,
height=50, height=50,
rail_generator=complex_rail_generator(nr_start_goal=20, nr_extra=1, min_dist=8, max_dist=99999, seed=0), rail_generator=complex_rail_generator(nr_start_goal=20, nr_extra=1, min_dist=8, max_dist=99999, seed=0),
obs_builder_object=TreeObservation, obs_builder_object=TreeObservation,
number_of_agents=20) number_of_agents=10)
env_renderer = RenderTool(env, gl="PILSVG", ) env_renderer = RenderTool(env, gl="PILSVG", )
...@@ -58,7 +59,7 @@ class RandomAgent: ...@@ -58,7 +59,7 @@ class RandomAgent:
# Initialize the agent with the parameters corresponding to the environment and observation_builder # Initialize the agent with the parameters corresponding to the environment and observation_builder
agent = RandomAgent(218, 4) agent = RandomAgent(218, 5)
n_trials = 5 n_trials = 5
# Empty dictionary for all agent action # Empty dictionary for all agent action
...@@ -75,7 +76,7 @@ for trials in range(1, n_trials + 1): ...@@ -75,7 +76,7 @@ for trials in range(1, n_trials + 1):
score = 0 score = 0
# Run episode # Run episode
for step in range(100): for step in range(500):
# Chose an action for each agent in the environment # Chose an action for each agent in the environment
for a in range(env.get_num_agents()): for a in range(env.get_num_agents()):
action = agent.act(obs[a]) action = agent.act(obs[a])
...@@ -89,7 +90,6 @@ for trials in range(1, n_trials + 1): ...@@ -89,7 +90,6 @@ for trials in range(1, n_trials + 1):
for a in range(env.get_num_agents()): for a in range(env.get_num_agents()):
agent.step((obs[a], action_dict[a], all_rewards[a], next_obs[a], done[a])) agent.step((obs[a], action_dict[a], all_rewards[a], next_obs[a], done[a]))
score += all_rewards[a] score += all_rewards[a]
obs = next_obs.copy() obs = next_obs.copy()
if done['__all__']: if done['__all__']:
break break
......
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