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
44635204
Commit
44635204
authored
5 years ago
by
Erik Nygren
Browse files
Options
Downloads
Patches
Plain Diff
fixed bug in randomly placed cities
parent
92c0f184
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
examples/flatland_2_0_example.py
+2
-2
2 additions, 2 deletions
examples/flatland_2_0_example.py
flatland/envs/rail_generators.py
+16
-15
16 additions, 15 deletions
flatland/envs/rail_generators.py
with
18 additions
and
17 deletions
examples/flatland_2_0_example.py
+
2
−
2
View file @
44635204
...
...
@@ -35,11 +35,11 @@ env = RailEnv(width=50,
rail_generator
=
sparse_rail_generator
(
num_cities
=
9
,
# Number of cities in map (where train stations are)
num_intersections
=
0
,
# Number of intersections (no start / target)
num_trainstations
=
15
,
# Number of possible start/targets on map
min_node_dist
=
3
,
# Minimal distance of nodes
min_node_dist
=
10
,
# Minimal distance of nodes
node_radius
=
4
,
# Proximity of stations to city center
num_neighb
=
2
,
# Number of connections to other cities/intersections
seed
=
15
,
# Random seed
grid_mode
=
Tru
e
,
grid_mode
=
Fals
e
,
enhance_intersection
=
False
),
schedule_generator
=
sparse_schedule_generator
(),
...
...
This diff is collapsed.
Click to expand it.
flatland/envs/rail_generators.py
+
16
−
15
View file @
44635204
...
...
@@ -604,26 +604,30 @@ def sparse_rail_generator(num_cities=5, num_intersections=4, num_trainstations=2
# Start at some node
current_node
=
np
.
random
.
randint
(
len
(
available_nodes_full
))
node_stack
=
[
current_node
]
open_nodes
=
np
.
copy
(
available_nodes_full
)
allowed_connections
=
num_neighb
first_node
=
True
i
=
0
boarder_connections
=
set
()
while
len
(
node_stack
)
>
0
:
current_node
=
node_stack
[
0
]
delete_idx
=
np
.
where
(
available_nodes_full
==
current_node
)
available_nodes_full
=
np
.
delete
(
available_nodes_full
,
delete_idx
,
0
)
while
len
(
open_nodes
)
>
0
:
if
len
(
node_stack
)
>
0
:
current_node
=
node_stack
[
0
]
else
:
current_node
=
np
.
random
.
choice
(
open_nodes
)
node_stack
.
append
(
current_node
)
delete_idx
=
np
.
where
(
open_nodes
==
current_node
)
open_nodes
=
np
.
delete
(
open_nodes
,
delete_idx
,
0
)
# Priority city to intersection connections
if
current_node
<
_num_cities
and
len
(
available_intersections
)
>
0
:
available_nodes
=
available_intersections
delete_idx
=
np
.
where
(
available_cities
==
current_node
)
available_cities
=
np
.
delete
(
available_cities
,
delete_idx
,
0
)
#
available_cities = np.delete(available_cities, delete_idx, 0)
# Priority intersection to city connections
elif
current_node
>=
_num_cities
and
len
(
available_cities
)
>
0
:
available_nodes
=
available_cities
delete_idx
=
np
.
where
(
available_intersections
==
current_node
)
available_intersections
=
np
.
delete
(
available_intersections
,
delete_idx
,
0
)
#
available_intersections = np.delete(available_intersections, delete_idx, 0)
# If no options possible connect to whatever node is still available
else
:
...
...
@@ -637,18 +641,15 @@ def sparse_rail_generator(num_cities=5, num_intersections=4, num_trainstations=2
# Set number of neighboring nodes
if
len
(
available_nodes
)
>=
allowed_connections
:
connected_neighb_idx
=
available_nodes
[:
allowed_connections
]
connected_neighb_idx
=
available_nodes
[
1
:
allowed_connections
+
1
]
else
:
connected_neighb_idx
=
available_nodes
print
(
current_node
,
connected_neighb_idx
)
# Less connections for subsequent nodes
if
first_node
:
allowed_connections
-=
1
first_node
=
False
# Connect to the neighboring nodes
for
neighb
in
connected_neighb_idx
:
if
neighb
not
in
node_stack
:
if
neighb
not
in
node_stack
and
neighb
in
open_nodes
:
node_stack
.
append
(
neighb
)
dist_from_center
=
distance_on_rail
(
node_positions
[
current_node
],
node_positions
[
neighb
])
...
...
@@ -824,8 +825,8 @@ def sparse_rail_generator(num_cities=5, num_intersections=4, num_trainstations=2
tries
=
0
while
to_close
:
x_tmp
=
node_radius
+
np
.
random
.
randint
(
height
-
node_radius
-
1
)
y_tmp
=
node_radius
+
np
.
random
.
randint
(
width
-
node_radius
-
1
)
x_tmp
=
node_radius
+
np
.
random
.
randint
(
height
-
2
*
node_radius
-
1
)
y_tmp
=
node_radius
+
np
.
random
.
randint
(
width
-
2
*
node_radius
-
1
)
to_close
=
False
# Check distance to cities
...
...
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