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
2b40ef62
Commit
2b40ef62
authored
5 years ago
by
spiglerg
Browse files
Options
Downloads
Patches
Plain Diff
fixed issue
#60
parent
739df52f
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/simple_example_3.py
+3
-3
3 additions, 3 deletions
examples/simple_example_3.py
flatland/envs/observations.py
+22
-9
22 additions, 9 deletions
flatland/envs/observations.py
with
25 additions
and
12 deletions
examples/simple_example_3.py
+
3
−
3
View file @
2b40ef62
...
@@ -7,8 +7,8 @@ from flatland.envs.observations import TreeObsForRailEnv
...
@@ -7,8 +7,8 @@ from flatland.envs.observations import TreeObsForRailEnv
from
flatland.envs.rail_env
import
RailEnv
from
flatland.envs.rail_env
import
RailEnv
from
flatland.utils.rendertools
import
RenderTool
from
flatland.utils.rendertools
import
RenderTool
random
.
seed
(
1
0
)
random
.
seed
(
1
)
np
.
random
.
seed
(
1
0
)
np
.
random
.
seed
(
1
)
env
=
RailEnv
(
width
=
7
,
env
=
RailEnv
(
width
=
7
,
height
=
7
,
height
=
7
,
...
@@ -19,7 +19,7 @@ env = RailEnv(width=7,
...
@@ -19,7 +19,7 @@ env = RailEnv(width=7,
# Print the observation vector for agent 0
# Print the observation vector for agent 0
obs
,
all_rewards
,
done
,
_
=
env
.
step
({
0
:
0
})
obs
,
all_rewards
,
done
,
_
=
env
.
step
({
0
:
0
})
for
i
in
range
(
env
.
get_num_agents
()):
for
i
in
range
(
env
.
get_num_agents
()):
env
.
obs_builder
.
util_print_obs_subtree
(
tree
=
obs
[
i
],
num_features_per_node
=
5
)
env
.
obs_builder
.
util_print_obs_subtree
(
tree
=
obs
[
i
],
num_features_per_node
=
7
)
env_renderer
=
RenderTool
(
env
,
gl
=
"
PIL
"
)
env_renderer
=
RenderTool
(
env
,
gl
=
"
PIL
"
)
env_renderer
.
renderEnv
(
show
=
True
,
frames
=
True
)
env_renderer
.
renderEnv
(
show
=
True
,
frames
=
True
)
...
...
This diff is collapsed.
Click to expand it.
flatland/envs/observations.py
+
22
−
9
View file @
2b40ef62
...
@@ -31,19 +31,32 @@ class TreeObsForRailEnv(ObservationBuilder):
...
@@ -31,19 +31,32 @@ class TreeObsForRailEnv(ObservationBuilder):
self
.
location_has_agent
=
{}
self
.
location_has_agent
=
{}
self
.
location_has_agent_direction
=
{}
self
.
location_has_agent_direction
=
{}
self
.
agents_previous_reset
=
None
def
reset
(
self
):
def
reset
(
self
):
agents
=
self
.
env
.
agents
agents
=
self
.
env
.
agents
nAgents
=
len
(
agents
)
nAgents
=
len
(
agents
)
self
.
distance_map
=
np
.
inf
*
np
.
ones
(
shape
=
(
nAgents
,
# self.env.number_of_agents,
self
.
env
.
height
,
self
.
env
.
width
,
4
))
self
.
max_dist
=
np
.
zeros
(
nAgents
)
self
.
max_dist
=
[
self
.
_distance_map_walker
(
agent
.
target
,
i
)
for
i
,
agent
in
enumerate
(
agents
)]
# Update local lookup table for all agents' target locations
compute_distance_map
=
True
self
.
location_has_target
=
{
tuple
(
agent
.
target
):
1
for
agent
in
agents
}
if
self
.
agents_previous_reset
is
not
None
:
if
nAgents
==
len
(
self
.
agents_previous_reset
):
compute_distance_map
=
False
for
i
in
range
(
nAgents
):
if
agents
[
i
].
target
!=
self
.
agents_previous_reset
[
i
].
target
:
compute_distance_map
=
True
self
.
agents_previous_reset
=
agents
if
compute_distance_map
:
self
.
distance_map
=
np
.
inf
*
np
.
ones
(
shape
=
(
nAgents
,
# self.env.number_of_agents,
self
.
env
.
height
,
self
.
env
.
width
,
4
))
self
.
max_dist
=
np
.
zeros
(
nAgents
)
self
.
max_dist
=
[
self
.
_distance_map_walker
(
agent
.
target
,
i
)
for
i
,
agent
in
enumerate
(
agents
)]
# Update local lookup table for all agents' target locations
self
.
location_has_target
=
{
tuple
(
agent
.
target
):
1
for
agent
in
agents
}
def
_distance_map_walker
(
self
,
position
,
target_nr
):
def
_distance_map_walker
(
self
,
position
,
target_nr
):
"""
"""
...
...
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