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
pranjal_dhole
Flatland
Commits
b04d3bd7
Commit
b04d3bd7
authored
5 years ago
by
Egli Adrian (IT-SCI-API-PFI)
Browse files
Options
Downloads
Patches
Plain Diff
Editor: Random scene, clean up
parent
5232204f
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
flatland/utils/editor.py
+5
-7
5 additions, 7 deletions
flatland/utils/editor.py
notebooks/Editor2.ipynb
+23
-28
23 additions, 28 deletions
notebooks/Editor2.ipynb
with
28 additions
and
35 deletions
flatland/utils/editor.py
+
5
−
7
View file @
b04d3bd7
...
...
@@ -115,7 +115,7 @@ class View(object):
self
.
wRegenSizeHeight
.
observe
(
self
.
controller
.
setRegenSizeHeight
,
names
=
"
value
"
)
# Number of Agents when regenerating
self
.
wRegenNAgents
=
IntSlider
(
value
=
1
,
min
=
0
,
max
=
20
,
step
=
1
,
description
=
"
# Agents
"
,
self
.
wRegenNAgents
=
IntSlider
(
value
=
1
,
min
=
0
,
max
=
5
,
step
=
1
,
description
=
"
# Agents
"
,
tip
=
"
Click regenerate or reset after changing this
"
)
self
.
wRegenMethod
=
RadioButtons
(
description
=
"
Regen
\n
Method
"
,
options
=
[
"
Empty
"
,
"
Random Cell
"
,
"
Path-based
"
])
...
...
@@ -136,12 +136,11 @@ class View(object):
# abbreviated description of buttons and the methods they call
ldButtons
=
[
dict
(
name
=
"
Refresh
"
,
method
=
self
.
controller
.
refresh
,
tip
=
"
Redraw only
"
),
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
=
"
Random
"
,
method
=
self
.
controller
.
reset
,
tip
=
"
Generate a randomized scene, including regen rail + agents
"
),
dict
(
name
=
"
Regenerate
"
,
method
=
self
.
controller
.
regenerate
,
tip
=
"
Regenerate the rails using the method selected below
"
),
dict
(
name
=
"
Load
"
,
method
=
self
.
controller
.
load
),
...
...
@@ -650,8 +649,7 @@ class EditorModel(object):
def
reset
(
self
,
replace_agents
=
False
,
nAgents
=
0
):
# if replace_agents:
# self.env.agents_handles = range(nAgents)
self
.
env
.
reset
(
regen_rail
=
True
,
replace_agents
=
replace_agents
)
self
.
player
=
None
self
.
regenerate
(
"
complex
"
,
nAgents
=
nAgents
)
self
.
redraw
()
def
restartAgents
(
self
):
...
...
@@ -703,7 +701,7 @@ class EditorModel(object):
elif
method
==
"
Random Cell
"
:
fnMethod
=
random_rail_generator
(
cell_type_relative_proportion
=
[
1
]
*
11
)
else
:
fnMethod
=
complex_rail_generator
(
nr_start_goal
=
5
,
nr_extra
=
20
,
min_dist
=
12
)
fnMethod
=
complex_rail_generator
(
nr_start_goal
=
nAgents
,
nr_extra
=
20
,
min_dist
=
12
,
seed
=
int
(
time
.
time
())
)
if
env
is
None
:
self
.
env
=
RailEnv
(
width
=
self
.
regen_size_width
,
...
...
This diff is collapsed.
Click to expand it.
notebooks/Editor2.ipynb
+
23
−
28
View file @
b04d3bd7
...
...
@@ -9,18 +9,9 @@
},
{
"cell_type": "code",
"execution_count":
9
,
"execution_count":
1
,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The autoreload extension is already loaded. To reload it, use:\n",
" %reload_ext autoreload\n"
]
}
],
"outputs": [],
"source": [
"%load_ext autoreload\n",
"%autoreload 2"
...
...
@@ -28,7 +19,7 @@
},
{
"cell_type": "code",
"execution_count":
10
,
"execution_count":
2
,
"metadata": {},
"outputs": [],
"source": [
...
...
@@ -41,7 +32,7 @@
},
{
"cell_type": "code",
"execution_count":
11
,
"execution_count":
3
,
"metadata": {},
"outputs": [
{
...
...
@@ -63,23 +54,31 @@
},
{
"cell_type": "code",
"execution_count":
12
,
"execution_count":
4
,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"cairo installed: OK\n"
]
}
],
"source": [
"from flatland.utils.editor import EditorMVC, EditorModel, View, Controller"
]
},
{
"cell_type": "code",
"execution_count":
13
,
"execution_count":
5
,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"<flatland.utils.graphics_pil.PILSVG object at 0x00000
1FC6FB9E1
98> <class 'flatland.utils.graphics_pil.PILSVG'>\n",
"<flatland.utils.graphics_pil.PILSVG object at 0x00000
22E68851F
98> <class 'flatland.utils.graphics_pil.PILSVG'>\n",
"<super: <class 'PILSVG'>, <PILSVG object>> <class 'super'>\n",
"Clear rails\n"
]
...
...
@@ -116,7 +115,7 @@
},
{
"cell_type": "code",
"execution_count":
14
,
"execution_count":
6
,
"metadata": {
"scrolled": false
},
...
...
@@ -124,7 +123,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "
df04f776b29f456eabb20b9587ea1f16
",
"model_id": "
3919c0bba981455285a93e045e305a05
",
"version_major": 2,
"version_minor": 0
},
...
...
@@ -139,11 +138,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"<flatland.utils.graphics_pil.PILSVG object at 0x000001FC6FBB7FD0> <class 'flatland.utils.graphics_pil.PILSVG'>\n",
"<super: <class 'PILSVG'>, <PILSVG object>> <class 'super'>\n",
"<flatland.utils.graphics_pil.PILSVG object at 0x000001FC6FA8C5C0> <class 'flatland.utils.graphics_pil.PILSVG'>\n",
"<super: <class 'PILSVG'>, <PILSVG object>> <class 'super'>\n",
"<flatland.utils.graphics_pil.PILSVG object at 0x000001FC73AF2908> <class 'flatland.utils.graphics_pil.PILSVG'>\n",
"<flatland.utils.graphics_pil.PILSVG object at 0x0000022E6919E630> <class 'flatland.utils.graphics_pil.PILSVG'>\n",
"<super: <class 'PILSVG'>, <PILSVG object>> <class 'super'>\n"
]
}
...
...
@@ -154,7 +149,7 @@
},
{
"cell_type": "code",
"execution_count":
15
,
"execution_count":
7
,
"metadata": {
"scrolled": false
},
...
...
@@ -162,7 +157,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "
6c0846dadce244ed877d53410dcfe0
a7",
"model_id": "
b91a94da22c846808020ab2aa1bc5b
a7",
"version_major": 2,
"version_minor": 0
},
...
...
@@ -181,7 +176,7 @@
},
{
"cell_type": "code",
"execution_count":
16
,
"execution_count":
8
,
"metadata": {},
"outputs": [
{
...
...
@@ -190,7 +185,7 @@
"(0, 0)"
]
},
"execution_count":
16
,
"execution_count":
8
,
"metadata": {},
"output_type": "execute_result"
}
...
...
%% 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
```
%% Output
cairo installed: OK
%% Cell type:code id: tags:
```
python
mvc
=
EditorMVC
(
sGL
=
"
PILSVG
"
)
# sGL="PIL")
```
%% Output
<flatland.utils.graphics_pil.PILSVG object at 0x00000
1FC6FB9E1
98> <class 'flatland.utils.graphics_pil.PILSVG'>
<flatland.utils.graphics_pil.PILSVG object at 0x00000
22E68851F
98> <class 'flatland.utils.graphics_pil.PILSVG'>
<super: <class 'PILSVG'>, <PILSVG object>> <class 'super'>
Clear rails
%% 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
<flatland.utils.graphics_pil.PILSVG object at 0x000001FC6FBB7FD0> <class 'flatland.utils.graphics_pil.PILSVG'>
<super: <class 'PILSVG'>, <PILSVG object>> <class 'super'>
<flatland.utils.graphics_pil.PILSVG object at 0x000001FC6FA8C5C0> <class 'flatland.utils.graphics_pil.PILSVG'>
<super: <class 'PILSVG'>, <PILSVG object>> <class 'super'>
<flatland.utils.graphics_pil.PILSVG object at 0x000001FC73AF2908> <class 'flatland.utils.graphics_pil.PILSVG'>
<flatland.utils.graphics_pil.PILSVG object at 0x0000022E6919E630> <class 'flatland.utils.graphics_pil.PILSVG'>
<super: <class 'PILSVG'>, <PILSVG object>> <class 'super'>
%% 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)
...
...
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