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

load -> step(s) works in editor

parent 6fc2266b
No related branches found
No related tags found
No related merge requests found
...@@ -171,7 +171,12 @@ if False: ...@@ -171,7 +171,12 @@ if False:
demo_001 = Demo(Scenario_Generator.load_scenario('./env-data/railway/example_flatland_001.pkl')) demo_001 = Demo(Scenario_Generator.load_scenario('./env-data/railway/temp.pkl'))
demo_001.set_record_frames('./rendering/frame_{:04d}.bmp') demo_001.run_demo(10)
demo_001.run_demo(60)
demo_001 = None demo_001 = None
if True:
demo_001 = Demo(Scenario_Generator.load_scenario('./env-data/railway/example_flatland_001.pkl'))
demo_001.set_record_frames('./rendering/frame_{:04d}.bmp')
demo_001.run_demo(60)
demo_001 = None
...@@ -654,13 +654,15 @@ class EditorModel(object): ...@@ -654,13 +654,15 @@ class EditorModel(object):
self.log("load file: ", self.env_filename) self.log("load file: ", self.env_filename)
# self.env.rail.load_transition_map(self.env_filename, override_gridsize=True) # self.env.rail.load_transition_map(self.env_filename, override_gridsize=True)
self.env.load(self.env_filename) self.env.load(self.env_filename)
if not self.regen_size_height == self.env.height or not self.regen_size_width == self.env.width:
if not self.regen_size_height == self.env.height and not self.regen_size_width == self.env.width:
self.regen_size_height = self.env.height self.regen_size_height = self.env.height
self.regen_size_width = self.env.width self.regen_size_width = self.env.width
self.regenerate(None, 0, self.env) self.regenerate(None, 0, self.env)
self.env.load(self.env_filename) self.env.load(self.env_filename)
self.env.restart_agents()
self.env.reset(False,False)
self.fix_env() self.fix_env()
self.set_env(self.env) self.set_env(self.env)
self.redraw() self.redraw()
...@@ -670,7 +672,12 @@ class EditorModel(object): ...@@ -670,7 +672,12 @@ class EditorModel(object):
def save(self): def save(self):
self.log("save to ", self.env_filename, " working dir: ", os.getcwd()) self.log("save to ", self.env_filename, " working dir: ", os.getcwd())
# self.env.rail.save_transition_map(self.env_filename) # self.env.rail.save_transition_map(self.env_filename)
temp_store = self.env.agents
# clear agents before save , because we want the "init" position of the agent to expert
self.env.agents = []
self.env.save(self.env_filename) self.env.save(self.env_filename)
# reset agents current (current position)
self.env.agents = temp_store
def regenerate(self, method=None, nAgents=0, env=None): def regenerate(self, method=None, nAgents=0, env=None):
self.log("Regenerate size", self.log("Regenerate size",
......
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
# Rail Editor v0.2 # Rail Editor v0.2
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
%load_ext autoreload %load_ext autoreload
%autoreload 2 %autoreload 2
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
import numpy as np import numpy as np
from numpy import array from numpy import array
import ipywidgets import ipywidgets
import IPython import IPython
from IPython.core.display import display, HTML from IPython.core.display import display, HTML
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
display(HTML("<style>.container { width:95% !important; }</style>")) display(HTML("<style>.container { width:95% !important; }</style>"))
``` ```
%% Output %% Output
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
from flatland.utils.editor import EditorMVC, EditorModel, View, Controller from flatland.utils.editor import EditorMVC, EditorModel, View, Controller
``` ```
%% Output %% Output
cairo installed: OK cairo installed: OK
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
mvc = EditorMVC(sGL="PILSVG" ) # sGL="PIL") mvc = EditorMVC(sGL="PILSVG" ) # sGL="PIL")
``` ```
%% Output %% Output
<flatland.utils.graphics_pil.PILSVG object at 0x000001C03C7A3080> <class 'flatland.utils.graphics_pil.PILSVG'> <flatland.utils.graphics_pil.PILSVG object at 0x000001E6748D1128> <class 'flatland.utils.graphics_pil.PILSVG'>
<super: <class 'PILSVG'>, <PILSVG object>> <class 'super'> <super: <class 'PILSVG'>, <PILSVG object>> <class 'super'>
0000000000000000 Background_#91D1DD.svg 0000000000000000 Background_#91D1DD.svg
WE 0000000000000100 Gleis_Deadend.svg WE 0000000000000100 Gleis_Deadend.svg
WW EE NN SS 1000010000100001 Gleis_Diamond_Crossing.svg WW EE NN SS 1000010000100001 Gleis_Diamond_Crossing.svg
WW EE 0000010000000001 Gleis_horizontal.svg WW EE 0000010000000001 Gleis_horizontal.svg
EN SW 0000100000010000 Gleis_Kurve_oben_links.svg EN SW 0000100000010000 Gleis_Kurve_oben_links.svg
WN SE 0000000001001000 Gleis_Kurve_oben_rechts.svg WN SE 0000000001001000 Gleis_Kurve_oben_rechts.svg
ES NW 0001001000000000 Gleis_Kurve_unten_links.svg ES NW 0001001000000000 Gleis_Kurve_unten_links.svg
NE WS 0100000000000010 Gleis_Kurve_unten_rechts.svg NE WS 0100000000000010 Gleis_Kurve_unten_rechts.svg
NN SS 1000000000100000 Gleis_vertikal.svg NN SS 1000000000100000 Gleis_vertikal.svg
NN SS EE WW ES NW SE WN 1001011001101001 Weiche_Double_Slip.svg NN SS EE WW ES NW SE WN 1001011001101001 Weiche_Double_Slip.svg
EE WW EN SW 0000110000010001 Weiche_horizontal_oben_links.svg EE WW EN SW 0000110000010001 Weiche_horizontal_oben_links.svg
EE WW SE WN 0000010001001001 Weiche_horizontal_oben_rechts.svg EE WW SE WN 0000010001001001 Weiche_horizontal_oben_rechts.svg
EE WW ES NW 0001011000000001 Weiche_horizontal_unten_links.svg EE WW ES NW 0001011000000001 Weiche_horizontal_unten_links.svg
EE WW NE WS 0100010000000011 Weiche_horizontal_unten_rechts.svg EE WW NE WS 0100010000000011 Weiche_horizontal_unten_rechts.svg
NN SS EE WW NW ES 1001011000100001 Weiche_Single_Slip.svg NN SS EE WW NW ES 1001011000100001 Weiche_Single_Slip.svg
NE NW ES WS 0101001000000010 Weiche_Symetrical.svg NE NW ES WS 0101001000000010 Weiche_Symetrical.svg
NN SS EN SW 1000100000110000 Weiche_vertikal_oben_links.svg NN SS EN SW 1000100000110000 Weiche_vertikal_oben_links.svg
NN SS SE WN 1000000001101000 Weiche_vertikal_oben_rechts.svg NN SS SE WN 1000000001101000 Weiche_vertikal_oben_rechts.svg
NN SS NW ES 1001001000100000 Weiche_vertikal_unten_links.svg NN SS NW ES 1001001000100000 Weiche_vertikal_unten_links.svg
NN SS NE WS 1100000000100010 Weiche_vertikal_unten_rechts.svg NN SS NE WS 1100000000100010 Weiche_vertikal_unten_rechts.svg
EW 0000000100000000 Bahnhof_#d50000_Deadend_links.svg EW 0000000100000000 Bahnhof_#d50000_Deadend_links.svg
NS 0010000000000000 Bahnhof_#d50000_Deadend_oben.svg NS 0010000000000000 Bahnhof_#d50000_Deadend_oben.svg
WE 0000000000000100 Bahnhof_#d50000_Deadend_rechts.svg WE 0000000000000100 Bahnhof_#d50000_Deadend_rechts.svg
SN 0000000010000000 Bahnhof_#d50000_Deadend_unten.svg SN 0000000010000000 Bahnhof_#d50000_Deadend_unten.svg
EE WW 0000010000000001 Bahnhof_#d50000_Gleis_horizontal.svg EE WW 0000010000000001 Bahnhof_#d50000_Gleis_horizontal.svg
NN SS 1000000000100000 Bahnhof_#d50000_Gleis_vertikal.svg NN SS 1000000000100000 Bahnhof_#d50000_Gleis_vertikal.svg
Clear rails Clear rails
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
## Instructions ## Instructions
- Drag to draw (improved dead-ends) - Drag to draw (improved dead-ends)
- Shift-Drag to erase rails (erasing dead ends not yet automated - drag right across them) - Shift-Drag to erase rails (erasing dead ends not yet automated - drag right across them)
- ctrl-click to add agent - ctrl-click to add agent
- direction chosen randomly to fit rail - direction chosen randomly to fit rail
- ctrl-shift-click to add target for last agent - ctrl-shift-click to add target for last agent
- target can be moved by repeating - target can be moved by repeating
- to Resize the env (cannot preserve work): - to Resize the env (cannot preserve work):
- select "Regen" tab, set regen size slider, click regenerate. - select "Regen" tab, set regen size slider, click regenerate.
- alt-click remove all rails from cell - alt-click remove all rails from cell
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
mvc.view.display() mvc.view.display()
``` ```
%% Output %% Output
<flatland.utils.graphics_pil.PILSVG object at 0x000001E674DEF048> <class 'flatland.utils.graphics_pil.PILSVG'>
<super: <class 'PILSVG'>, <PILSVG object>> <class 'super'>
0000000000000000 Background_#91D1DD.svg
WE 0000000000000100 Gleis_Deadend.svg
WW EE NN SS 1000010000100001 Gleis_Diamond_Crossing.svg
WW EE 0000010000000001 Gleis_horizontal.svg
EN SW 0000100000010000 Gleis_Kurve_oben_links.svg
WN SE 0000000001001000 Gleis_Kurve_oben_rechts.svg
ES NW 0001001000000000 Gleis_Kurve_unten_links.svg
NE WS 0100000000000010 Gleis_Kurve_unten_rechts.svg
NN SS 1000000000100000 Gleis_vertikal.svg
NN SS EE WW ES NW SE WN 1001011001101001 Weiche_Double_Slip.svg
EE WW EN SW 0000110000010001 Weiche_horizontal_oben_links.svg
EE WW SE WN 0000010001001001 Weiche_horizontal_oben_rechts.svg
EE WW ES NW 0001011000000001 Weiche_horizontal_unten_links.svg
EE WW NE WS 0100010000000011 Weiche_horizontal_unten_rechts.svg
NN SS EE WW NW ES 1001011000100001 Weiche_Single_Slip.svg
NE NW ES WS 0101001000000010 Weiche_Symetrical.svg
NN SS EN SW 1000100000110000 Weiche_vertikal_oben_links.svg
NN SS SE WN 1000000001101000 Weiche_vertikal_oben_rechts.svg
NN SS NW ES 1001001000100000 Weiche_vertikal_unten_links.svg
NN SS NE WS 1100000000100010 Weiche_vertikal_unten_rechts.svg
EW 0000000100000000 Bahnhof_#d50000_Deadend_links.svg
NS 0010000000000000 Bahnhof_#d50000_Deadend_oben.svg
WE 0000000000000100 Bahnhof_#d50000_Deadend_rechts.svg
SN 0000000010000000 Bahnhof_#d50000_Deadend_unten.svg
EE WW 0000010000000001 Bahnhof_#d50000_Gleis_horizontal.svg
NN SS 1000000000100000 Bahnhof_#d50000_Gleis_vertikal.svg
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
mvc.view.wOutput.clear_output() mvc.view.wOutput.clear_output()
mvc.view.wOutput mvc.view.wOutput
``` ```
%% Output %% Output
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
len(mvc.editor.env.agents), len(mvc.editor.env.agents_static) len(mvc.editor.env.agents), len(mvc.editor.env.agents_static)
``` ```
%% Output %% Output
(0, 0) (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