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
300dccdc
Commit
300dccdc
authored
5 years ago
by
u229589
Browse files
Options
Downloads
Patches
Plain Diff
refactor name _city_overlap
parent
74346783
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
+6
-8
6 additions, 8 deletions
flatland/envs/rail_generators.py
with
6 additions
and
8 deletions
flatland/envs/rail_generators.py
+
6
−
8
View file @
300dccdc
...
...
@@ -566,7 +566,7 @@ def sparse_rail_generator(max_num_cities: int = 5, grid_mode: bool = False, max_
else
:
city_positions
,
city_cells
=
_generate_random_city_positions
(
max_num_cities
,
city_radius
,
width
,
height
)
# reduce num_cities
, _num_cities, _num_intersections
if less were generated in
not_grid_
mode
# reduce num_cities if less were generated in
random
mode
num_cities
=
len
(
city_positions
)
if
DEBUG_PRINT_TIMING
:
print
(
"
City position time
"
,
time
.
time
()
-
node_time_start
,
"
Seconds
"
)
...
...
@@ -622,10 +622,8 @@ def sparse_rail_generator(max_num_cities: int = 5, grid_mode: bool = False, max_
}}
def
_generate_random_city_positions
(
num_cities
:
int
,
city_radius
:
int
,
width
:
int
,
height
:
int
)
->
(
List
[
Tuple
[
int
,
int
]],
List
[
Tuple
[
int
,
int
]]):
node_positions
=
[]
city_cells
=
[]
node_positions
:
List
[
Tuple
[
int
,
int
]]
=
[]
city_cells
:
List
[
Tuple
[
int
,
int
]]
=
[]
for
node_idx
in
range
(
num_cities
):
to_close
=
True
tries
=
0
...
...
@@ -636,7 +634,7 @@ def sparse_rail_generator(max_num_cities: int = 5, grid_mode: bool = False, max_
to_close
=
False
# Check distance to nodes
for
node_pos
in
node_positions
:
if
_
city
_overlap
((
x_tmp
,
y_tmp
),
node_pos
,
2
*
(
city_radius
+
1
)
+
1
):
if
_
are_cities
_overlap
ping
((
x_tmp
,
y_tmp
),
node_pos
,
2
*
(
city_radius
+
1
)
+
1
):
to_close
=
True
if
not
to_close
:
...
...
@@ -909,7 +907,7 @@ def sparse_rail_generator(max_num_cities: int = 5, grid_mode: bool = False, max_
# http://stackoverflow.com/questions/3071415/efficient-method-to-calculate-the-rank-vector-of-a-list-in-python
return
sorted
(
range
(
len
(
seq
)),
key
=
seq
.
__getitem__
)
def
_get_cells_in_city
(
center
:
Tuple
[
int
],
radius
:
int
)
->
List
[
Tuple
[
int
,
int
]]:
def
_get_cells_in_city
(
center
:
Tuple
[
int
,
int
],
radius
:
int
)
->
List
[
Tuple
[
int
,
int
]]:
"""
Function to return all cells within a city
:param center: center coordinates of city
...
...
@@ -922,7 +920,7 @@ def sparse_rail_generator(max_num_cities: int = 5, grid_mode: bool = False, max_
y_values
=
np
.
tile
(
y_range
,
len
(
x_range
))
return
list
(
zip
(
x_values
,
y_values
))
def
_
city
_overlap
(
center_1
,
center_2
,
radius
):
def
_
are_cities
_overlap
ping
(
center_1
,
center_2
,
radius
):
return
np
.
abs
(
center_1
[
0
]
-
center_2
[
0
])
<
radius
and
np
.
abs
(
center_1
[
1
]
-
center_2
[
1
])
<
radius
def
_track_number
(
city_position
,
city_orientation
,
position
):
...
...
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