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
1bba6852
Commit
1bba6852
authored
5 years ago
by
Egli Adrian (IT-SCI-API-PFI)
Browse files
Options
Downloads
Patches
Plain Diff
renamed ShortestPathElement -> WalkingElement (naming fits better)
parent
cf66525c
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/envs/rail_env_utils.py
+5
-5
5 additions, 5 deletions
flatland/envs/rail_env_utils.py
tests/test_flatland_envs_predictions.py
+13
-13
13 additions, 13 deletions
tests/test_flatland_envs_predictions.py
with
18 additions
and
18 deletions
flatland/envs/rail_env_utils.py
+
5
−
5
View file @
1bba6852
...
@@ -14,7 +14,7 @@ from flatland.envs.rail_generators import rail_from_file
...
@@ -14,7 +14,7 @@ from flatland.envs.rail_generators import rail_from_file
from
flatland.envs.schedule_generators
import
schedule_from_file
from
flatland.envs.schedule_generators
import
schedule_from_file
from
flatland.utils.ordered_set
import
OrderedSet
from
flatland.utils.ordered_set
import
OrderedSet
ShortestPath
Element
=
\
Walking
Element
=
\
NamedTuple
(
'
Path_Element
'
,
NamedTuple
(
'
Path_Element
'
,
[(
'
position
'
,
Tuple
[
int
,
int
]),
(
'
direction
'
,
int
),
(
'
next_action_element
'
,
RailEnvNextAction
)])
[(
'
position
'
,
Tuple
[
int
,
int
]),
(
'
direction
'
,
int
),
(
'
next_action_element
'
,
RailEnvNextAction
)])
...
@@ -87,7 +87,7 @@ def get_valid_move_actions_(agent_direction: Grid4TransitionsEnum,
...
@@ -87,7 +87,7 @@ def get_valid_move_actions_(agent_direction: Grid4TransitionsEnum,
return
valid_actions
return
valid_actions
def
get_shortest_paths
(
distance_map
:
DistanceMap
)
->
Dict
[
int
,
List
[
ShortestPath
Element
]]:
def
get_shortest_paths
(
distance_map
:
DistanceMap
)
->
Dict
[
int
,
List
[
Walking
Element
]]:
# TODO: do we need to support unreachable targets?
# TODO: do we need to support unreachable targets?
# TODO refactoring: unify with predictor (support agent.moving and max_depth)
# TODO refactoring: unify with predictor (support agent.moving and max_depth)
shortest_paths
=
dict
()
shortest_paths
=
dict
()
...
@@ -106,13 +106,13 @@ def get_shortest_paths(distance_map: DistanceMap) -> Dict[int, List[ShortestPath
...
@@ -106,13 +106,13 @@ def get_shortest_paths(distance_map: DistanceMap) -> Dict[int, List[ShortestPath
best_next_action
=
next_action
best_next_action
=
next_action
distance
=
next_action_distance
distance
=
next_action_distance
shortest_paths
[
a
.
handle
].
append
(
ShortestPath
Element
(
position
,
direction
,
best_next_action
))
shortest_paths
[
a
.
handle
].
append
(
Walking
Element
(
position
,
direction
,
best_next_action
))
position
=
best_next_action
.
next_position
position
=
best_next_action
.
next_position
direction
=
best_next_action
.
next_direction
direction
=
best_next_action
.
next_direction
shortest_paths
[
a
.
handle
].
append
(
shortest_paths
[
a
.
handle
].
append
(
ShortestPath
Element
(
position
,
direction
,
Walking
Element
(
position
,
direction
,
RailEnvNextAction
(
RailEnvActions
.
STOP_MOVING
,
position
,
direction
)))
RailEnvNextAction
(
RailEnvActions
.
STOP_MOVING
,
position
,
direction
)))
return
shortest_paths
return
shortest_paths
This diff is collapsed.
Click to expand it.
tests/test_flatland_envs_predictions.py
+
13
−
13
View file @
1bba6852
...
@@ -8,7 +8,7 @@ from flatland.core.grid.grid4 import Grid4TransitionsEnum
...
@@ -8,7 +8,7 @@ from flatland.core.grid.grid4 import Grid4TransitionsEnum
from
flatland.envs.observations
import
TreeObsForRailEnv
from
flatland.envs.observations
import
TreeObsForRailEnv
from
flatland.envs.predictions
import
DummyPredictorForRailEnv
,
ShortestPathPredictorForRailEnv
from
flatland.envs.predictions
import
DummyPredictorForRailEnv
,
ShortestPathPredictorForRailEnv
from
flatland.envs.rail_env
import
RailEnv
,
RailEnvActions
,
RailEnvNextAction
from
flatland.envs.rail_env
import
RailEnv
,
RailEnvActions
,
RailEnvNextAction
from
flatland.envs.rail_env_utils
import
get_shortest_paths
,
ShortestPath
Element
from
flatland.envs.rail_env_utils
import
get_shortest_paths
,
Walking
Element
from
flatland.envs.rail_generators
import
rail_from_grid_transition_map
from
flatland.envs.rail_generators
import
rail_from_grid_transition_map
from
flatland.envs.schedule_generators
import
random_schedule_generator
from
flatland.envs.schedule_generators
import
random_schedule_generator
from
flatland.utils.rendertools
import
RenderTool
from
flatland.utils.rendertools
import
RenderTool
...
@@ -145,18 +145,18 @@ def test_shortest_path_predictor(rendering=False):
...
@@ -145,18 +145,18 @@ def test_shortest_path_predictor(rendering=False):
paths
=
get_shortest_paths
(
env
.
distance_map
)[
0
]
paths
=
get_shortest_paths
(
env
.
distance_map
)[
0
]
assert
paths
==
[
assert
paths
==
[
ShortestPath
Element
((
5
,
6
),
0
,
RailEnvNextAction
(
action
=
RailEnvActions
.
MOVE_FORWARD
,
next_position
=
(
4
,
6
),
Walking
Element
((
5
,
6
),
0
,
RailEnvNextAction
(
action
=
RailEnvActions
.
MOVE_FORWARD
,
next_position
=
(
4
,
6
),
next_direction
=
0
)),
next_direction
=
0
)),
ShortestPath
Element
((
4
,
6
),
0
,
RailEnvNextAction
(
action
=
RailEnvActions
.
MOVE_FORWARD
,
next_position
=
(
3
,
6
),
Walking
Element
((
4
,
6
),
0
,
RailEnvNextAction
(
action
=
RailEnvActions
.
MOVE_FORWARD
,
next_position
=
(
3
,
6
),
next_direction
=
0
)),
next_direction
=
0
)),
ShortestPath
Element
((
3
,
6
),
0
,
RailEnvNextAction
(
action
=
RailEnvActions
.
MOVE_FORWARD
,
next_position
=
(
3
,
7
),
Walking
Element
((
3
,
6
),
0
,
RailEnvNextAction
(
action
=
RailEnvActions
.
MOVE_FORWARD
,
next_position
=
(
3
,
7
),
next_direction
=
1
)),
next_direction
=
1
)),
ShortestPath
Element
((
3
,
7
),
1
,
RailEnvNextAction
(
action
=
RailEnvActions
.
MOVE_FORWARD
,
next_position
=
(
3
,
8
),
Walking
Element
((
3
,
7
),
1
,
RailEnvNextAction
(
action
=
RailEnvActions
.
MOVE_FORWARD
,
next_position
=
(
3
,
8
),
next_direction
=
1
)),
next_direction
=
1
)),
ShortestPath
Element
((
3
,
8
),
1
,
RailEnvNextAction
(
action
=
RailEnvActions
.
MOVE_FORWARD
,
next_position
=
(
3
,
9
),
Walking
Element
((
3
,
8
),
1
,
RailEnvNextAction
(
action
=
RailEnvActions
.
MOVE_FORWARD
,
next_position
=
(
3
,
9
),
next_direction
=
1
)),
next_direction
=
1
)),
ShortestPath
Element
((
3
,
9
),
1
,
RailEnvNextAction
(
action
=
RailEnvActions
.
STOP_MOVING
,
next_position
=
(
3
,
9
),
Walking
Element
((
3
,
9
),
1
,
RailEnvNextAction
(
action
=
RailEnvActions
.
STOP_MOVING
,
next_position
=
(
3
,
9
),
next_direction
=
1
))]
next_direction
=
1
))]
# extract the data
# extract the data
predictions
=
env
.
obs_builder
.
predictions
predictions
=
env
.
obs_builder
.
predictions
...
...
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