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
75b24550
Commit
75b24550
authored
5 years ago
by
Erik Nygren
Browse files
Options
Downloads
Patches
Plain Diff
Fixing level sparse rail generator
parent
8b39c7f7
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
flatland/envs/rail_generators.py
+7
-5
7 additions, 5 deletions
flatland/envs/rail_generators.py
with
7 additions
and
5 deletions
flatland/envs/rail_generators.py
+
7
−
5
View file @
75b24550
...
...
@@ -614,9 +614,10 @@ def sparse_rail_generator(max_num_cities: int = 5, grid_mode: bool = False, max_
# We compute the city radius by the given max number of rails it can contain.
# The radius is equal to the number of tracks divided by 2
# We add 2 cells to avoid that track lenght is to shot
# We add 2 cells to avoid that track lenght is to sho
r
t
city_padding
=
2
city_radius
=
int
(
np
.
ceil
((
max_rails_in_city
)
//
2
))
+
city_padding
# We use ceil if we get uneven numbers of city radius. This is to guarantee that all rails fit within the city.
city_radius
=
int
(
np
.
ceil
((
max_rails_in_city
)
/
2
))
+
city_padding
vector_field
=
np
.
zeros
(
shape
=
(
height
,
width
))
-
1.
min_nr_rails_in_city
=
2
...
...
@@ -843,9 +844,11 @@ def sparse_rail_generator(max_num_cities: int = 5, grid_mode: bool = False, max_
start_idx
=
int
((
nr_of_connection_points
-
number_of_out_rails
)
/
2
)
for
direction
in
range
(
4
):
connection_slots
=
np
.
arange
(
nr_of_connection_points
)
-
start_idx
# Offset the rails away from the center of the city
offset_distances
=
np
.
arange
(
nr_of_connection_points
)
-
int
(
nr_of_connection_points
/
2
)
# The clipping helps ofsetting one side more than the other to avoid switches at same locations
# The magic number plus one is added such that all points have at least one offset
inner_point_offset
=
np
.
abs
(
offset_distances
)
+
np
.
clip
(
offset_distances
,
0
,
1
)
+
1
for
connection_idx
in
range
(
connections_per_direction
[
direction
]):
if
direction
==
0
:
tmp_coordinates
=
(
...
...
@@ -1024,8 +1027,8 @@ def sparse_rail_generator(max_num_cities: int = 5, grid_mode: bool = False, max_
source
=
inner_connection_points
[
current_city
][
boarder
][
track_id
]
target
=
inner_connection_points
[
current_city
][
opposite_boarder
][
track_id
]
current_track
=
connect_straight_line_in_grid_map
(
grid_map
,
source
,
target
,
rail_trans
)
free_rails
[
current_city
].
append
(
current_track
)
for
track_id
in
range
(
nr_of_connection_points
):
source
=
inner_connection_points
[
current_city
][
boarder
][
track_id
]
target
=
inner_connection_points
[
current_city
][
opposite_boarder
][
track_id
]
...
...
@@ -1042,7 +1045,6 @@ def sparse_rail_generator(max_num_cities: int = 5, grid_mode: bool = False, max_
target_outer
=
outer_connection_points
[
current_city
][
opposite_boarder
][
track_id
-
start_idx
]
connect_straight_line_in_grid_map
(
grid_map
,
source
,
source_outer
,
rail_trans
)
connect_straight_line_in_grid_map
(
grid_map
,
target
,
target_outer
,
rail_trans
)
return
free_rails
def
_set_trainstation_positions
(
city_positions
:
IntVector2DArray
,
city_radius
:
int
,
...
...
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