Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Flatland
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
sfwatergit
Flatland
Commits
18a63599
Commit
18a63599
authored
5 years ago
by
Egli Adrian (IT-SCI-API-PFI)
Browse files
Options
Downloads
Patches
Plain Diff
load -> step(s) works in editor
parent
6fc2266b
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
examples/demo.py
+8
-3
8 additions, 3 deletions
examples/demo.py
flatland/utils/editor.py
+9
-2
9 additions, 2 deletions
flatland/utils/editor.py
notebooks/Editor2.ipynb
+37
-3
37 additions, 3 deletions
notebooks/Editor2.ipynb
with
54 additions
and
8 deletions
examples/demo.py
+
8
−
3
View file @
18a63599
...
@@ -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
This diff is collapsed.
Click to expand it.
flatland/utils/editor.py
+
9
−
2
View file @
18a63599
...
@@ -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
"
,
...
...
This diff is collapsed.
Click to expand it.
notebooks/Editor2.ipynb
+
37
−
3
View file @
18a63599
...
@@ -78,7 +78,7 @@
...
@@ -78,7 +78,7 @@
"name": "stdout",
"name": "stdout",
"output_type": "stream",
"output_type": "stream",
"text": [
"text": [
"<flatland.utils.graphics_pil.PILSVG object at 0x000001
C03C7A3080
> <class 'flatland.utils.graphics_pil.PILSVG'>\n",
"<flatland.utils.graphics_pil.PILSVG object at 0x000001
E6748D1128
> <class 'flatland.utils.graphics_pil.PILSVG'>\n",
"<super: <class 'PILSVG'>, <PILSVG object>> <class 'super'>\n",
"<super: <class 'PILSVG'>, <PILSVG object>> <class 'super'>\n",
" 0000000000000000 Background_#91D1DD.svg\n",
" 0000000000000000 Background_#91D1DD.svg\n",
"WE 0000000000000100 Gleis_Deadend.svg\n",
"WE 0000000000000100 Gleis_Deadend.svg\n",
...
@@ -149,7 +149,7 @@
...
@@ -149,7 +149,7 @@
{
{
"data": {
"data": {
"application/vnd.jupyter.widget-view+json": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "
82d6d69b02d14d51b773a3c2257844e6
",
"model_id": "
0fd27ca20d9c411586c8ccae843f3950
",
"version_major": 2,
"version_major": 2,
"version_minor": 0
"version_minor": 0
},
},
...
@@ -159,6 +159,40 @@
...
@@ -159,6 +159,40 @@
},
},
"metadata": {},
"metadata": {},
"output_type": "display_data"
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"<flatland.utils.graphics_pil.PILSVG object at 0x000001E674DEF048> <class 'flatland.utils.graphics_pil.PILSVG'>\n",
"<super: <class 'PILSVG'>, <PILSVG object>> <class 'super'>\n",
" 0000000000000000 Background_#91D1DD.svg\n",
"WE 0000000000000100 Gleis_Deadend.svg\n",
"WW EE NN SS 1000010000100001 Gleis_Diamond_Crossing.svg\n",
"WW EE 0000010000000001 Gleis_horizontal.svg\n",
"EN SW 0000100000010000 Gleis_Kurve_oben_links.svg\n",
"WN SE 0000000001001000 Gleis_Kurve_oben_rechts.svg\n",
"ES NW 0001001000000000 Gleis_Kurve_unten_links.svg\n",
"NE WS 0100000000000010 Gleis_Kurve_unten_rechts.svg\n",
"NN SS 1000000000100000 Gleis_vertikal.svg\n",
"NN SS EE WW ES NW SE WN 1001011001101001 Weiche_Double_Slip.svg\n",
"EE WW EN SW 0000110000010001 Weiche_horizontal_oben_links.svg\n",
"EE WW SE WN 0000010001001001 Weiche_horizontal_oben_rechts.svg\n",
"EE WW ES NW 0001011000000001 Weiche_horizontal_unten_links.svg\n",
"EE WW NE WS 0100010000000011 Weiche_horizontal_unten_rechts.svg\n",
"NN SS EE WW NW ES 1001011000100001 Weiche_Single_Slip.svg\n",
"NE NW ES WS 0101001000000010 Weiche_Symetrical.svg\n",
"NN SS EN SW 1000100000110000 Weiche_vertikal_oben_links.svg\n",
"NN SS SE WN 1000000001101000 Weiche_vertikal_oben_rechts.svg\n",
"NN SS NW ES 1001001000100000 Weiche_vertikal_unten_links.svg\n",
"NN SS NE WS 1100000000100010 Weiche_vertikal_unten_rechts.svg\n",
"EW 0000000100000000 Bahnhof_#d50000_Deadend_links.svg\n",
"NS 0010000000000000 Bahnhof_#d50000_Deadend_oben.svg\n",
"WE 0000000000000100 Bahnhof_#d50000_Deadend_rechts.svg\n",
"SN 0000000010000000 Bahnhof_#d50000_Deadend_unten.svg\n",
"EE WW 0000010000000001 Bahnhof_#d50000_Gleis_horizontal.svg\n",
"NN SS 1000000000100000 Bahnhof_#d50000_Gleis_vertikal.svg\n"
]
}
}
],
],
"source": [
"source": [
...
@@ -175,7 +209,7 @@
...
@@ -175,7 +209,7 @@
{
{
"data": {
"data": {
"application/vnd.jupyter.widget-view+json": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "
047cd0c1a66e47ae9fcdbcef6eb6773d
",
"model_id": "
e4c58e43c54847c7bc4ad0327ca506d8
",
"version_major": 2,
"version_major": 2,
"version_minor": 0
"version_minor": 0
},
},
...
...
%% 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 0x000001
C03C7A3080
> <class 'flatland.utils.graphics_pil.PILSVG'>
<flatland.utils.graphics_pil.PILSVG object at 0x000001
E6748D1128
> <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)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment