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
21d3448b
Commit
21d3448b
authored
5 years ago
by
Erik Nygren
Browse files
Options
Downloads
Patches
Plain Diff
First impementation of sparse rail generator.
not functional yet
parent
6fade66c
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
+90
-0
90 additions, 0 deletions
flatland/envs/generators.py
tests/test_flatland_env_sparse_rail_generator.py
+14
-0
14 additions, 0 deletions
tests/test_flatland_env_sparse_rail_generator.py
with
104 additions
and
0 deletions
flatland/envs/generators.py
+
90
−
0
View file @
21d3448b
...
@@ -690,3 +690,93 @@ def realistic_rail_generator(nr_start_goal=1, nr_extra=100, min_dist=20, max_dis
...
@@ -690,3 +690,93 @@ def realistic_rail_generator(nr_start_goal=1, nr_extra=100, min_dist=20, max_dis
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
)
return
generator
return
generator
def
sparse_rail_generator
(
nr_train_stations
=
1
,
nr_nodes
=
100
,
mean_node_neighbours
=
2
,
min_node_dist
=
20
,
node_radius
=
2
,
seed
=
0
):
'''
:param nr_train_stations:
:param nr_nodes:
:param mean_node_neighbours:
:param min_node_dist:
:param seed:
:return:
'''
def
generator
(
width
,
height
,
num_agents
,
num_resets
=
0
):
if
num_agents
>
nr_train_stations
:
num_agents
=
nr_train_stations
print
(
"
complex_rail_generator: num_agents > nr_start_goal, changing num_agents
"
)
rail_trans
=
RailEnvTransitions
()
grid_map
=
GridTransitionMap
(
width
=
width
,
height
=
height
,
transitions
=
rail_trans
)
rail_array
=
grid_map
.
grid
rail_array
.
fill
(
0
)
np
.
random
.
seed
(
seed
+
num_resets
)
# Generate a set of nodes for the sparse network
node_positions
=
[]
for
node_idx
in
range
(
nr_nodes
):
to_close
=
True
while
to_close
:
x_tmp
=
np
.
random
.
randint
(
width
)
y_tmp
=
np
.
random
.
randint
(
height
)
to_close
=
False
for
node_pos
in
node_positions
:
if
distance_on_rail
((
x_tmp
,
y_tmp
),
node_pos
)
<
min_node_dist
:
to_close
=
True
if
not
to_close
:
node_positions
.
append
((
x_tmp
,
y_tmp
))
# Generate start and target node directory for all agents
agent_start_targets_nodes
=
[]
for
agent_idx
in
range
(
num_agents
):
start_target_tuple
=
np
.
random
.
choice
(
nr_nodes
,
2
,
replace
=
False
)
agent_start_targets_nodes
.
append
(
start_target_tuple
)
# Generate actual start and target locations from around nodes
agents_position
=
[]
agents_target
=
[]
agents_direction
=
[]
agent_idx
=
0
for
start_target
in
agent_start_targets_nodes
:
start_x
=
np
.
clip
(
node_positions
[
start_target
[
0
]][
0
]
+
np
.
random
.
randint
(
-
node_radius
,
node_radius
),
0
,
width
-
1
)
start_y
=
np
.
clip
(
node_positions
[
start_target
[
0
]][
1
]
+
np
.
random
.
randint
(
-
node_radius
,
node_radius
),
0
,
height
-
1
)
target_x
=
np
.
clip
(
node_positions
[
start_target
[
1
]][
0
]
+
np
.
random
.
randint
(
-
node_radius
,
node_radius
),
0
,
width
-
1
)
target_y
=
np
.
clip
(
node_positions
[
start_target
[
1
]][
1
]
+
np
.
random
.
randint
(
-
node_radius
,
node_radius
),
0
,
height
-
1
)
if
agent_idx
==
0
:
agents_position
.
append
((
start_y
,
start_x
))
agents_target
.
append
((
target_y
,
target_x
))
else
:
while
((
start_x
,
start_y
)
in
agents_position
or
(
target_x
,
target_y
)
in
agents_target
):
start_x
=
np
.
clip
(
node_positions
[
start_target
[
0
]][
0
]
+
np
.
random
.
randint
(
-
node_radius
,
node_radius
),
0
,
width
-
1
)
start_y
=
np
.
clip
(
node_positions
[
start_target
[
0
]][
1
]
+
np
.
random
.
randint
(
-
node_radius
,
node_radius
),
0
,
height
-
1
)
target_x
=
np
.
clip
(
node_positions
[
start_target
[
1
]][
0
]
+
np
.
random
.
randint
(
-
node_radius
,
node_radius
),
0
,
width
-
1
)
target_y
=
np
.
clip
(
node_positions
[
start_target
[
1
]][
1
]
+
np
.
random
.
randint
(
-
node_radius
,
node_radius
),
0
,
height
-
1
)
agents_position
.
append
((
start_y
,
start_x
))
agents_target
.
append
((
target_y
,
target_x
))
agents_direction
.
append
(
0
)
agent_idx
+=
1
print
(
agents_position
)
print
(
agents_target
)
print
(
node_positions
)
for
n
in
node_positions
:
for
m
in
node_positions
:
print
(
distance_on_rail
(
n
,
m
))
return
grid_map
,
agents_position
,
agents_direction
,
agents_target
,
[
1.0
]
*
len
(
agents_position
)
return
generator
This diff is collapsed.
Click to expand it.
tests/test_flatland_env_sparse_rail_generator.py
0 → 100644
+
14
−
0
View file @
21d3448b
from
flatland.envs.generators
import
sparse_rail_generator
from
flatland.envs.observations
import
GlobalObsForRailEnv
from
flatland.envs.rail_env
import
RailEnv
def
test_sparse_rail_generator
():
env
=
RailEnv
(
width
=
20
,
height
=
20
,
rail_generator
=
sparse_rail_generator
(
nr_train_stations
=
10
,
nr_nodes
=
5
,
min_node_dist
=
10
,
node_radius
=
4
),
number_of_agents
=
10
,
obs_builder_object
=
GlobalObsForRailEnv
())
# reset to initialize agents_static
env
.
reset
()
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