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
5d186dc5
Commit
5d186dc5
authored
5 years ago
by
Erik Nygren
Browse files
Options
Downloads
Patches
Plain Diff
still buggy with treeeobservation
parent
7ecdafb9
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
examples/flatland_2_0_example.py
+5
-5
5 additions, 5 deletions
examples/flatland_2_0_example.py
flatland/envs/observations.py
+23
-8
23 additions, 8 deletions
flatland/envs/observations.py
with
28 additions
and
13 deletions
examples/flatland_2_0_example.py
+
5
−
5
View file @
5d186dc5
...
...
@@ -28,13 +28,13 @@ speed_ration_map = {1.: 0.25, # Fast passenger train
1.
/
3.
:
0.25
,
# Slow commuter train
1.
/
4.
:
0.25
}
# Slow freight train
env
=
RailEnv
(
width
=
10
0
,
height
=
2
0
,
rail_generator
=
sparse_rail_generator
(
num_cities
=
2
,
# Number of cities in map (where train stations are)
env
=
RailEnv
(
width
=
4
0
,
height
=
4
0
,
rail_generator
=
sparse_rail_generator
(
num_cities
=
8
,
# Number of cities in map (where train stations are)
seed
=
1
,
# Random seed
grid_mode
=
Tru
e
,
grid_mode
=
Fals
e
,
max_inter_city_rails
=
2
,
max_tracks_in_city
=
8
,
max_tracks_in_city
=
4
,
),
schedule_generator
=
sparse_schedule_generator
(
speed_ration_map
),
number_of_agents
=
20
,
...
...
This diff is collapsed.
Click to expand it.
flatland/envs/observations.py
+
23
−
8
View file @
5d186dc5
...
...
@@ -161,13 +161,20 @@ class TreeObsForRailEnv(ObservationBuilder):
# Update local lookup table for all agents' positions
self
.
location_has_agent
=
dict
()
self
.
location_has_agent_direction
=
dict
()
for
agent
in
self
.
env
.
agents
:
if
tuple
(
agent
.
position
)
in
self
.
location_has_agent
:
self
.
location_has_agent
[
tuple
(
agent
.
position
)]
=
self
.
location_has_agent
[
tuple
(
agent
.
position
)]
+
1
else
:
self
.
location_has_agent
[
tuple
(
agent
.
position
)]
=
1
# TODO: Update this to handle number of agents at same location
self
.
location_has_agent_direction
=
{
tuple
(
agent
.
position
):
agent
.
direction
for
agent
in
self
.
env
.
agents
}
if
(
agent
.
position
,
agent
.
direction
)
in
self
.
location_has_agent_direction
:
self
.
location_has_agent_direction
[(
agent
.
position
,
agent
.
direction
)]
=
\
self
.
location_has_agent_direction
[(
agent
.
position
,
agent
.
direction
)]
+
1
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
}
...
...
@@ -264,20 +271,28 @@ class TreeObsForRailEnv(ObservationBuilder):
if
self
.
location_has_agent_malfunction
[
position
]
>
malfunctioning_agent
:
malfunctioning_agent
=
self
.
location_has_agent_malfunction
[
position
]
if
self
.
location_has_
agent
_
direction
[
position
]
==
direction
:
if
(
agent
.
position
,
agent
.
direction
)
in
self
.
location_has_agent_
direction
:
# Cummulate the number of agents on branch with same direction
other_agent_same_direction
+=
1
other_agent_same_direction
+=
self
.
location_has_agent_direction
[(
agent
.
position
,
agent
.
direction
)]
# Check fractional speed of agents
current_fractional_speed
=
self
.
location_has_agent_speed
[
position
]
if
current_fractional_speed
<
min_fractional_speed
:
min_fractional_speed
=
current_fractional_speed
if
self
.
location_has_agent_direction
[
position
]
!=
direction
:
# Cummulate the number of agents on branch with other direction
other_agent_opposite_direction
+=
1
# Other direction agents
# 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
)]
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)
# Check number of possible transitions for agent and total number of transitions in cell (type)
cell_transitions
=
self
.
env
.
rail
.
get_transitions
(
*
position
,
direction
)
transition_bit
=
bin
(
self
.
env
.
rail
.
get_full_transitions
(
*
position
))
total_transitions
=
transition_bit
.
count
(
"
1
"
)
...
...
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