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
yoogottamk
Flatland
Commits
c361c45b
Commit
c361c45b
authored
5 years ago
by
hagrid67
Browse files
Options
Downloads
Patches
Plain Diff
plot targets. play with larger grid 15x15, 5 agents. delay=0.
parent
0a43b421
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/play_model.py
+6
-6
6 additions, 6 deletions
examples/play_model.py
flatland/utils/render_qt.py
+1
-0
1 addition, 0 deletions
flatland/utils/render_qt.py
flatland/utils/rendertools.py
+16
-7
16 additions, 7 deletions
flatland/utils/rendertools.py
with
23 additions
and
13 deletions
examples/play_model.py
+
6
−
6
View file @
c361c45b
...
@@ -10,7 +10,7 @@ import matplotlib.pyplot as plt
...
@@ -10,7 +10,7 @@ import matplotlib.pyplot as plt
import
time
import
time
def
main
(
render
=
True
,
delay
=
2
):
def
main
(
render
=
True
,
delay
=
0.0
):
random
.
seed
(
1
)
random
.
seed
(
1
)
np
.
random
.
seed
(
1
)
np
.
random
.
seed
(
1
)
...
@@ -27,10 +27,10 @@ def main(render=True, delay=2):
...
@@ -27,10 +27,10 @@ def main(render=True, delay=2):
0.0
]
# Case 7 - dead end
0.0
]
# Case 7 - dead end
# Example generate a random rail
# Example generate a random rail
env
=
RailEnv
(
width
=
7
,
env
=
RailEnv
(
width
=
15
,
height
=
7
,
height
=
15
,
rail_generator
=
random_rail_generator
(
cell_type_relative_proportion
=
transition_probability
),
rail_generator
=
random_rail_generator
(
cell_type_relative_proportion
=
transition_probability
),
number_of_agents
=
1
)
number_of_agents
=
5
)
if
render
:
if
render
:
env_renderer
=
RenderTool
(
env
,
gl
=
"
QT
"
)
env_renderer
=
RenderTool
(
env
,
gl
=
"
QT
"
)
...
@@ -52,7 +52,7 @@ def main(render=True, delay=2):
...
@@ -52,7 +52,7 @@ def main(render=True, delay=2):
dones_list
=
[]
dones_list
=
[]
action_prob
=
[
0
]
*
4
action_prob
=
[
0
]
*
4
agent
=
Agent
(
state_size
,
action_size
,
"
FC
"
,
0
)
agent
=
Agent
(
state_size
,
action_size
,
"
FC
"
,
0
)
agent
.
qnetwork_local
.
load_state_dict
(
torch
.
load
(
'
../flatland/baselines/Nets/avoid_checkpoint9900.pth
'
))
#
agent.qnetwork_local.load_state_dict(torch.load('../flatland/baselines/Nets/avoid_checkpoint9900.pth'))
def
max_lt
(
seq
,
val
):
def
max_lt
(
seq
,
val
):
"""
"""
...
@@ -108,7 +108,7 @@ def main(render=True, delay=2):
...
@@ -108,7 +108,7 @@ def main(render=True, delay=2):
env_renderer
.
renderEnv
(
show
=
True
,
frames
=
True
,
iEpisode
=
trials
,
iStep
=
step
)
env_renderer
.
renderEnv
(
show
=
True
,
frames
=
True
,
iEpisode
=
trials
,
iStep
=
step
)
if
delay
>
0
:
if
delay
>
0
:
time
.
sleep
(
delay
)
time
.
sleep
(
delay
)
iFrame
+=
1
iFrame
+=
1
...
...
This diff is collapsed.
Click to expand it.
flatland/utils/render_qt.py
+
1
−
0
View file @
c361c45b
...
@@ -73,6 +73,7 @@ class QTGL(GraphicsLayer):
...
@@ -73,6 +73,7 @@ class QTGL(GraphicsLayer):
def
scatter
(
self
,
gX
,
gY
,
color
=
None
,
marker
=
"
o
"
,
size
=
5
,
*
args
,
**
kwargs
):
def
scatter
(
self
,
gX
,
gY
,
color
=
None
,
marker
=
"
o
"
,
size
=
5
,
*
args
,
**
kwargs
):
color
=
self
.
adaptColor
(
color
)
color
=
self
.
adaptColor
(
color
)
self
.
qtr
.
setColor
(
*
color
)
self
.
qtr
.
setColor
(
*
color
)
self
.
qtr
.
setLineColor
(
*
color
)
r
=
np
.
sqrt
(
size
)
r
=
np
.
sqrt
(
size
)
gPoints
=
np
.
stack
([
np
.
atleast_1d
(
gX
),
-
np
.
atleast_1d
(
gY
)]).
T
*
self
.
cell_pixels
gPoints
=
np
.
stack
([
np
.
atleast_1d
(
gX
),
-
np
.
atleast_1d
(
gY
)]).
T
*
self
.
cell_pixels
for
x
,
y
in
gPoints
:
for
x
,
y
in
gPoints
:
...
...
This diff is collapsed.
Click to expand it.
flatland/utils/rendertools.py
+
16
−
7
View file @
c361c45b
...
@@ -134,7 +134,7 @@ class RenderTool(object):
...
@@ -134,7 +134,7 @@ class RenderTool(object):
gTransRCAg
=
rt
.
gTransRC
[
giTrans
]
gTransRCAg
=
rt
.
gTransRC
[
giTrans
]
self
.
plotTrans
(
visit
.
rc
,
gTransRCAg
,
depth
=
str
(
visit
.
iDepth
),
color
=
color
)
self
.
plotTrans
(
visit
.
rc
,
gTransRCAg
,
depth
=
str
(
visit
.
iDepth
),
color
=
color
)
def
plotAgents
(
self
):
def
plotAgents
(
self
,
targets
=
True
):
cmap
=
self
.
gl
.
get_cmap
(
'
hsv
'
,
lut
=
self
.
env
.
number_of_agents
+
1
)
cmap
=
self
.
gl
.
get_cmap
(
'
hsv
'
,
lut
=
self
.
env
.
number_of_agents
+
1
)
for
iAgent
in
range
(
self
.
env
.
number_of_agents
):
for
iAgent
in
range
(
self
.
env
.
number_of_agents
):
oColor
=
cmap
(
iAgent
)
oColor
=
cmap
(
iAgent
)
...
@@ -142,7 +142,11 @@ class RenderTool(object):
...
@@ -142,7 +142,11 @@ class RenderTool(object):
rcPos
=
self
.
env
.
agents_position
[
iAgent
]
rcPos
=
self
.
env
.
agents_position
[
iAgent
]
iDir
=
self
.
env
.
agents_direction
[
iAgent
]
# agent direction index
iDir
=
self
.
env
.
agents_direction
[
iAgent
]
# agent direction index
self
.
plotAgent
(
rcPos
,
iDir
,
oColor
)
if
targets
:
target
=
self
.
env
.
agents_target
[
iAgent
]
else
:
target
=
None
self
.
plotAgent
(
rcPos
,
iDir
,
oColor
,
target
=
target
)
# gTransRCAg = self.getTransRC(rcPos, iDir)
# gTransRCAg = self.getTransRC(rcPos, iDir)
# self.plotTrans(rcPos, gTransRCAg)
# self.plotTrans(rcPos, gTransRCAg)
...
@@ -183,7 +187,7 @@ class RenderTool(object):
...
@@ -183,7 +187,7 @@ class RenderTool(object):
else
:
else
:
return
gTransRCAg
return
gTransRCAg
def
plotAgent
(
self
,
rcPos
,
iDir
,
sC
olor
=
"
r
"
):
def
plotAgent
(
self
,
rcPos
,
iDir
,
c
olor
=
"
r
"
,
target
=
None
):
"""
"""
Plot a simple agent.
Plot a simple agent.
Assumes a working graphics layer context (cf a MPL figure).
Assumes a working graphics layer context (cf a MPL figure).
...
@@ -194,16 +198,21 @@ class RenderTool(object):
...
@@ -194,16 +198,21 @@ class RenderTool(object):
xyDir
=
np
.
matmul
(
rcDir
,
rt
.
grc2xy
)
# agent direction in xy
xyDir
=
np
.
matmul
(
rcDir
,
rt
.
grc2xy
)
# agent direction in xy
xyPos
=
np
.
matmul
(
rcPos
-
rcDir
/
2
,
rt
.
grc2xy
)
+
rt
.
xyHalf
xyPos
=
np
.
matmul
(
rcPos
-
rcDir
/
2
,
rt
.
grc2xy
)
+
rt
.
xyHalf
self
.
gl
.
scatter
(
*
xyPos
,
color
=
sC
olor
,
size
=
1
0
)
# agent location
self
.
gl
.
scatter
(
*
xyPos
,
color
=
c
olor
,
size
=
4
0
)
# agent location
xyDirLine
=
array
([
xyPos
,
xyPos
+
xyDir
/
2
]).
T
# line for agent orient.
xyDirLine
=
array
([
xyPos
,
xyPos
+
xyDir
/
2
]).
T
# line for agent orient.
self
.
gl
.
plot
(
*
xyDirLine
,
color
=
sColor
,
lw
=
5
,
ms
=
0
,
alpha
=
0.6
)
self
.
gl
.
plot
(
*
xyDirLine
,
color
=
color
,
lw
=
5
,
ms
=
0
,
alpha
=
0.6
)
if
target
is
not
None
:
rcTarget
=
array
(
target
)
xyTarget
=
np
.
matmul
(
rcTarget
,
rt
.
grc2xy
)
+
rt
.
xyHalf
self
.
_draw_square
(
xyTarget
,
1
/
3
,
color
)
if
False
:
if
False
:
# mark the next cell we're heading into
# mark the next cell we're heading into
rcNext
=
rcPos
+
rcDir
rcNext
=
rcPos
+
rcDir
xyNext
=
np
.
matmul
(
rcNext
,
rt
.
grc2xy
)
+
rt
.
xyHalf
xyNext
=
np
.
matmul
(
rcNext
,
rt
.
grc2xy
)
+
rt
.
xyHalf
self
.
gl
.
scatter
(
*
xyNext
,
color
=
sC
olor
)
self
.
gl
.
scatter
(
*
xyNext
,
color
=
c
olor
)
def
plotTrans
(
self
,
rcPos
,
gTransRCAg
,
color
=
"
r
"
,
depth
=
None
):
def
plotTrans
(
self
,
rcPos
,
gTransRCAg
,
color
=
"
r
"
,
depth
=
None
):
"""
"""
...
@@ -571,7 +580,7 @@ class RenderTool(object):
...
@@ -571,7 +580,7 @@ class RenderTool(object):
# Draw each agent + its orientation + its target
# Draw each agent + its orientation + its target
if
agents
:
if
agents
:
cmap
=
self
.
gl
.
get_cmap
(
'
hsv
'
,
lut
=
env
.
number_of_agents
+
1
)
cmap
=
self
.
gl
.
get_cmap
(
'
hsv
'
,
lut
=
env
.
number_of_agents
+
1
)
self
.
plotAgents
()
self
.
plotAgents
(
targets
=
True
)
if
False
:
if
False
:
for
i
in
range
(
env
.
number_of_agents
):
for
i
in
range
(
env
.
number_of_agents
):
...
...
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