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
sfwatergit
Flatland
Commits
ed720ea2
Commit
ed720ea2
authored
5 years ago
by
Erik Nygren
Browse files
Options
Downloads
Patches
Plain Diff
minor changes to rendering of observation
parent
e6051fd9
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
examples/training_navigation.py
+8
-6
8 additions, 6 deletions
examples/training_navigation.py
flatland/envs/generators.py
+1
-1
1 addition, 1 deletion
flatland/envs/generators.py
flatland/utils/rendertools.py
+6
-5
6 additions, 5 deletions
flatland/utils/rendertools.py
with
15 additions
and
12 deletions
examples/training_navigation.py
+
8
−
6
View file @
ed720ea2
...
@@ -5,7 +5,7 @@ from flatland.utils.rendertools import *
...
@@ -5,7 +5,7 @@ from flatland.utils.rendertools import *
from
flatland.baselines.dueling_double_dqn
import
Agent
from
flatland.baselines.dueling_double_dqn
import
Agent
from
collections
import
deque
from
collections
import
deque
import
torch
,
random
import
torch
,
random
import
time
random
.
seed
(
1
)
random
.
seed
(
1
)
np
.
random
.
seed
(
1
)
np
.
random
.
seed
(
1
)
...
@@ -25,15 +25,16 @@ transition_probability = [15, # empty cell - Case 0
...
@@ -25,15 +25,16 @@ transition_probability = [15, # empty cell - Case 0
# Example generate a random rail
# Example generate a random rail
"""
"""
env = RailEnv(width=
1
0,
env = RailEnv(width=
2
0,
height=
1
0,
height=
2
0,
rail_generator=random_rail_generator(cell_type_relative_proportion=transition_probability),
rail_generator=random_rail_generator(cell_type_relative_proportion=transition_probability),
number_of_agents=
5
)
number_of_agents=
1
)
"""
"""
env
=
RailEnv
(
width
=
15
,
env
=
RailEnv
(
width
=
15
,
height
=
15
,
height
=
15
,
rail_generator
=
complex_rail_generator
(
nr_start_goal
=
3
,
min_dist
=
5
,
max_dist
=
99999
,
seed
=
0
),
rail_generator
=
complex_rail_generator
(
nr_start_goal
=
2
,
nr_extra
=
30
,
min_dist
=
5
,
max_dist
=
99999
,
seed
=
0
),
number_of_agents
=
3
)
number_of_agents
=
3
)
"""
"""
env = RailEnv(width=20,
env = RailEnv(width=20,
height=20,
height=20,
...
@@ -139,7 +140,8 @@ for trials in range(1, n_trials + 1):
...
@@ -139,7 +140,8 @@ for trials in range(1, n_trials + 1):
# Run episode
# Run episode
for
step
in
range
(
100
):
for
step
in
range
(
100
):
if
demo
:
if
demo
:
env_renderer
.
renderEnv
(
show
=
True
)
env_renderer
.
renderEnv
(
show
=
True
,
obsrender
=
True
)
time
.
sleep
(
2
)
# print(step)
# print(step)
# Action
# Action
for
a
in
range
(
env
.
get_num_agents
()):
for
a
in
range
(
env
.
get_num_agents
()):
...
...
This diff is collapsed.
Click to expand it.
flatland/envs/generators.py
+
1
−
1
View file @
ed720ea2
...
@@ -9,7 +9,7 @@ from flatland.envs.env_utils import distance_on_rail, connect_rail, get_directio
...
@@ -9,7 +9,7 @@ from flatland.envs.env_utils import distance_on_rail, connect_rail, get_directio
from
flatland.envs.env_utils
import
get_rnd_agents_pos_tgt_dir_on_rail
from
flatland.envs.env_utils
import
get_rnd_agents_pos_tgt_dir_on_rail
def
complex_rail_generator
(
nr_start_goal
=
1
,
nr_extra
=
10
,
min_dist
=
2
,
max_dist
=
99999
,
seed
=
0
):
def
complex_rail_generator
(
nr_start_goal
=
1
,
nr_extra
=
10
0
,
min_dist
=
2
0
,
max_dist
=
99999
,
seed
=
0
):
"""
"""
Parameters
Parameters
-------
-------
...
...
This diff is collapsed.
Click to expand it.
flatland/utils/rendertools.py
+
6
−
5
View file @
ed720ea2
...
@@ -472,12 +472,13 @@ class RenderTool(object):
...
@@ -472,12 +472,13 @@ class RenderTool(object):
xyMid
+
[
-
dx
+
dy
,
-
dx
-
dy
]])
xyMid
+
[
-
dx
+
dy
,
-
dx
-
dy
]])
self
.
gl
.
plot
(
*
xyArrow
.
T
,
color
=
sColor
)
self
.
gl
.
plot
(
*
xyArrow
.
T
,
color
=
sColor
)
def
renderObs
(
self
,
agent_handles
,
observation_
lis
t
):
def
renderObs
(
self
,
agent_handles
,
observation_
dic
t
):
"""
"""
Render the extent of the observation of each agent. All cells that appear in the agent obsrevation will be
highlighted.
:param agent_handles: List of agent indices to adapt color and get correct observation
:param observation_dict: dictionary containing sets of cells of the agent observation
:param agent_handles:
:param observation_list:
:return:
"""
"""
rt
=
self
.
__class__
rt
=
self
.
__class__
...
@@ -485,7 +486,7 @@ class RenderTool(object):
...
@@ -485,7 +486,7 @@ class RenderTool(object):
for
agent
in
agent_handles
:
for
agent
in
agent_handles
:
color
=
cmap
(
agent
)
color
=
cmap
(
agent
)
for
visited_cell
in
observation_
lis
t
[
agent
]:
for
visited_cell
in
observation_
dic
t
[
agent
]:
cell_coord
=
array
(
visited_cell
[:
2
])
cell_coord
=
array
(
visited_cell
[:
2
])
cell_coord_trans
=
np
.
matmul
(
cell_coord
,
rt
.
grc2xy
)
+
rt
.
xyHalf
cell_coord_trans
=
np
.
matmul
(
cell_coord
,
rt
.
grc2xy
)
+
rt
.
xyHalf
self
.
_draw_square
(
cell_coord_trans
,
1
/
3
,
color
)
self
.
_draw_square
(
cell_coord_trans
,
1
/
3
,
color
)
...
...
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