Skip to content
Snippets Groups Projects
Commit 13c34d6c authored by Egli Adrian (IT-SCI-API-PFI)'s avatar Egli Adrian (IT-SCI-API-PFI)
Browse files

...

parent fd1eafda
No related branches found
No related tags found
No related merge requests found
File added
File added
import os
import time
import random
import numpy as np
......@@ -137,9 +138,18 @@ class Demo:
_ = self.env.reset(False, False)
for step in range(max_nbr_of_steps):
time.sleep(.1)
# Action
for iAgent in range(self.env.get_num_agents()):
action = 2
if True:
if not ((step) % 2 == 0):
if iAgent % 2 == 1:
action = 0
if False:
agent = self.env.agents[iAgent]
trial = 0
......@@ -150,6 +160,7 @@ class Demo:
break
action_dict.update({iAgent: action})
self.renderer.renderEnv(show=True, action_dict=action_dict)
# Environment step
......@@ -180,7 +191,18 @@ if False:
demo_002.run_demo()
demo_002 = None
demo_flatland_000 = Demo(Scenario_Generator.load_scenario('./env-data/railway/example_flatland_000.pkl'))
demo_flatland_000 = Demo(Scenario_Generator.load_scenario('./env-data/railway/example_flatland_000.pkl'))
demo_flatland_000.renderer.resize()
demo_flatland_000.run_demo(1800)
demo_flatland_000 = None
demo_flatland_000 = Demo(Scenario_Generator.load_scenario('./env-data/railway/example_flatland_001.pkl'))
demo_flatland_000.renderer.resize()
demo_flatland_000.run_demo(1800)
demo_flatland_000 = None
demo_flatland_000 = Demo(Scenario_Generator.load_scenario('./env-data/railway/example_network_003.pkl'))
demo_flatland_000.renderer.resize()
demo_flatland_000.run_demo(1800)
demo_flatland_000 = None
......@@ -201,8 +201,8 @@ class RailEnv(Environment):
continue
if self.dones[iAgent]: # this agent has already completed...
print("rail_env.py @", currentframe().f_back.f_lineno, " agent ", iAgent,
"has already completed : why action will not be executed!!!!? ADRIAN")
# print("rail_env.py @", currentframe().f_back.f_lineno, " agent ", iAgent,
# "has already completed : why action will not be executed!!!!? ADRIAN")
continue
action = action_dict[iAgent]
......
%% Cell type:markdown id: tags:
# Rail Editor v0.2
%% Cell type:code id: tags:
``` python
%load_ext autoreload
%autoreload 2
```
%% Output
The autoreload extension is already loaded. To reload it, use:
%reload_ext autoreload
%% Cell type:code id: tags:
``` python
import numpy as np
from numpy import array
import ipywidgets
import IPython
from IPython.core.display import display, HTML
```
%% Cell type:code id: tags:
``` python
display(HTML("<style>.container { width:95% !important; }</style>"))
```
%% Output
%% Cell type:code id: tags:
``` python
from flatland.utils.editor import EditorMVC, EditorModel, View, Controller
```
%% Cell type:code id: tags:
``` python
mvc = EditorMVC(sGL="PIL" ) # sGL="PIL")
```
%% Output
%% Cell type:markdown id: tags:
## Instructions
- Drag to draw (improved dead-ends)
- Shift-Drag to erase rails (erasing dead ends not yet automated - drag right across them)
- ctrl-click to add agent
- direction chosen randomly to fit rail
- ctrl-shift-click to add target for last agent
- target can be moved by repeating
- to Resize the env (cannot preserve work):
- select "Regen" tab, set regen size slider, click regenerate.
- alt-click remove all rails from cell
%% Cell type:code id: tags:
``` python
mvc.view.display()
```
%% Output
%% Cell type:code id: tags:
``` python
mvc.view.wOutput.clear_output()
mvc.view.wOutput
```
%% Output
%% Cell type:code id: tags:
``` python
len(mvc.editor.env.agents), len(mvc.editor.env.agents_static)
```
%% Output
(0, 0)
......
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