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
b935770a
Commit
b935770a
authored
5 years ago
by
Erik Nygren
Browse files
Options
Downloads
Plain Diff
Merge branch 'master' into '140_predictor_multi_speed'
# Conflicts: # examples/training_example.py
parents
30b4ca61
8775f09c
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
examples/training_example.py
+7
-4
7 additions, 4 deletions
examples/training_example.py
flatland/envs/observations.py
+11
-7
11 additions, 7 deletions
flatland/envs/observations.py
with
18 additions
and
11 deletions
examples/training_example.py
+
7
−
4
View file @
b935770a
...
...
@@ -13,11 +13,11 @@ np.random.seed(1)
TreeObservation
=
TreeObsForRailEnv
(
max_depth
=
2
,
predictor
=
ShortestPathPredictorForRailEnv
())
LocalGridObs
=
LocalObsForRailEnv
(
view_height
=
10
,
view_width
=
2
,
center
=
2
)
env
=
RailEnv
(
width
=
5
0
,
height
=
5
0
,
env
=
RailEnv
(
width
=
2
0
,
height
=
2
0
,
rail_generator
=
complex_rail_generator
(
nr_start_goal
=
10
,
nr_extra
=
1
,
min_dist
=
8
,
max_dist
=
99999
,
seed
=
0
),
obs_builder_object
=
TreeObservation
,
number_of_agents
=
5
)
number_of_agents
=
3
)
env_renderer
=
RenderTool
(
env
,
gl
=
"
PILSVG
"
,
)
...
...
@@ -68,6 +68,9 @@ for trials in range(1, n_trials + 1):
# Reset environment and get initial observations for all agents
obs
=
env
.
reset
()
for
idx
in
range
(
env
.
get_num_agents
()):
tmp_agent
=
env
.
agents
[
idx
]
tmp_agent
.
speed_data
[
"
speed
"
]
=
1
/
(
idx
+
1
)
env_renderer
.
reset
()
# Here you can also further enhance the provided observation by means of normalization
# See training navigation example in the baseline repository
...
...
@@ -83,7 +86,7 @@ for trials in range(1, n_trials + 1):
# Environment step which returns the observations for all agents, their corresponding
# reward and whether their are done
next_obs
,
all_rewards
,
done
,
_
=
env
.
step
(
action_dict
)
env_renderer
.
render_env
(
show
=
True
,
show_observations
=
Fals
e
,
show_predictions
=
Tru
e
)
env_renderer
.
render_env
(
show
=
True
,
show_observations
=
Tru
e
,
show_predictions
=
Fals
e
)
# Update replay buffer and train agent
for
a
in
range
(
env
.
get_num_agents
()):
...
...
This diff is collapsed.
Click to expand it.
flatland/envs/observations.py
+
11
−
7
View file @
b935770a
...
...
@@ -324,6 +324,7 @@ class TreeObsForRailEnv(ObservationBuilder):
visited
=
set
()
agent
=
self
.
env
.
agents
[
handle
]
time_per_cell
=
np
.
reciprocal
(
agent
.
speed_data
[
"
speed
"
])
own_target_encountered
=
np
.
inf
other_agent_encountered
=
np
.
inf
other_target_encountered
=
np
.
inf
...
...
@@ -359,18 +360,21 @@ class TreeObsForRailEnv(ObservationBuilder):
crossing_found
=
True
# Register possible future conflict
if
self
.
predictor
and
num_steps
<
self
.
max_prediction_depth
:
predicted_time
=
int
(
tot_dist
*
time_per_cell
)
if
self
.
predictor
and
predicted_time
<
self
.
max_prediction_depth
:
int_position
=
coordinate_to_position
(
self
.
env
.
width
,
[
position
])
if
tot_dist
<
self
.
max_prediction_depth
:
pre_step
=
max
(
0
,
tot_dist
-
1
)
post_step
=
min
(
self
.
max_prediction_depth
-
1
,
tot_dist
+
1
)
pre_step
=
max
(
0
,
predicted_time
-
1
)
post_step
=
min
(
self
.
max_prediction_depth
-
1
,
predicted_time
+
1
)
# Look for conflicting paths at distance tot_dist
if
int_position
in
np
.
delete
(
self
.
predicted_pos
[
tot_dist
],
handle
,
0
):
conflicting_agent
=
np
.
where
(
self
.
predicted_pos
[
tot_dist
]
==
int_position
)
if
int_position
in
np
.
delete
(
self
.
predicted_pos
[
predicted_time
],
handle
,
0
):
conflicting_agent
=
np
.
where
(
self
.
predicted_pos
[
predicted_time
]
==
int_position
)
for
ca
in
conflicting_agent
[
0
]:
if
direction
!=
self
.
predicted_dir
[
tot_dist
][
ca
]
and
cell_transitions
[
self
.
_reverse_dir
(
self
.
predicted_dir
[
tot_dist
][
ca
])]
==
1
and
tot_dist
<
potential_conflict
:
if
direction
!=
self
.
predicted_dir
[
predicted_time
][
ca
]
and
cell_transitions
[
self
.
_reverse_dir
(
self
.
predicted_dir
[
predicted_time
][
ca
])]
==
1
and
tot_dist
<
potential_conflict
:
potential_conflict
=
tot_dist
if
self
.
env
.
dones
[
ca
]
and
tot_dist
<
potential_conflict
:
potential_conflict
=
tot_dist
...
...
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