Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
marl-flatland
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
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
manavsinghal157
marl-flatland
Commits
2ebc782d
Commit
2ebc782d
authored
4 years ago
by
Egli Adrian (IT-SCI-API-PFI)
Browse files
Options
Downloads
Patches
Plain Diff
DeadLockAvoidanceAgent -> observation
parent
78d1c9ff
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
reinforcement_learning/dddqn_policy.py
+1
-3
1 addition, 3 deletions
reinforcement_learning/dddqn_policy.py
run.py
+1
-1
1 addition, 1 deletion
run.py
utils/fast_tree_obs.py
+18
-3
18 additions, 3 deletions
utils/fast_tree_obs.py
with
20 additions
and
7 deletions
reinforcement_learning/dddqn_policy.py
+
1
−
3
View file @
2ebc782d
...
@@ -124,9 +124,7 @@ class DDDQNPolicy(Policy):
...
@@ -124,9 +124,7 @@ class DDDQNPolicy(Policy):
if
os
.
path
.
exists
(
filename
+
"
.local
"
)
and
os
.
path
.
exists
(
filename
+
"
.target
"
):
if
os
.
path
.
exists
(
filename
+
"
.local
"
)
and
os
.
path
.
exists
(
filename
+
"
.target
"
):
self
.
qnetwork_local
.
load_state_dict
(
torch
.
load
(
filename
+
"
.local
"
))
self
.
qnetwork_local
.
load_state_dict
(
torch
.
load
(
filename
+
"
.local
"
))
print
(
"
qnetwork_local loaded (
'
{}
'
)
"
.
format
(
filename
+
"
.local
"
))
print
(
"
qnetwork_local loaded (
'
{}
'
)
"
.
format
(
filename
+
"
.local
"
))
if
self
.
evaluation_mode
:
if
not
self
.
evaluation_mode
:
self
.
qnetwork_target
=
copy
.
deepcopy
(
self
.
qnetwork_local
)
else
:
self
.
qnetwork_target
.
load_state_dict
(
torch
.
load
(
filename
+
"
.target
"
))
self
.
qnetwork_target
.
load_state_dict
(
torch
.
load
(
filename
+
"
.target
"
))
print
(
"
qnetwork_target loaded (
'
{}
'
)
"
.
format
(
filename
+
"
.target
"
))
print
(
"
qnetwork_target loaded (
'
{}
'
)
"
.
format
(
filename
+
"
.target
"
))
else
:
else
:
...
...
This diff is collapsed.
Click to expand it.
run.py
+
1
−
1
View file @
2ebc782d
...
@@ -25,7 +25,7 @@ from reinforcement_learning.dddqn_policy import DDDQNPolicy
...
@@ -25,7 +25,7 @@ from reinforcement_learning.dddqn_policy import DDDQNPolicy
VERBOSE
=
True
VERBOSE
=
True
# Checkpoint to use (remember to push it!)
# Checkpoint to use (remember to push it!)
checkpoint
=
"
./checkpoints/2011031
60541-
18
0
0.pth
"
checkpoint
=
"
./checkpoints/2011031
721
18
-
0.pth
"
# Use last action cache
# Use last action cache
USE_ACTION_CACHE
=
True
USE_ACTION_CACHE
=
True
...
...
This diff is collapsed.
Click to expand it.
utils/fast_tree_obs.py
+
18
−
3
View file @
2ebc782d
...
@@ -2,8 +2,9 @@ import numpy as np
...
@@ -2,8 +2,9 @@ import numpy as np
from
flatland.core.env_observation_builder
import
ObservationBuilder
from
flatland.core.env_observation_builder
import
ObservationBuilder
from
flatland.core.grid.grid4_utils
import
get_new_position
from
flatland.core.grid.grid4_utils
import
get_new_position
from
flatland.envs.agent_utils
import
RailAgentStatus
from
flatland.envs.agent_utils
import
RailAgentStatus
from
flatland.envs.rail_env
import
fast_count_nonzero
,
fast_argmax
from
flatland.envs.rail_env
import
fast_count_nonzero
,
fast_argmax
,
RailEnvActions
from
utils.dead_lock_avoidance_agent
import
DeadLockAvoidanceAgent
"""
"""
LICENCE for the FastTreeObs Observation Builder
LICENCE for the FastTreeObs Observation Builder
...
@@ -17,11 +18,12 @@ Author: Adrian Egli (adrian.egli@gmail.com)
...
@@ -17,11 +18,12 @@ Author: Adrian Egli (adrian.egli@gmail.com)
[Researchgate](https://www.linkedin.com/in/adrian-egli-733a9544/)
[Researchgate](https://www.linkedin.com/in/adrian-egli-733a9544/)
"""
"""
class
FastTreeObs
(
ObservationBuilder
):
class
FastTreeObs
(
ObservationBuilder
):
def
__init__
(
self
,
max_depth
):
def
__init__
(
self
,
max_depth
):
self
.
max_depth
=
max_depth
self
.
max_depth
=
max_depth
self
.
observation_dim
=
27
self
.
observation_dim
=
30
def
build_data
(
self
):
def
build_data
(
self
):
if
self
.
env
is
not
None
:
if
self
.
env
is
not
None
:
...
@@ -32,6 +34,9 @@ class FastTreeObs(ObservationBuilder):
...
@@ -32,6 +34,9 @@ class FastTreeObs(ObservationBuilder):
self
.
debug_render_path_list
=
[]
self
.
debug_render_path_list
=
[]
if
self
.
env
is
not
None
:
if
self
.
env
is
not
None
:
self
.
find_all_cell_where_agent_can_choose
()
self
.
find_all_cell_where_agent_can_choose
()
self
.
dead_lock_avoidance_agent
=
DeadLockAvoidanceAgent
(
self
.
env
)
else
:
self
.
dead_lock_avoidance_agent
=
None
def
find_all_cell_where_agent_can_choose
(
self
):
def
find_all_cell_where_agent_can_choose
(
self
):
switches
=
{}
switches
=
{}
...
@@ -238,6 +243,10 @@ class FastTreeObs(ObservationBuilder):
...
@@ -238,6 +243,10 @@ class FastTreeObs(ObservationBuilder):
# observation[23] : If there is a switch on the path which agent can not use -> 1
# observation[23] : If there is a switch on the path which agent can not use -> 1
# observation[24] : If there is a switch on the path which agent can not use -> 1
# observation[24] : If there is a switch on the path which agent can not use -> 1
# observation[25] : If there is a switch on the path which agent can not use -> 1
# observation[25] : If there is a switch on the path which agent can not use -> 1
# observation[26] : If there the dead-lock avoidance agent predicts a deadlock -> 1
if
handle
==
0
:
self
.
dead_lock_avoidance_agent
.
start_step
()
observation
=
np
.
zeros
(
self
.
observation_dim
)
observation
=
np
.
zeros
(
self
.
observation_dim
)
visited
=
[]
visited
=
[]
...
@@ -292,6 +301,12 @@ class FastTreeObs(ObservationBuilder):
...
@@ -292,6 +301,12 @@ class FastTreeObs(ObservationBuilder):
observation
[
8
]
=
int
(
agents_near_to_switch
)
observation
[
8
]
=
int
(
agents_near_to_switch
)
observation
[
9
]
=
int
(
agents_near_to_switch_all
)
observation
[
9
]
=
int
(
agents_near_to_switch_all
)
action
=
self
.
dead_lock_avoidance_agent
.
act
([
handle
],
0.0
)
observation
[
26
]
=
int
(
action
==
RailEnvActions
.
STOP_MOVING
)
observation
[
27
]
=
int
(
action
==
RailEnvActions
.
MOVE_LEFT
)
observation
[
28
]
=
int
(
action
==
RailEnvActions
.
MOVE_FORWARD
)
observation
[
29
]
=
int
(
action
==
RailEnvActions
.
MOVE_RIGHT
)
self
.
env
.
dev_obs_dict
.
update
({
handle
:
visited
})
self
.
env
.
dev_obs_dict
.
update
({
handle
:
visited
})
return
observation
return
observation
\ No newline at end of file
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