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
Package Registry
Model registry
Operate
Environments
Terraform modules
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
elrichgro
Flatland
Commits
8edce041
Commit
8edce041
authored
5 years ago
by
spiglerg
Browse files
Options
Downloads
Plain Diff
refactored env observations ISSUE #24 + fixed most pylint errors
parents
12138cdb
dc2fa1ee
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/rendertools.py
+15
-15
15 additions, 15 deletions
flatland/utils/rendertools.py
tests/test_rendertools.py
+4
-0
4 additions, 0 deletions
tests/test_rendertools.py
with
19 additions
and
15 deletions
flatland/utils/rendertools.py
+
15
−
15
View file @
8edce041
...
...
@@ -130,7 +130,7 @@ class RenderTool(object):
self
.
gl
=
PILGL
(
env
.
width
,
env
.
height
)
elif
gl
==
"
QTSVG
"
:
self
.
gl
=
QTSVG
(
env
.
width
,
env
.
height
)
self
.
new_rail
=
True
def
set_new_rail
(
self
):
...
...
@@ -153,14 +153,14 @@ class RenderTool(object):
def
plotAgents
(
self
,
targets
=
True
,
iSelectedAgent
=
None
):
cmap
=
self
.
gl
.
get_cmap
(
'
hsv
'
,
lut
=
max
(
len
(
self
.
env
.
agents
),
len
(
self
.
env
.
agents_static
)
+
1
))
lut
=
max
(
len
(
self
.
env
.
agents
),
len
(
self
.
env
.
agents_static
)
+
1
))
for
iAgent
,
agent
in
enumerate
(
self
.
env
.
agents_static
):
if
agent
is
None
:
continue
oColor
=
cmap
(
iAgent
)
self
.
plotAgent
(
agent
.
position
,
agent
.
direction
,
oColor
,
target
=
agent
.
target
if
targets
else
None
,
static
=
True
,
selected
=
iAgent
==
iSelectedAgent
)
static
=
True
,
selected
=
iAgent
==
iSelectedAgent
)
for
iAgent
,
agent
in
enumerate
(
self
.
env
.
agents
):
if
agent
is
None
:
...
...
@@ -488,9 +488,9 @@ class RenderTool(object):
if
not
self
.
gl
.
is_raster
():
self
.
renderEnv2
(
show
,
curves
,
spacing
,
arrows
,
agents
,
sRailColor
,
frames
,
iEpisode
,
iStep
,
iSelectedAgent
,
action_dict
)
arrows
,
agents
,
sRailColor
,
frames
,
iEpisode
,
iStep
,
iSelectedAgent
,
action_dict
)
return
# cell_size is a bit pointless with matplotlib - it does not relate to pixels,
...
...
@@ -667,16 +667,16 @@ class RenderTool(object):
for
i
in
range
(
nDepth
):
nDepthNodes
=
nBranchFactor
**
i
# rScale = nBranchFactor ** (nDepth - i)
rShrinkDepth
=
1
/
(
i
+
1
)
rShrinkDepth
=
1
/
(
i
+
1
)
# gX1 = np.linspace(-nDepthNodes / 2, nDepthNodes / 2, nDepthNodes) * rShrinkDepth
gX1
=
np
.
linspace
(
-
(
nDepthNodes
-
1
),
(
nDepthNodes
-
1
),
nDepthNodes
)
*
rShrinkDepth
gX1
=
np
.
linspace
(
-
(
nDepthNodes
-
1
),
(
nDepthNodes
-
1
),
nDepthNodes
)
*
rShrinkDepth
gY1
=
np
.
ones
((
nDepthNodes
))
*
i
gZ1
=
np
.
zeros
((
nDepthNodes
))
gP1
=
array
([
gX1
,
gY1
,
gZ1
])
gP01
=
np
.
append
(
gP0
,
gP1
,
axis
=
1
)
if
nDepthNodes
>
1
:
nDepthNodesPrev
=
nDepthNodes
/
nBranchFactor
giP0
=
np
.
repeat
(
np
.
arange
(
nDepthNodesPrev
),
nBranchFactor
)
...
...
@@ -687,7 +687,7 @@ class RenderTool(object):
self
.
gl
.
plot
(
gP01
[
0
],
-
gP01
[
1
],
lines
=
giLinePoints
,
color
=
"
gray
"
)
gP0
=
array
([
gX1
,
gY1
,
gZ1
])
def
renderEnv2
(
self
,
show
=
False
,
curves
=
True
,
spacing
=
False
,
arrows
=
False
,
agents
=
True
,
sRailColor
=
"
gray
"
,
...
...
@@ -715,7 +715,7 @@ class RenderTool(object):
self
.
gl
.
setRailAt
(
r
,
c
,
binTrans
)
cmap
=
self
.
gl
.
get_cmap
(
'
hsv
'
,
lut
=
max
(
len
(
self
.
env
.
agents
),
len
(
self
.
env
.
agents_static
)
+
1
))
lut
=
max
(
len
(
self
.
env
.
agents
),
len
(
self
.
env
.
agents_static
)
+
1
))
for
iAgent
,
agent
in
enumerate
(
self
.
env
.
agents
):
if
agent
is
None
:
...
...
@@ -729,14 +729,14 @@ class RenderTool(object):
if
iAgent
in
action_dict
:
iAction
=
action_dict
[
iAgent
]
new_direction
,
action_isValid
=
self
.
env
.
check_action
(
agent
,
iAction
)
if
action_isValid
:
self
.
gl
.
setAgentAt
(
iAgent
,
*
agent
.
position
,
agent
.
direction
,
new_direction
,
color
=
oColor
)
else
:
pass
# print("invalid action - agent ", iAgent, " bend ", agent.direction, new_direction)
# self.gl.setAgentAt(iAgent, *agent.position, agent.direction, new_direction)
self
.
gl
.
show
()
for
i
in
range
(
3
):
self
.
gl
.
processEvents
()
...
...
This diff is collapsed.
Click to expand it.
tests/test_rendertools.py
+
4
−
0
View file @
8edce041
...
...
@@ -6,6 +6,10 @@ Tests for `flatland` package.
from
flatland.envs.rail_env
import
RailEnv
,
random_rail_generator
import
numpy
as
np
<<<<<<<
HEAD
=======
# import os
>>>>>>>
dc2fa1ee0244b15c76d89ab768c5e1bbd2716147
import
sys
import
matplotlib.pyplot
as
plt
...
...
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