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
33701dd2
Commit
33701dd2
authored
5 years ago
by
u214892
Browse files
Options
Downloads
Patches
Plain Diff
make FLATland core useable without rendering
parent
772a9826
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
flatland/action_plan/action_plan_player.py
+15
-13
15 additions, 13 deletions
flatland/action_plan/action_plan_player.py
tests/test_action_plan.py
+14
-1
14 additions, 1 deletion
tests/test_action_plan.py
with
29 additions
and
14 deletions
flatland/action_plan/action_plan_player.py
+
15
−
13
View file @
33701dd2
from
typing
import
Callable
from
flatland.action_plan.action_plan
import
ControllerFromTrainruns
from
flatland.envs.rail_env
import
RailEnv
from
flatland.envs.rail_trainrun_data_structures
import
Waypoint
from
flatland.utils.rendertools
import
RenderTool
,
AgentRenderVariant
class
ControllerFromTrainrunsReplayer
():
"""
Allows to verify a `DeterministicController` by replaying it against a FLATland env without malfunction.
"""
@staticmethod
def
replay_verify
(
ctl
:
ControllerFromTrainruns
,
env
:
RailEnv
,
rendering
:
bool
):
"""
Replays this deterministic `ActionPlan` and verifies whether it is feasible.
"""
if
rendering
:
renderer
=
RenderTool
(
env
,
gl
=
"
PILSVG
"
,
agent_render_variant
=
AgentRenderVariant
.
AGENT_SHOWS_OPTIONS_AND_BOX
,
show_debug
=
True
,
clear_debug_text
=
True
,
screen_height
=
1000
,
screen_width
=
1000
)
renderer
.
render_env
(
show
=
True
,
show_observations
=
False
,
show_predictions
=
False
)
def
replay_verify
(
ctl
:
ControllerFromTrainruns
,
env
:
RailEnv
,
call_back
:
Callable
[[
RailEnv
],
None
]
=
lambda
*
a
,
**
k
:
None
):
"""
Replays this deterministic `ActionPlan` and verifies whether it is feasible.
Parameters
----------
ctl
env
call_back
Called before/after each step() call. The env is passed to it.
"""
call_back
(
env
)
i
=
0
while
not
env
.
dones
[
'
__all__
'
]
and
i
<=
env
.
_max_episode_steps
:
for
agent_id
,
agent
in
enumerate
(
env
.
agents
):
...
...
@@ -30,7 +33,6 @@ class ControllerFromTrainrunsReplayer():
obs
,
all_rewards
,
done
,
_
=
env
.
step
(
actions
)
if
rendering
:
renderer
.
render_env
(
show
=
True
,
show_observations
=
False
,
show_predictions
=
False
)
call_back
(
env
)
i
+=
1
This diff is collapsed.
Click to expand it.
tests/test_action_plan.py
+
14
−
1
View file @
33701dd2
...
...
@@ -7,6 +7,7 @@ from flatland.envs.rail_env import RailEnv, RailEnvActions
from
flatland.envs.rail_generators
import
rail_from_grid_transition_map
from
flatland.envs.rail_trainrun_data_structures
import
Waypoint
from
flatland.envs.schedule_generators
import
random_schedule_generator
from
flatland.utils.rendertools
import
RenderTool
,
AgentRenderVariant
from
flatland.utils.simple_rail
import
make_simple_rail
...
...
@@ -84,4 +85,16 @@ def test_action_plan(rendering: bool = False):
deterministic_controller
=
ControllerFromTrainruns
(
env
,
chosen_path_dict
)
deterministic_controller
.
print_action_plan
()
ControllerFromTrainruns
.
assert_actions_plans_equal
(
expected_action_plan
,
deterministic_controller
.
action_plan
)
ControllerFromTrainrunsReplayer
.
replay_verify
(
deterministic_controller
,
env
,
rendering
)
if
rendering
:
renderer
=
RenderTool
(
env
,
gl
=
"
PILSVG
"
,
agent_render_variant
=
AgentRenderVariant
.
AGENT_SHOWS_OPTIONS_AND_BOX
,
show_debug
=
True
,
clear_debug_text
=
True
,
screen_height
=
1000
,
screen_width
=
1000
)
def
render
(
*
argv
):
if
rendering
:
renderer
.
render_env
(
show
=
True
,
show_observations
=
False
,
show_predictions
=
False
)
ControllerFromTrainrunsReplayer
.
replay_verify
(
deterministic_controller
,
env
,
call_back
=
render
)
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