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
sfwatergit
Flatland
Commits
ff2ea11d
Commit
ff2ea11d
authored
5 years ago
by
Erik Nygren
Browse files
Options
Downloads
Patches
Plain Diff
updated how distance from agent is measured to detect conflicts!
parent
920032da
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/observations.py
+30
-25
30 additions, 25 deletions
flatland/envs/observations.py
with
30 additions
and
25 deletions
flatland/envs/observations.py
+
30
−
25
View file @
ff2ea11d
...
@@ -273,7 +273,7 @@ class TreeObsForRailEnv(ObservationBuilder):
...
@@ -273,7 +273,7 @@ class TreeObsForRailEnv(ObservationBuilder):
if
possible_transitions
[
branch_direction
]:
if
possible_transitions
[
branch_direction
]:
new_cell
=
self
.
_new_position
(
agent
.
position
,
branch_direction
)
new_cell
=
self
.
_new_position
(
agent
.
position
,
branch_direction
)
branch_observation
,
branch_visited
=
\
branch_observation
,
branch_visited
=
\
self
.
_explore_branch
(
handle
,
new_cell
,
branch_direction
,
root_observation
,
1
)
self
.
_explore_branch
(
handle
,
new_cell
,
branch_direction
,
root_observation
,
0
,
1
)
observation
=
observation
+
branch_observation
observation
=
observation
+
branch_observation
visited
=
visited
.
union
(
branch_visited
)
visited
=
visited
.
union
(
branch_visited
)
else
:
else
:
...
@@ -286,7 +286,7 @@ class TreeObsForRailEnv(ObservationBuilder):
...
@@ -286,7 +286,7 @@ class TreeObsForRailEnv(ObservationBuilder):
self
.
env
.
dev_obs_dict
[
handle
]
=
visited
self
.
env
.
dev_obs_dict
[
handle
]
=
visited
return
observation
return
observation
def
_explore_branch
(
self
,
handle
,
position
,
direction
,
root_observation
,
depth
):
def
_explore_branch
(
self
,
handle
,
position
,
direction
,
root_observation
,
tot_dist
,
depth
):
"""
"""
Utility function to compute tree-based observations.
Utility function to compute tree-based observations.
"""
"""
...
@@ -332,26 +332,31 @@ class TreeObsForRailEnv(ObservationBuilder):
...
@@ -332,26 +332,31 @@ class TreeObsForRailEnv(ObservationBuilder):
# Register possible conflict
# Register possible conflict
if
self
.
predictor
and
num_steps
<
self
.
max_prediction_depth
:
if
self
.
predictor
and
num_steps
<
self
.
max_prediction_depth
:
int_position
=
coordinate_to_position
(
self
.
env
.
width
,
[
position
])
int_position
=
coordinate_to_position
(
self
.
env
.
width
,
[
position
])
pre_step
=
max
(
0
,
num_steps
-
1
)
if
tot_dist
<
self
.
max_prediction_depth
:
post_step
=
min
(
self
.
max_prediction_depth
-
1
,
num_steps
+
1
)
pre_step
=
max
(
0
,
tot_dist
-
1
)
# Look for opposing paths at distance num_step
post_step
=
min
(
self
.
max_prediction_depth
-
1
,
tot_dist
+
1
)
if
int_position
in
np
.
delete
(
self
.
predicted_pos
[
num_steps
],
handle
):
conflicting_agent
=
np
.
where
(
np
.
delete
(
self
.
predicted_pos
[
num_steps
],
handle
)
==
int_position
)
# Look for opposing paths at distance num_step
for
ca
in
conflicting_agent
:
if
int_position
in
np
.
delete
(
self
.
predicted_pos
[
tot_dist
],
handle
):
if
direction
!=
self
.
predicted_dir
[
num_steps
][
ca
[
0
]]:
conflicting_agent
=
np
.
where
(
np
.
delete
(
self
.
predicted_pos
[
tot_dist
],
handle
)
==
int_position
)
potential_conflict
=
1
for
ca
in
conflicting_agent
:
# Look for opposing paths at distance num_step-1
if
direction
!=
self
.
predicted_dir
[
tot_dist
][
ca
[
0
]]:
elif
int_position
in
np
.
delete
(
self
.
predicted_pos
[
pre_step
],
handle
):
potential_conflict
=
1
conflicting_agent
=
np
.
where
(
self
.
predicted_pos
[
pre_step
]
==
int_position
)
# print("Potential Conflict",position,handle,ca[0],tot_dist,depth)
for
ca
in
conflicting_agent
:
# Look for opposing paths at distance num_step-1
if
direction
!=
self
.
predicted_dir
[
pre_step
][
ca
[
0
]]:
elif
int_position
in
np
.
delete
(
self
.
predicted_pos
[
pre_step
],
handle
):
potential_conflict
=
1
conflicting_agent
=
np
.
where
(
self
.
predicted_pos
[
pre_step
]
==
int_position
)
# Look for opposing paths at distance num_step+1
for
ca
in
conflicting_agent
:
elif
int_position
in
np
.
delete
(
self
.
predicted_pos
[
post_step
],
handle
):
if
direction
!=
self
.
predicted_dir
[
pre_step
][
ca
[
0
]]:
conflicting_agent
=
np
.
where
(
np
.
delete
(
self
.
predicted_pos
[
post_step
],
handle
)
==
int_position
)
potential_conflict
=
1
for
ca
in
conflicting_agent
:
# print("Potential Conflict", position,handle,ca[0],pre_step,depth)
if
direction
!=
self
.
predicted_dir
[
post_step
][
ca
[
0
]]:
# Look for opposing paths at distance num_step+1
potential_conflict
=
1
elif
int_position
in
np
.
delete
(
self
.
predicted_pos
[
post_step
],
handle
):
conflicting_agent
=
np
.
where
(
np
.
delete
(
self
.
predicted_pos
[
post_step
],
handle
)
==
int_position
)
for
ca
in
conflicting_agent
:
if
direction
!=
self
.
predicted_dir
[
post_step
][
ca
[
0
]]:
potential_conflict
=
1
# print("Potential Conflict", position,handle,ca[0],post_step,depth)
if
position
in
self
.
location_has_target
and
position
!=
agent
.
target
:
if
position
in
self
.
location_has_target
and
position
!=
agent
.
target
:
if
num_steps
<
other_target_encountered
:
if
num_steps
<
other_target_encountered
:
...
@@ -395,7 +400,7 @@ class TreeObsForRailEnv(ObservationBuilder):
...
@@ -395,7 +400,7 @@ class TreeObsForRailEnv(ObservationBuilder):
direction
=
np
.
argmax
(
cell_transitions
)
direction
=
np
.
argmax
(
cell_transitions
)
position
=
self
.
_new_position
(
position
,
direction
)
position
=
self
.
_new_position
(
position
,
direction
)
num_steps
+=
1
num_steps
+=
1
tot_dist
+=
1
elif
num_transitions
>
0
:
elif
num_transitions
>
0
:
# Switch detected
# Switch detected
last_isSwitch
=
True
last_isSwitch
=
True
...
@@ -499,7 +504,7 @@ class TreeObsForRailEnv(ObservationBuilder):
...
@@ -499,7 +504,7 @@ class TreeObsForRailEnv(ObservationBuilder):
branch_observation
,
branch_visited
=
self
.
_explore_branch
(
handle
,
branch_observation
,
branch_visited
=
self
.
_explore_branch
(
handle
,
new_cell
,
new_cell
,
(
branch_direction
+
2
)
%
4
,
(
branch_direction
+
2
)
%
4
,
new_root_observation
,
new_root_observation
,
tot_dist
+
1
,
depth
+
1
)
depth
+
1
)
observation
=
observation
+
branch_observation
observation
=
observation
+
branch_observation
if
len
(
branch_visited
)
!=
0
:
if
len
(
branch_visited
)
!=
0
:
...
@@ -509,7 +514,7 @@ class TreeObsForRailEnv(ObservationBuilder):
...
@@ -509,7 +514,7 @@ class TreeObsForRailEnv(ObservationBuilder):
branch_observation
,
branch_visited
=
self
.
_explore_branch
(
handle
,
branch_observation
,
branch_visited
=
self
.
_explore_branch
(
handle
,
new_cell
,
new_cell
,
branch_direction
,
branch_direction
,
new_root_observation
,
new_root_observation
,
tot_dist
+
1
,
depth
+
1
)
depth
+
1
)
observation
=
observation
+
branch_observation
observation
=
observation
+
branch_observation
if
len
(
branch_visited
)
!=
0
:
if
len
(
branch_visited
)
!=
0
:
...
...
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