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
pranjal_dhole
Flatland
Commits
00cf76e3
Commit
00cf76e3
authored
5 years ago
by
Erik Nygren
Browse files
Options
Downloads
Patches
Plain Diff
updated tree obs to not do computations for each agent every time again
parent
9ee8a299
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
+24
-24
24 additions, 24 deletions
flatland/envs/observations.py
with
24 additions
and
24 deletions
flatland/envs/observations.py
+
24
−
24
View file @
00cf76e3
...
@@ -78,6 +78,30 @@ class TreeObsForRailEnv(ObservationBuilder):
...
@@ -78,6 +78,30 @@ class TreeObsForRailEnv(ObservationBuilder):
self
.
predicted_pos
.
update
({
t
:
coordinate_to_position
(
self
.
env
.
width
,
pos_list
)})
self
.
predicted_pos
.
update
({
t
:
coordinate_to_position
(
self
.
env
.
width
,
pos_list
)})
self
.
predicted_dir
.
update
({
t
:
dir_list
})
self
.
predicted_dir
.
update
({
t
:
dir_list
})
self
.
max_prediction_depth
=
len
(
self
.
predicted_pos
)
self
.
max_prediction_depth
=
len
(
self
.
predicted_pos
)
# Update local lookup table for all agents' positions
# ignore other agents not in the grid (only status active and done)
# self.location_has_agent = {tuple(agent.position): 1 for agent in self.env.agents if
# agent.status in [RailAgentStatus.ACTIVE, RailAgentStatus.DONE]}
self
.
location_has_agent
=
{}
self
.
location_has_agent_direction
=
{}
self
.
location_has_agent_speed
=
{}
self
.
location_has_agent_malfunction
=
{}
self
.
location_has_agent_ready_to_depart
=
{}
for
_agent
in
self
.
env
.
agents
:
if
_agent
.
status
in
[
RailAgentStatus
.
ACTIVE
,
RailAgentStatus
.
DONE
]
and
\
_agent
.
position
:
self
.
location_has_agent
[
tuple
(
_agent
.
position
)]
=
1
self
.
location_has_agent_direction
[
tuple
(
_agent
.
position
)]
=
_agent
.
direction
self
.
location_has_agent_speed
[
tuple
(
_agent
.
position
)]
=
_agent
.
speed_data
[
'
speed
'
]
self
.
location_has_agent_malfunction
[
tuple
(
_agent
.
position
)]
=
_agent
.
malfunction_data
[
'
malfunction
'
]
if
_agent
.
status
in
[
RailAgentStatus
.
READY_TO_DEPART
]
and
\
_agent
.
initial_position
:
self
.
location_has_agent_ready_to_depart
[
tuple
(
_agent
.
initial_position
)]
=
\
self
.
location_has_agent_ready_to_depart
.
get
(
tuple
(
_agent
.
initial_position
),
0
)
+
1
observations
=
super
().
get_many
(
handles
)
observations
=
super
().
get_many
(
handles
)
...
@@ -162,30 +186,6 @@ class TreeObsForRailEnv(ObservationBuilder):
...
@@ -162,30 +186,6 @@ class TreeObsForRailEnv(ObservationBuilder):
In case the target node is reached, the values are [0, 0, 0, 0, 0].
In case the target node is reached, the values are [0, 0, 0, 0, 0].
"""
"""
# Update local lookup table for all agents' positions
# ignore other agents not in the grid (only status active and done)
# self.location_has_agent = {tuple(agent.position): 1 for agent in self.env.agents if
# agent.status in [RailAgentStatus.ACTIVE, RailAgentStatus.DONE]}
self
.
location_has_agent
=
{}
self
.
location_has_agent_direction
=
{}
self
.
location_has_agent_speed
=
{}
self
.
location_has_agent_malfunction
=
{}
self
.
location_has_agent_ready_to_depart
=
{}
for
_agent
in
self
.
env
.
agents
:
if
_agent
.
status
in
[
RailAgentStatus
.
ACTIVE
,
RailAgentStatus
.
DONE
]
and
\
_agent
.
position
:
self
.
location_has_agent
[
tuple
(
_agent
.
position
)]
=
1
self
.
location_has_agent_direction
[
tuple
(
_agent
.
position
)]
=
_agent
.
direction
self
.
location_has_agent_speed
[
tuple
(
_agent
.
position
)]
=
_agent
.
speed_data
[
'
speed
'
]
self
.
location_has_agent_malfunction
[
tuple
(
_agent
.
position
)]
=
_agent
.
malfunction_data
[
'
malfunction
'
]
if
_agent
.
status
in
[
RailAgentStatus
.
READY_TO_DEPART
]
and
\
_agent
.
initial_position
:
self
.
location_has_agent_ready_to_depart
[
tuple
(
_agent
.
initial_position
)]
=
\
self
.
location_has_agent_ready_to_depart
.
get
(
tuple
(
_agent
.
initial_position
),
0
)
+
1
if
handle
>
len
(
self
.
env
.
agents
):
if
handle
>
len
(
self
.
env
.
agents
):
print
(
"
ERROR: obs _get - handle
"
,
handle
,
"
len(agents)
"
,
len
(
self
.
env
.
agents
))
print
(
"
ERROR: obs _get - handle
"
,
handle
,
"
len(agents)
"
,
len
(
self
.
env
.
agents
))
agent
=
self
.
env
.
agents
[
handle
]
# TODO: handle being treated as index
agent
=
self
.
env
.
agents
[
handle
]
# TODO: handle being treated as index
...
...
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