Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
neurips2020-flatland-starter-kit
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Analyze
Contributor 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
adrian_egli
neurips2020-flatland-starter-kit
Commits
f310811b
Commit
f310811b
authored
4 years ago
by
Egli Adrian (IT-SCI-API-PFI)
Browse files
Options
Downloads
Patches
Plain Diff
ShortestPathWalkerHeuristicPolicy
parent
3b48de68
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
utils/shortest_path_walker_heuristic_agent.py
+57
-0
57 additions, 0 deletions
utils/shortest_path_walker_heuristic_agent.py
with
57 additions
and
0 deletions
utils/shortest_path_walker_heuristic_agent.py
0 → 100644
+
57
−
0
View file @
f310811b
import
numpy
as
np
from
flatland.envs.rail_env
import
RailEnvActions
from
reinforcement_learning.policy
import
Policy
class
ShortestPathWalkerHeuristicPolicy
(
Policy
):
def
step
(
self
,
state
,
action
,
reward
,
next_state
,
done
):
pass
def
act
(
self
,
node
,
eps
=
0.
):
left_node
=
node
.
childs
.
get
(
'
L
'
)
forward_node
=
node
.
childs
.
get
(
'
F
'
)
right_node
=
node
.
childs
.
get
(
'
R
'
)
dist_map
=
np
.
zeros
(
5
)
dist_map
[
RailEnvActions
.
DO_NOTHING
]
=
np
.
inf
dist_map
[
RailEnvActions
.
STOP_MOVING
]
=
100000
# left
if
left_node
==
-
np
.
inf
:
dist_map
[
RailEnvActions
.
MOVE_LEFT
]
=
np
.
inf
else
:
if
left_node
.
num_agents_opposite_direction
==
0
:
dist_map
[
RailEnvActions
.
MOVE_LEFT
]
=
left_node
.
dist_min_to_target
else
:
dist_map
[
RailEnvActions
.
MOVE_LEFT
]
=
np
.
inf
# forward
if
forward_node
==
-
np
.
inf
:
dist_map
[
RailEnvActions
.
MOVE_FORWARD
]
=
np
.
inf
else
:
if
forward_node
.
num_agents_opposite_direction
==
0
:
dist_map
[
RailEnvActions
.
MOVE_FORWARD
]
=
forward_node
.
dist_min_to_target
else
:
dist_map
[
RailEnvActions
.
MOVE_FORWARD
]
=
np
.
inf
# right
if
right_node
==
-
np
.
inf
:
dist_map
[
RailEnvActions
.
MOVE_RIGHT
]
=
np
.
inf
else
:
if
right_node
.
num_agents_opposite_direction
==
0
:
dist_map
[
RailEnvActions
.
MOVE_RIGHT
]
=
right_node
.
dist_min_to_target
else
:
dist_map
[
RailEnvActions
.
MOVE_RIGHT
]
=
np
.
inf
return
np
.
argmin
(
dist_map
)
def
save
(
self
,
filename
):
pass
def
load
(
self
,
filename
):
pass
policy
=
ShortestPathWalkerHeuristicPolicy
()
def
normalize_observation
(
observation
,
tree_depth
:
int
,
observation_radius
=
0
):
return
observation
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