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
594adf63
Commit
594adf63
authored
5 years ago
by
Egli Adrian (IT-SCI-API-PFI)
Browse files
Options
Downloads
Patches
Plain Diff
get shortestpath return type changed
parent
d1971b42
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/envs/rail_env_utils.py
+5
-2
5 additions, 2 deletions
flatland/envs/rail_env_utils.py
tests/test_flatland_envs_predictions.py
+13
-6
13 additions, 6 deletions
tests/test_flatland_envs_predictions.py
with
18 additions
and
8 deletions
flatland/envs/rail_env_utils.py
+
5
−
2
View file @
594adf63
...
@@ -98,7 +98,6 @@ def get_shortest_paths(distance_map: DistanceMap) -> Dict[int, List[ShortestPath
...
@@ -98,7 +98,6 @@ def get_shortest_paths(distance_map: DistanceMap) -> Dict[int, List[ShortestPath
distance
=
math
.
inf
distance
=
math
.
inf
while
(
position
!=
a
.
target
):
while
(
position
!=
a
.
target
):
next_actions
=
get_valid_move_actions_
(
direction
,
position
,
distance_map
.
rail
)
next_actions
=
get_valid_move_actions_
(
direction
,
position
,
distance_map
.
rail
)
best_next_action
=
None
best_next_action
=
None
for
next_action
in
next_actions
:
for
next_action
in
next_actions
:
next_action_distance
=
distance_map
.
get
()[
next_action_distance
=
distance_map
.
get
()[
...
@@ -111,5 +110,9 @@ def get_shortest_paths(distance_map: DistanceMap) -> Dict[int, List[ShortestPath
...
@@ -111,5 +110,9 @@ def get_shortest_paths(distance_map: DistanceMap) -> Dict[int, List[ShortestPath
position
=
best_next_action
.
next_position
position
=
best_next_action
.
next_position
direction
=
best_next_action
.
next_direction
direction
=
best_next_action
.
next_direction
if
position
==
a
.
target
:
shortest_paths
[
a
.
handle
].
append
(
ShortestPathElement
(
position
,
direction
,
RailEnvNextAction
(
RailEnvActions
.
DO_NOTHING
,
position
,
direction
)))
return
shortest_paths
return
shortest_paths
This diff is collapsed.
Click to expand it.
tests/test_flatland_envs_predictions.py
+
13
−
6
View file @
594adf63
...
@@ -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
from
flatland.envs.rail_env_utils
import
get_shortest_paths
,
ShortestPathElement
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,11 +145,18 @@ def test_shortest_path_predictor(rendering=False):
...
@@ -145,11 +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
==
[
RailEnvNextAction
(
action
=
RailEnvActions
.
MOVE_FORWARD
,
next_position
=
(
4
,
6
),
next_direction
=
0
),
ShortestPathElement
((
5
,
6
),
0
,
RailEnvNextAction
(
action
=
RailEnvActions
.
MOVE_FORWARD
,
next_position
=
(
4
,
6
),
RailEnvNextAction
(
action
=
RailEnvActions
.
MOVE_FORWARD
,
next_position
=
(
3
,
6
),
next_direction
=
0
),
next_direction
=
0
)),
RailEnvNextAction
(
action
=
RailEnvActions
.
MOVE_FORWARD
,
next_position
=
(
3
,
7
),
next_direction
=
1
),
ShortestPathElement
((
4
,
6
),
0
,
RailEnvNextAction
(
action
=
RailEnvActions
.
MOVE_FORWARD
,
next_position
=
(
3
,
6
),
RailEnvNextAction
(
action
=
RailEnvActions
.
MOVE_FORWARD
,
next_position
=
(
3
,
8
),
next_direction
=
1
),
next_direction
=
0
)),
RailEnvNextAction
(
action
=
RailEnvActions
.
MOVE_FORWARD
,
next_position
=
(
3
,
9
),
next_direction
=
1
)]
ShortestPathElement
((
3
,
6
),
0
,
RailEnvNextAction
(
action
=
RailEnvActions
.
MOVE_FORWARD
,
next_position
=
(
3
,
7
),
next_direction
=
1
)),
ShortestPathElement
((
3
,
7
),
1
,
RailEnvNextAction
(
action
=
RailEnvActions
.
MOVE_FORWARD
,
next_position
=
(
3
,
8
),
next_direction
=
1
)),
ShortestPathElement
((
3
,
8
),
1
,
RailEnvNextAction
(
action
=
RailEnvActions
.
MOVE_FORWARD
,
next_position
=
(
3
,
9
),
next_direction
=
1
)),
ShortestPathElement
((
3
,
9
),
1
,
RailEnvNextAction
(
action
=
RailEnvActions
.
DO_NOTHING
,
next_position
=
(
3
,
9
),
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