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
c9207ec0
Commit
c9207ec0
authored
5 years ago
by
Erik Nygren
Browse files
Options
Downloads
Patches
Plain Diff
updated how closest neighbours are found. Now always looking at directions similar to initial try
parent
35cc3bc4
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
examples/flatland_2_0_example.py
+1
-1
1 addition, 1 deletion
examples/flatland_2_0_example.py
flatland/envs/rail_generators.py
+25
-33
25 additions, 33 deletions
flatland/envs/rail_generators.py
with
26 additions
and
34 deletions
examples/flatland_2_0_example.py
+
1
−
1
View file @
c9207ec0
...
@@ -33,7 +33,7 @@ env = RailEnv(width=50,
...
@@ -33,7 +33,7 @@ env = RailEnv(width=50,
rail_generator
=
sparse_rail_generator
(
num_cities
=
9
,
# Number of cities in map (where train stations are)
rail_generator
=
sparse_rail_generator
(
num_cities
=
9
,
# Number of cities in map (where train stations are)
min_node_dist
=
12
,
# Minimal distance of nodes
min_node_dist
=
12
,
# Minimal distance of nodes
node_radius
=
4
,
# Proximity of stations to city center
node_radius
=
4
,
# Proximity of stations to city center
seed
=
0
,
# Random seed
seed
=
12
,
# Random seed
grid_mode
=
False
,
grid_mode
=
False
,
max_inter_city_rails
=
2
,
max_inter_city_rails
=
2
,
tracks_in_city
=
5
,
tracks_in_city
=
5
,
...
...
This diff is collapsed.
Click to expand it.
flatland/envs/rail_generators.py
+
25
−
33
View file @
c9207ec0
...
@@ -728,23 +728,19 @@ def sparse_rail_generator(num_cities=5, min_node_dist=20, node_radius=2,
...
@@ -728,23 +728,19 @@ def sparse_rail_generator(num_cities=5, min_node_dist=20, node_radius=2,
for
current_node
in
np
.
arange
(
len
(
node_positions
)):
for
current_node
in
np
.
arange
(
len
(
node_positions
)):
direction
=
0
direction
=
0
connected_to_city
=
[]
connected_to_city
=
[]
neighbours
=
_closest_neigh_in_direction
(
current_node
,
node_positions
)
for
nbr_connection_points
in
connection_info
[
current_node
]:
for
nbr_connection_points
in
connection_info
[
current_node
]:
if
nbr_connection_points
>
0
:
if
nbr_connection_points
>
0
:
neighb_idx
=
_closest_neigh_in_direction
(
current_node
,
direction
,
node_positions
)
neighb_idx
=
neighbours
[
direction
]
else
:
else
:
direction
+=
1
direction
+=
1
continue
continue
if
neighb_idx
is
None
or
neighb_idx
in
connected_to_city
:
# If no closest neighbour was found look for the next one clock wise to avoid connecting to previous node
node_dist
=
[]
tmp_direction
=
(
direction
+
1
)
%
4
for
av_node
in
node_positions
:
while
neighb_idx
is
None
:
node_dist
.
append
(
distance_on_rail
(
node_positions
[
current_node
],
av_node
))
neighb_idx
=
neighbours
[
tmp_direction
]
i
=
1
tmp_direction
=
(
tmp_direction
-
1
)
%
4
neighbours
=
np
.
argsort
(
node_dist
)
neighb_idx
=
neighbours
[
i
]
while
neighb_idx
in
connected_to_city
:
i
+=
1
neighb_idx
=
neighbours
[
i
]
connected_to_city
.
append
(
neighb_idx
)
connected_to_city
.
append
(
neighb_idx
)
for
tmp_out_connection_point
in
connection_points
[
current_node
][
direction
]:
for
tmp_out_connection_point
in
connection_points
[
current_node
][
direction
]:
...
@@ -882,33 +878,29 @@ def sparse_rail_generator(num_cities=5, min_node_dist=20, node_radius=2,
...
@@ -882,33 +878,29 @@ def sparse_rail_generator(num_cities=5, min_node_dist=20, node_radius=2,
for
cell
in
rails_to_fix
:
for
cell
in
rails_to_fix
:
grid_map
.
fix_transitions
(
cell
)
grid_map
.
fix_transitions
(
cell
)
def
_closest_neigh_in_direction
(
current_node
,
direction
,
node_positions
):
def
_closest_neigh_in_direction
(
current_node
,
node_positions
):
# Sort available neighbors according to their distance.
"""
Returns indices of closest neighbours in every direction NESW
:param current_node: Index of node in node_positions list
:param node_positions: list of all points being considered
:return: list of index of closest neighbours in all directions
"""
node_dist
=
[]
node_dist
=
[]
closest_neighb
=
[
None
for
i
in
range
(
4
)]
for
av_node
in
range
(
len
(
node_positions
)):
for
av_node
in
range
(
len
(
node_positions
)):
node_dist
.
append
(
distance_on_rail
(
node_positions
[
current_node
],
node_positions
[
av_node
]))
node_dist
.
append
(
distance_on_rail
(
node_positions
[
current_node
],
node_positions
[
av_node
]))
sorted_neighbours
=
np
.
argsort
(
node_dist
)
sorted_neighbours
=
np
.
argsort
(
node_dist
)
direction_set
=
0
for
neighb
in
sorted_neighbours
[
1
:]:
for
neighb
in
sorted_neighbours
[
1
:]:
distance_0
=
np
.
abs
(
node_positions
[
current_node
][
0
]
-
node_positions
[
neighb
][
0
])
direction_to_neighb
=
direction_to_point
(
node_positions
[
current_node
],
node_positions
[
neighb
])
distance_1
=
np
.
abs
(
node_positions
[
current_node
][
1
]
-
node_positions
[
neighb
][
1
])
if
closest_neighb
[
direction_to_neighb
]
==
None
:
if
direction
==
0
:
closest_neighb
[
direction_to_neighb
]
=
neighb
if
node_positions
[
neighb
][
0
]
<
node_positions
[
current_node
][
0
]
and
distance_1
<=
distance_0
:
direction_set
+=
1
return
neighb
if
direction_set
==
4
:
if
direction
==
1
:
return
closest_neighb
if
node_positions
[
neighb
][
1
]
>
node_positions
[
current_node
][
1
]
and
distance_0
<=
distance_1
:
return
neighb
return
closest_neighb
if
direction
==
2
:
if
node_positions
[
neighb
][
0
]
>
node_positions
[
current_node
][
0
]
and
distance_1
<=
distance_0
:
return
neighb
if
direction
==
3
:
if
node_positions
[
neighb
][
1
]
<
node_positions
[
current_node
][
1
]
and
distance_0
<=
distance_1
:
return
neighb
return
None
def
argsort
(
seq
):
def
argsort
(
seq
):
# http://stackoverflow.com/questions/3071415/efficient-method-to-calculate-the-rank-vector-of-a-list-in-python
# http://stackoverflow.com/questions/3071415/efficient-method-to-calculate-the-rank-vector-of-a-list-in-python
...
...
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