diff --git a/env-data/railway/example_network_000.pkl b/env-data/railway/example_network_000.pkl index 280688c2629331621ab2ea80b4b096226464e653..ab7764b1ea250633e5a0cd2ec9b93a4e07479c9f 100644 Binary files a/env-data/railway/example_network_000.pkl and b/env-data/railway/example_network_000.pkl differ diff --git a/env-data/railway/example_network_001.pkl b/env-data/railway/example_network_001.pkl index 801f95149dec6eb4d47fd14e36d30f2541480188..af9dc43246449562065be64c750a06c75c3e7571 100644 Binary files a/env-data/railway/example_network_001.pkl and b/env-data/railway/example_network_001.pkl differ diff --git a/env-data/railway/example_network_002.pkl b/env-data/railway/example_network_002.pkl index 898d54ebeb823e48790d4661ffe75a6940cd0712..d39e44798066e0a0b753006775c5727326fc58da 100644 Binary files a/env-data/railway/example_network_002.pkl and b/env-data/railway/example_network_002.pkl differ diff --git a/examples/demo.py b/examples/demo.py index 7e3725bccde4d4635c3a5e5ff275af9606018184..a53370aac5b3668cb12f7f794b1d91d563ef96e4 100644 --- a/examples/demo.py +++ b/examples/demo.py @@ -6,7 +6,6 @@ import time import numpy as np import torch -from flatland.baselines.dueling_double_dqn import Agent from flatland.envs.generators import complex_rail_generator # from flatland.envs.generators import rail_from_list_of_saved_GridTransitionMap_generator from flatland.envs.generators import random_rail_generator @@ -126,13 +125,7 @@ class Demo: def __init__(self, env): self.env = env self.create_renderer() - self.load_agent() - - def load_agent(self): - self.state_size = 105 * 2 self.action_size = 4 - self.agent = Agent(self.state_size, self.action_size, "FC", 0) - self.agent.qnetwork_local.load_state_dict(torch.load('./flatland/baselines/Nets/avoid_checkpoint15000.pth')) def create_renderer(self): self.renderer = RenderTool(self.env, gl="QTSVG") @@ -170,10 +163,12 @@ class Demo: # print(step) # Action for a in range(self.env.get_num_agents()): - action = self.agent.act(agent_obs[a]) + action = np.random.choice(self.action_size) #self.agent.act(agent_obs[a]) action_prob[action] += 1 action_dict.update({a: action}) + print(action_dict) + self.renderer.renderEnv(show=True,action_dict=action_dict) # Environment step @@ -196,7 +191,7 @@ class Demo: break -if True: +if False: demo_000 = Demo(Scenario_Generator.generate_random_scenario()) demo_000.run_demo() demo_000 = None diff --git a/flatland/utils/editor.py b/flatland/utils/editor.py index 91d81faa471fc81dbec5270fe079ce77fa7a03b4..59a55db5218acabb67904692a0b4cc8207b0df00 100644 --- a/flatland/utils/editor.py +++ b/flatland/utils/editor.py @@ -132,6 +132,7 @@ class View(object): dict(name="Clear", method=self.controller.clear, tip="Clear rails and agents"), dict(name="Reset", method=self.controller.reset, tip="Standard env reset, including regen rail + agents"), + dict(name="Rotate Agent", method=self.controller.rotate_agent, tip="Rotate selected agent"), dict(name="Restart Agents", method=self.controller.restartAgents, tip="Move agents back to start positions"), dict(name="Regenerate", method=self.controller.regenerate, @@ -325,6 +326,15 @@ class Controller(object): self.model.reset(replace_agents=self.view.wReplaceAgents.value, nAgents=self.view.wRegenNAgents.value) + def rotate_agent(self,event): + self.log("Rotate Agent:", self.model.iSelectedAgent) + if self.model.iSelectedAgent is not None: + for iAgent, agent in enumerate(self.model.env.agents_static): + if agent is None: + continue + agent.direction = (agent.direction + 1) % 4 + self.model.redraw() + def restartAgents(self, event): self.log("Restart Agents - nAgents:", self.view.wRegenNAgents.value) self.model.restartAgents() @@ -695,8 +705,7 @@ class EditorModel(object): # No if self.iSelectedAgent is None: # Create a new agent and select it. - ## ADRIAN - agent_static = EnvAgentStatic(rcCell, np.random.choice(4), rcCell) + agent_static = EnvAgentStatic(rcCell,0, rcCell) self.iSelectedAgent = self.env.add_agent_static(agent_static) self.player = None # will need to start a new player else: diff --git a/notebooks/Editor2.ipynb b/notebooks/Editor2.ipynb index 8305d11536c234714620f1dd529b0e3e7677981d..20286e886c5d73f0ce427e8feeb209a8ad99c000 100644 --- a/notebooks/Editor2.ipynb +++ b/notebooks/Editor2.ipynb @@ -105,7 +105,7 @@ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "83640a5c6059421d92e0d69049ad232f", + "model_id": "7b66ea9348c9477f881ff27456987363", "version_major": 2, "version_minor": 0 }, @@ -131,7 +131,7 @@ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "dc7691bf5f804c5c95604cb551dbb335", + "model_id": "ffa0f869fe8a4921a7415384b75c1ded", "version_major": 2, "version_minor": 0 },