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
0744a856
Commit
0744a856
authored
5 years ago
by
Egli Adrian (IT-SCI-API-PFI)
Browse files
Options
Downloads
Patches
Plain Diff
added variants of rendering: see AgentRenderVariant
parent
4548fa8b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
examples/simple_example_3.py
+1
-1
1 addition, 1 deletion
examples/simple_example_3.py
flatland/utils/rendertools.py
+41
-10
41 additions, 10 deletions
flatland/utils/rendertools.py
with
42 additions
and
11 deletions
examples/simple_example_3.py
+
1
−
1
View file @
0744a856
...
@@ -2,7 +2,7 @@ import random
...
@@ -2,7 +2,7 @@ import random
import
numpy
as
np
import
numpy
as
np
from
flatland.envs.generators
import
random_rail_generator
,
complex_rail_generator
from
flatland.envs.generators
import
complex_rail_generator
from
flatland.envs.observations
import
TreeObsForRailEnv
from
flatland.envs.observations
import
TreeObsForRailEnv
from
flatland.envs.rail_env
import
RailEnv
from
flatland.envs.rail_env
import
RailEnv
from
flatland.utils.rendertools
import
RenderTool
from
flatland.utils.rendertools
import
RenderTool
...
...
This diff is collapsed.
Click to expand it.
flatland/utils/rendertools.py
+
41
−
10
View file @
0744a856
import
time
import
time
from
collections
import
deque
from
collections
import
deque
from
enum
import
IntEnum
import
numpy
as
np
import
numpy
as
np
from
numpy
import
array
from
numpy
import
array
...
@@ -10,6 +11,13 @@ from flatland.utils.graphics_pil import PILGL, PILSVG
...
@@ -10,6 +11,13 @@ from flatland.utils.graphics_pil import PILGL, PILSVG
# TODO: suggested renaming to RailEnvRenderTool, as it will only work with RailEnv!
# TODO: suggested renaming to RailEnvRenderTool, as it will only work with RailEnv!
class
AgentRenderVariant
(
IntEnum
):
BOX_ONLY
=
0
ONE_STEP_BEHIND
=
1
AGENT_SHOWS_OPTIONS
=
2
ONE_STEP_BEHIND_AND_BOX
=
3
AGENT_SHOWS_OPTIONS_AND_BOX
=
4
class
RenderTool
(
object
):
class
RenderTool
(
object
):
"""
Class to render the RailEnv and agents.
"""
Class to render the RailEnv and agents.
...
@@ -30,12 +38,14 @@ class RenderTool(object):
...
@@ -30,12 +38,14 @@ class RenderTool(object):
gTheta
=
np
.
linspace
(
0
,
np
.
pi
/
2
,
5
)
gTheta
=
np
.
linspace
(
0
,
np
.
pi
/
2
,
5
)
gArc
=
array
([
np
.
cos
(
gTheta
),
np
.
sin
(
gTheta
)]).
T
# from [1,0] to [0,1]
gArc
=
array
([
np
.
cos
(
gTheta
),
np
.
sin
(
gTheta
)]).
T
# from [1,0] to [0,1]
def
__init__
(
self
,
env
,
gl
=
"
PILSVG
"
,
jupyter
=
False
):
def
__init__
(
self
,
env
,
gl
=
"
PILSVG
"
,
jupyter
=
False
,
agentRenderVariant
=
AgentRenderVariant
.
AGENT_SHOWS_OPTIONS
):
self
.
env
=
env
self
.
env
=
env
self
.
iFrame
=
0
self
.
iFrame
=
0
self
.
time1
=
time
.
time
()
self
.
time1
=
time
.
time
()
self
.
lTimes
=
deque
()
self
.
lTimes
=
deque
()
self
.
agentRenderVariant
=
agentRenderVariant
if
gl
==
"
PIL
"
:
if
gl
==
"
PIL
"
:
self
.
gl
=
PILGL
(
env
.
width
,
env
.
height
,
jupyter
)
self
.
gl
=
PILGL
(
env
.
width
,
env
.
height
,
jupyter
)
elif
gl
==
"
PILSVG
"
:
elif
gl
==
"
PILSVG
"
:
...
@@ -664,18 +674,39 @@ class RenderTool(object):
...
@@ -664,18 +674,39 @@ class RenderTool(object):
if
agent
is
None
:
if
agent
is
None
:
continue
continue
if
agent
.
old_position
is
not
None
:
if
self
.
agentRenderVariant
==
AgentRenderVariant
.
BOX_ONLY
:
position
=
agent
.
old_position
self
.
gl
.
setCellOccupied
(
iAgent
,
*
(
agent
.
position
))
direction
=
agent
.
direction
elif
self
.
agentRenderVariant
==
AgentRenderVariant
.
ONE_STEP_BEHIND
or
\
old_direction
=
agent
.
old_direction
self
.
agentRenderVariant
==
AgentRenderVariant
.
ONE_STEP_BEHIND_AND_BOX
:
if
agent
.
old_position
is
not
None
:
position
=
agent
.
old_position
direction
=
agent
.
direction
old_direction
=
agent
.
old_direction
else
:
position
=
agent
.
position
direction
=
agent
.
direction
old_direction
=
agent
.
direction
# setAgentAt uses the agent index for the color
if
self
.
agentRenderVariant
==
AgentRenderVariant
.
ONE_STEP_BEHIND_AND_BOX
:
self
.
gl
.
setCellOccupied
(
iAgent
,
*
(
agent
.
position
))
self
.
gl
.
setAgentAt
(
iAgent
,
*
position
,
old_direction
,
direction
,
iSelectedAgent
==
iAgent
)
else
:
else
:
position
=
agent
.
position
position
=
agent
.
position
direction
=
agent
.
direction
direction
=
agent
.
direction
old_direction
=
agent
.
direction
for
possible_directions
in
range
(
4
):
# Is a transition along movement `desired_movement_from_new_cell' to the current cell possible?
# setAgentAt uses the agent index for the color
isValid
=
env
.
rail
.
get_transition
((
*
agent
.
position
,
agent
.
direction
),
possible_directions
)
self
.
gl
.
setCellOccupied
(
iAgent
,
*
(
agent
.
position
))
if
isValid
:
self
.
gl
.
setAgentAt
(
iAgent
,
*
position
,
old_direction
,
direction
,
iSelectedAgent
==
iAgent
)
direction
=
possible_directions
# setAgentAt uses the agent index for the color
self
.
gl
.
setAgentAt
(
iAgent
,
*
position
,
agent
.
direction
,
direction
,
iSelectedAgent
==
iAgent
)
# setAgentAt uses the agent index for the color
if
self
.
agentRenderVariant
==
AgentRenderVariant
.
AGENT_SHOWS_OPTIONS_AND_BOX
:
self
.
gl
.
setCellOccupied
(
iAgent
,
*
(
agent
.
position
))
self
.
gl
.
setAgentAt
(
iAgent
,
*
position
,
agent
.
direction
,
direction
,
iSelectedAgent
==
iAgent
)
if
show_observations
:
if
show_observations
:
self
.
renderObs
(
range
(
env
.
get_num_agents
()),
env
.
dev_obs_dict
)
self
.
renderObs
(
range
(
env
.
get_num_agents
()),
env
.
dev_obs_dict
)
...
...
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