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
2df4a434
Commit
2df4a434
authored
5 years ago
by
Erik Nygren
Browse files
Options
Downloads
Patches
Plain Diff
fixed bug in tree observation.
parent
6d7ff5cd
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/flatland_2_0_example.py
+2
-2
2 additions, 2 deletions
examples/flatland_2_0_example.py
flatland/envs/observations.py
+4
-7
4 additions, 7 deletions
flatland/envs/observations.py
with
6 additions
and
9 deletions
examples/flatland_2_0_example.py
+
2
−
2
View file @
2df4a434
import
numpy
as
np
from
flatland.envs.observations
import
TreeObsForRailEnv
,
GlobalObsForRailEnv
from
flatland.envs.observations
import
TreeObsForRailEnv
from
flatland.envs.predictions
import
ShortestPathPredictorForRailEnv
from
flatland.envs.rail_env
import
RailEnv
from
flatland.envs.rail_generators
import
sparse_rail_generator
...
...
@@ -39,7 +39,7 @@ env = RailEnv(width=40,
schedule_generator
=
sparse_schedule_generator
(
speed_ration_map
),
number_of_agents
=
20
,
stochastic_data
=
stochastic_data
,
# Malfunction data generator
obs_builder_object
=
GlobalObsForRailEnv
()
,
obs_builder_object
=
TreeObservation
,
remove_agents_at_target
=
True
)
...
...
This diff is collapsed.
Click to expand it.
flatland/envs/observations.py
+
4
−
7
View file @
2df4a434
...
...
@@ -174,7 +174,6 @@ class TreeObsForRailEnv(ObservationBuilder):
else
:
self
.
location_has_agent_direction
[(
agent
.
position
,
agent
.
direction
)]
=
1
self
.
location_has_agent_speed
=
{
tuple
(
agent
.
position
):
agent
.
speed_data
[
'
speed
'
]
for
agent
in
self
.
env
.
agents
}
self
.
location_has_agent_malfunction
=
{
tuple
(
agent
.
position
):
agent
.
malfunction_data
[
'
malfunction
'
]
for
agent
in
self
.
env
.
agents
}
...
...
@@ -271,9 +270,9 @@ class TreeObsForRailEnv(ObservationBuilder):
if
self
.
location_has_agent_malfunction
[
position
]
>
malfunctioning_agent
:
malfunctioning_agent
=
self
.
location_has_agent_malfunction
[
position
]
if
(
agent
.
position
,
agent
.
direction
)
in
self
.
location_has_agent_direction
:
if
(
position
,
direction
)
in
self
.
location_has_agent_direction
:
# Cummulate the number of agents on branch with same direction
other_agent_same_direction
+=
self
.
location_has_agent_direction
[(
agent
.
position
,
agent
.
direction
)]
other_agent_same_direction
+=
self
.
location_has_agent_direction
[(
position
,
direction
)]
# Check fractional speed of agents
current_fractional_speed
=
self
.
location_has_agent_speed
[
position
]
...
...
@@ -284,13 +283,11 @@ class TreeObsForRailEnv(ObservationBuilder):
# TODO: This does not work as expected yet
other_agent_opposite_direction
+=
self
.
location_has_agent
[
position
]
-
\
self
.
location_has_agent_direction
[
(
agent
.
position
,
agent
.
direction
)]
(
position
,
direction
)]
else
:
# If no agent in the same direction was found all agents in that position are other direction
other_agent_opposite_direction
+=
self
.
location_has_agent
[
position
]
print
(
"
went in here
"
)
if
other_agent_opposite_direction
>
0
:
print
(
"
Other agents
"
,
other_agent_opposite_direction
)
# Check number of possible transitions for agent and total number of transitions in cell (type)
cell_transitions
=
self
.
env
.
rail
.
get_transitions
(
*
position
,
direction
)
...
...
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