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
pranjal_dhole
Flatland
Commits
f0149144
Commit
f0149144
authored
5 years ago
by
u214892
Browse files
Options
Downloads
Patches
Plain Diff
SIM-119 refactoring review from Erik
parent
efb97f66
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/action_plan/action_plan.py
+12
-11
12 additions, 11 deletions
flatland/action_plan/action_plan.py
tests/test_action_plan.py
+5
-5
5 additions, 5 deletions
tests/test_action_plan.py
with
17 additions
and
16 deletions
flatland/action_plan/action_plan.py
+
12
−
11
View file @
f0149144
...
...
@@ -22,7 +22,8 @@ ActionPlan = List[ActionPlanElement]
ActionPlanDict
=
Dict
[
int
,
ActionPlan
]
class
DeterministicController
():
class
ControllerFromTrainRuns
():
"""
Takes train runs, derives the actions from it and re-acts them.
"""
pp
=
pprint
.
PrettyPrinter
(
indent
=
4
)
def
__init__
(
self
,
...
...
@@ -36,7 +37,7 @@ class DeterministicController():
def
get_way_point_before_or_at_step
(
self
,
agent_id
:
int
,
step
:
int
)
->
WayPoint
:
"""
Get the wa
lking eleme
nt from which the current position can be extracted.
Get the wa
y point poi
nt from which the current position can be extracted.
Parameters
----------
...
...
@@ -126,23 +127,23 @@ class DeterministicController():
"
len for agent {} should be the same.
\n\n
expected ({}) = {}
\n\n
actual ({}) = {}
"
.
format
(
k
,
len
(
expected_action_plan
[
k
]),
DeterministicController
.
pp
.
pformat
(
expected_action_plan
[
k
]),
ControllerFromTrainRuns
.
pp
.
pformat
(
expected_action_plan
[
k
]),
len
(
actual_action_plan
[
k
]),
DeterministicController
.
pp
.
pformat
(
actual_action_plan
[
k
]))
ControllerFromTrainRuns
.
pp
.
pformat
(
actual_action_plan
[
k
]))
for
i
in
range
(
len
(
expected_action_plan
[
k
])):
assert
expected_action_plan
[
k
][
i
]
==
actual_action_plan
[
k
][
i
],
\
"
not the same at agent {} at step {}
\n\n
expected = {}
\n\n
actual = {}
"
.
format
(
k
,
i
,
DeterministicController
.
pp
.
pformat
(
expected_action_plan
[
k
][
i
]),
DeterministicController
.
pp
.
pformat
(
actual_action_plan
[
k
][
i
]))
ControllerFromTrainRuns
.
pp
.
pformat
(
expected_action_plan
[
k
][
i
]),
ControllerFromTrainRuns
.
pp
.
pformat
(
actual_action_plan
[
k
][
i
]))
assert
expected_action_plan
==
actual_action_plan
,
\
"
expected {}, found {}
"
.
format
(
expected_action_plan
,
actual_action_plan
)
def
_create_action_plan_for_agent
(
self
,
agent_id
,
agent_path_new
)
->
ActionPlan
:
def
_create_action_plan_for_agent
(
self
,
agent_id
,
train_run
)
->
ActionPlan
:
action_plan
=
[]
agent
=
self
.
env
.
agents
[
agent_id
]
minimum_cell_time
=
int
(
np
.
ceil
(
1.0
/
agent
.
speed_data
[
'
speed
'
]))
for
path_loop
,
train_run_way_point
in
enumerate
(
agent_path_new
):
for
path_loop
,
train_run_way_point
in
enumerate
(
train_run
):
train_run_way_point
:
TrainRunWayPoint
=
train_run_way_point
position
=
train_run_way_point
.
way_point
.
position
...
...
@@ -150,7 +151,7 @@ class DeterministicController():
if
Vec2d
.
is_equal
(
agent
.
target
,
position
):
break
next_train_run_way_point
:
TrainRunWayPoint
=
agent_path_new
[
path_loop
+
1
]
next_train_run_way_point
:
TrainRunWayPoint
=
train_run
[
path_loop
+
1
]
next_position
=
next_train_run_way_point
.
way_point
.
position
if
path_loop
==
0
:
...
...
@@ -247,11 +248,11 @@ class DeterministicController():
action_plan
.
append
(
action
)
class
DeterministicController
Replayer
():
class
ControllerFromTrainRuns
Replayer
():
"""
Allows to verify a `DeterministicController` by replaying it against a FLATland env without malfunction.
"""
@staticmethod
def
replay_verify
(
max_episode_steps
:
int
,
ctl
:
DeterministicController
,
env
:
RailEnv
,
rendering
:
bool
):
def
replay_verify
(
max_episode_steps
:
int
,
ctl
:
ControllerFromTrainRuns
,
env
:
RailEnv
,
rendering
:
bool
):
"""
Replays this deterministic `ActionPlan` and verifies whether it is feasible.
"""
if
rendering
:
renderer
=
RenderTool
(
env
,
gl
=
"
PILSVG
"
,
...
...
This diff is collapsed.
Click to expand it.
tests/test_action_plan.py
+
5
−
5
View file @
f0149144
from
flatland.action_plan.action_plan
import
TrainRunWayPoint
,
DeterministicController
Replayer
,
ActionPlanElement
,
\
DeterministicController
from
flatland.action_plan.action_plan
import
TrainRunWayPoint
,
ControllerFromTrainRuns
Replayer
,
ActionPlanElement
,
\
ControllerFromTrainRuns
from
flatland.core.grid.grid4
import
Grid4TransitionsEnum
from
flatland.envs.observations
import
GlobalObsForRailEnv
from
flatland.envs.rail_env
import
RailEnv
,
RailEnvActions
...
...
@@ -82,7 +82,7 @@ def test_action_plan(rendering: bool = False):
MAX_EPISODE_STEPS
=
50
deterministic_controller
=
DeterministicController
(
env
,
chosen_path_dict
)
deterministic_controller
=
ControllerFromTrainRuns
(
env
,
chosen_path_dict
)
deterministic_controller
.
print_action_plan
()
DeterministicController
.
assert_actions_plans_equal
(
expected_action_plan
,
deterministic_controller
.
action_plan
)
DeterministicController
Replayer
.
replay_verify
(
MAX_EPISODE_STEPS
,
deterministic_controller
,
env
,
rendering
)
ControllerFromTrainRuns
.
assert_actions_plans_equal
(
expected_action_plan
,
deterministic_controller
.
action_plan
)
ControllerFromTrainRuns
Replayer
.
replay_verify
(
MAX_EPISODE_STEPS
,
deterministic_controller
,
env
,
rendering
)
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