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
Flatland
Flatland
Commits
772a9826
Commit
772a9826
authored
5 years ago
by
u214892
Browse files
Options
Downloads
Patches
Plain Diff
make FLATland core useable without rendering
parent
c9b4f94b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!281
Core without rendering
Pipeline
#2857
passed
5 years ago
Stage: tests
Stage: integration_testing
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
flatland/action_plan/action_plan.py
+0
-33
0 additions, 33 deletions
flatland/action_plan/action_plan.py
flatland/action_plan/action_plan_player.py
+36
-0
36 additions, 0 deletions
flatland/action_plan/action_plan_player.py
tests/test_action_plan.py
+2
-1
2 additions, 1 deletion
tests/test_action_plan.py
with
38 additions
and
34 deletions
flatland/action_plan/action_plan.py
+
0
−
33
View file @
772a9826
...
...
@@ -7,7 +7,6 @@ from flatland.core.grid.grid_utils import Vec2dOperations as Vec2d
from
flatland.envs.rail_env
import
RailEnv
,
RailEnvActions
from
flatland.envs.rail_env_shortest_paths
import
get_action_for_move
from
flatland.envs.rail_trainrun_data_structures
import
Waypoint
,
Trainrun
,
TrainrunWaypoint
from
flatland.utils.rendertools
import
RenderTool
,
AgentRenderVariant
# ---- ActionPlan ---------------
# an action plan element represents the actions to be taken by an agent at the given time step
...
...
@@ -264,35 +263,3 @@ class ControllerFromTrainruns():
# execute the action exactly minimum_cell_time before the entry into the next cell
action
=
ActionPlanElement
(
next_trainrun_waypoint
.
scheduled_at
-
minimum_cell_time
,
next_action
)
action_plan
.
append
(
action
)
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
)
i
=
0
while
not
env
.
dones
[
'
__all__
'
]
and
i
<=
env
.
_max_episode_steps
:
for
agent_id
,
agent
in
enumerate
(
env
.
agents
):
waypoint
:
Waypoint
=
ctl
.
get_waypoint_before_or_at_step
(
agent_id
,
i
)
assert
agent
.
position
==
waypoint
.
position
,
\
"
before {}, agent {} at {}, expected {}
"
.
format
(
i
,
agent_id
,
agent
.
position
,
waypoint
.
position
)
actions
=
ctl
.
act
(
i
)
print
(
"
actions for {}: {}
"
.
format
(
i
,
actions
))
obs
,
all_rewards
,
done
,
_
=
env
.
step
(
actions
)
if
rendering
:
renderer
.
render_env
(
show
=
True
,
show_observations
=
False
,
show_predictions
=
False
)
i
+=
1
This diff is collapsed.
Click to expand it.
flatland/action_plan/action_plan_player.py
0 → 100644
+
36
−
0
View file @
772a9826
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
)
i
=
0
while
not
env
.
dones
[
'
__all__
'
]
and
i
<=
env
.
_max_episode_steps
:
for
agent_id
,
agent
in
enumerate
(
env
.
agents
):
waypoint
:
Waypoint
=
ctl
.
get_waypoint_before_or_at_step
(
agent_id
,
i
)
assert
agent
.
position
==
waypoint
.
position
,
\
"
before {}, agent {} at {}, expected {}
"
.
format
(
i
,
agent_id
,
agent
.
position
,
waypoint
.
position
)
actions
=
ctl
.
act
(
i
)
print
(
"
actions for {}: {}
"
.
format
(
i
,
actions
))
obs
,
all_rewards
,
done
,
_
=
env
.
step
(
actions
)
if
rendering
:
renderer
.
render_env
(
show
=
True
,
show_observations
=
False
,
show_predictions
=
False
)
i
+=
1
This diff is collapsed.
Click to expand it.
tests/test_action_plan.py
+
2
−
1
View file @
772a9826
from
flatland.action_plan.action_plan
import
TrainrunWaypoint
,
ControllerFromTrainrunsReplayer
,
ActionPlanElement
,
\
from
flatland.action_plan.action_plan
import
TrainrunWaypoint
,
ActionPlanElement
,
\
ControllerFromTrainruns
from
flatland.action_plan.action_plan_player
import
ControllerFromTrainrunsReplayer
from
flatland.core.grid.grid4
import
Grid4TransitionsEnum
from
flatland.envs.observations
import
GlobalObsForRailEnv
from
flatland.envs.rail_env
import
RailEnv
,
RailEnvActions
...
...
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