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
d1971b42
Commit
d1971b42
authored
5 years ago
by
Egli Adrian (IT-SCI-API-PFI)
Browse files
Options
Downloads
Patches
Plain Diff
get shortestpath return type changed
parent
d56a44fe
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
flatland/envs/rail_env_utils.py
+11
-4
11 additions, 4 deletions
flatland/envs/rail_env_utils.py
with
11 additions
and
4 deletions
flatland/envs/rail_env_utils.py
+
11
−
4
View file @
d1971b42
import
math
from
typing
import
Tuple
,
Set
,
Dict
,
List
from
typing
import
Tuple
,
Set
,
Dict
,
List
,
NamedTuple
import
numpy
as
np
...
...
@@ -14,6 +14,10 @@ from flatland.envs.rail_generators import rail_from_file
from
flatland.envs.schedule_generators
import
schedule_from_file
from
flatland.utils.ordered_set
import
OrderedSet
ShortestPathElement
=
\
NamedTuple
(
'
Path_Element
'
,
[(
'
position
'
,
Tuple
[
int
,
int
]),
(
'
direction
'
,
int
),
(
'
next_action_element
'
,
RailEnvNextAction
)])
def
load_flatland_environment_from_file
(
file_name
,
load_from_package
=
None
,
obs_builder_object
=
None
):
if
obs_builder_object
is
None
:
...
...
@@ -83,7 +87,7 @@ def get_valid_move_actions_(agent_direction: Grid4TransitionsEnum,
return
valid_actions
def
get_shortest_paths
(
distance_map
:
DistanceMap
)
->
Dict
[
int
,
List
[
RailEnvNextAction
]]:
def
get_shortest_paths
(
distance_map
:
DistanceMap
)
->
Dict
[
int
,
List
[
ShortestPathElement
]]:
# TODO: do we need to support unreachable targets?
# TODO refactoring: unify with predictor (support agent.moving and max_depth)
shortest_paths
=
dict
()
...
...
@@ -97,12 +101,15 @@ def get_shortest_paths(distance_map: DistanceMap) -> Dict[int, List[RailEnvNextA
best_next_action
=
None
for
next_action
in
next_actions
:
next_action_distance
=
distance_map
.
get
()[
a
.
handle
,
next_action
.
next_position
[
0
],
next_action
.
next_position
[
1
],
next_action
.
next_direction
]
next_action_distance
=
distance_map
.
get
()[
a
.
handle
,
next_action
.
next_position
[
0
],
next_action
.
next_position
[
1
],
next_action
.
next_direction
]
if
next_action_distance
<
distance
:
best_next_action
=
next_action
distance
=
next_action_distance
shortest_paths
[
a
.
handle
].
append
(
ShortestPathElement
(
position
,
direction
,
best_next_action
))
position
=
best_next_action
.
next_position
direction
=
best_next_action
.
next_direction
shortest_paths
[
a
.
handle
].
append
(
best_next_action
)
return
shortest_paths
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