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
391d7f22
Commit
391d7f22
authored
5 years ago
by
Egli Adrian (IT-SCI-API-PFI)
Browse files
Options
Downloads
Patches
Plain Diff
feasible solution: OK?
parent
f1379a0a
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
flatland/envs/generators.py
+49
-15
49 additions, 15 deletions
flatland/envs/generators.py
tests/test_flatland_env_sparse_rail_generator.py
+1
-0
1 addition, 0 deletions
tests/test_flatland_env_sparse_rail_generator.py
with
50 additions
and
15 deletions
flatland/envs/generators.py
+
49
−
15
View file @
391d7f22
...
@@ -673,10 +673,16 @@ def realistic_rail_generator(nr_start_goal=1, seed=0):
...
@@ -673,10 +673,16 @@ def realistic_rail_generator(nr_start_goal=1, seed=0):
max_n_track_seg
=
np
.
random
.
choice
([
3
,
4
,
5
])
max_n_track_seg
=
np
.
random
.
choice
([
3
,
4
,
5
])
x_offsets
=
np
.
arange
(
0
,
height
,
max_n_track_seg
).
astype
(
int
)
x_offsets
=
np
.
arange
(
0
,
height
,
max_n_track_seg
).
astype
(
int
)
agents_positions
=
[]
agents_positions_forward
=
[]
agents_directions_forward
=
[]
agents_positions_backward
=
[]
agents_directions_backward
=
[]
agents_targets
=
[]
agents_targets
=
[]
agents_directions
=
[]
idx_forward
=
[]
idx_backward
=
[]
idx_target
=
0
for
off_set_loop
in
range
(
len
(
x_offsets
)):
for
off_set_loop
in
range
(
len
(
x_offsets
)):
off_set
=
x_offsets
[
off_set_loop
]
off_set
=
x_offsets
[
off_set_loop
]
# second track
# second track
...
@@ -752,24 +758,52 @@ def realistic_rail_generator(nr_start_goal=1, seed=0):
...
@@ -752,24 +758,52 @@ def realistic_rail_generator(nr_start_goal=1, seed=0):
make_switch_w_e
(
width
,
height
,
grid_map
,
c
)
make_switch_w_e
(
width
,
height
,
grid_map
,
c
)
add_pos
=
(
int
((
start
[
0
]
+
goal
[
0
])
/
2
),
int
((
start
[
1
]
+
goal
[
1
])
/
2
))
add_pos
=
(
int
((
start
[
0
]
+
goal
[
0
])
/
2
),
int
((
start
[
1
]
+
goal
[
1
])
/
2
))
agents_positions
.
append
(
add_pos
)
if
nbr_track_loop
%
2
==
0
:
agents_directions
.
append
([
1
,
3
][
nbr_track_loop
%
2
])
agents_positions_forward
.
append
(
add_pos
)
add_pos
=
(
int
((
start
[
0
]
+
goal
[
0
])
/
2
),
int
((
2
*
start
[
1
]
+
goal
[
1
])
/
3
))
agents_directions_forward
.
append
(([
1
,
3
][
off_set_loop
%
2
]))
idx_forward
.
append
(
idx_target
)
else
:
agents_positions_backward
.
append
(
add_pos
)
agents_directions_backward
.
append
(([
1
,
3
][
off_set_loop
%
2
]))
idx_backward
.
append
(
idx_target
)
add_pos
=
(
int
((
start
[
0
]
+
goal
[
0
])
/
2
),
int
((
2
*
start
[
1
]
+
goal
[
1
])
/
3
),
idx_target
)
agents_targets
.
append
(
add_pos
)
agents_targets
.
append
(
add_pos
)
idx_target
+=
1
agents_position
=
[]
agents_position
=
[]
agents_target
=
[]
agents_target
=
[]
agents_direction
=
[]
agents_direction
=
[]
filter_agent
=
np
.
random
.
choice
(
np
.
arange
(
len
(
agents_positions
)),
min
(
len
(
agents_positions
),
num_agents
),
False
)
for
f
in
filter_agent
:
for
a
in
range
(
min
(
len
(
agents_targets
),
num_agents
)):
d
=
agents_positions
[
f
]
t
=
np
.
random
.
choice
(
range
(
len
(
agents_targets
)))
agents_position
.
append
(
d
)
d
=
agents_targets
[
t
]
d
=
agents_directions
[
f
]
agents_targets
.
pop
(
t
)
agents_direction
.
append
(
d
)
if
d
[
2
]
<
idx_target
/
2
:
filter_target
=
np
.
random
.
choice
(
np
.
arange
(
len
(
agents_targets
)),
min
(
len
(
agents_targets
),
num_agents
),
False
)
if
len
(
idx_backward
)
>
0
:
for
f
in
filter_target
:
agents_target
.
append
((
d
[
0
],
d
[
1
]))
d
=
agents_targets
[
f
]
sel
=
np
.
random
.
choice
(
range
(
len
(
idx_backward
)))
agents_target
.
append
(
d
)
# backward
p
=
agents_positions_backward
[
sel
]
d
=
agents_directions_backward
[
sel
]
agents_positions_backward
.
pop
(
sel
)
agents_directions_backward
.
pop
(
sel
)
idx_backward
.
pop
(
sel
)
agents_position
.
append
((
p
[
0
],
p
[
1
]))
agents_direction
.
append
(
d
)
else
:
if
len
(
idx_forward
)
>
0
:
agents_target
.
append
((
d
[
0
],
d
[
1
]))
sel
=
np
.
random
.
choice
(
range
(
len
(
idx_forward
)))
# forward
p
=
agents_positions_forward
[
sel
]
d
=
agents_directions_forward
[
sel
]
agents_positions_forward
.
pop
(
sel
)
agents_directions_forward
.
pop
(
sel
)
idx_forward
.
pop
(
sel
)
agents_position
.
append
((
p
[
0
],
p
[
1
]))
agents_direction
.
append
(
d
)
return
grid_map
,
agents_position
,
agents_direction
,
agents_target
,
[
1.0
]
*
len
(
agents_position
)
return
grid_map
,
agents_position
,
agents_direction
,
agents_target
,
[
1.0
]
*
len
(
agents_position
)
...
...
This diff is collapsed.
Click to expand it.
tests/test_flatland_env_sparse_rail_generator.py
+
1
−
0
View file @
391d7f22
...
@@ -33,3 +33,4 @@ def test_sparse_rail_generator():
...
@@ -33,3 +33,4 @@ def test_sparse_rail_generator():
env_renderer
=
RenderTool
(
env
,
gl
=
"
PILSVG
"
,
)
env_renderer
=
RenderTool
(
env
,
gl
=
"
PILSVG
"
,
)
env_renderer
.
render_env
(
show
=
True
,
show_observations
=
True
,
show_predictions
=
False
)
env_renderer
.
render_env
(
show
=
True
,
show_observations
=
True
,
show_predictions
=
False
)
time
.
sleep
(
2
)
time
.
sleep
(
2
)
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