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
14034cfa
Commit
14034cfa
authored
5 years ago
by
Egli Adrian (IT-SCI-API-PFI)
Browse files
Options
Downloads
Patches
Plain Diff
new method for generating switches at stations
parent
4b64873a
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
examples/Simple_Realistic_Railway_Generator.py
+21
-15
21 additions, 15 deletions
examples/Simple_Realistic_Railway_Generator.py
with
21 additions
and
15 deletions
examples/Simple_Realistic_Railway_Generator.py
+
21
−
15
View file @
14034cfa
...
@@ -174,22 +174,26 @@ def realistic_rail_generator(num_cities=5,
...
@@ -174,22 +174,26 @@ def realistic_rail_generator(num_cities=5,
return
nodes_added
,
station_slots
,
start_nodes_added
,
end_nodes_added
,
station_tracks
return
nodes_added
,
station_slots
,
start_nodes_added
,
end_nodes_added
,
station_tracks
def
create_switches_at_stations
(
width
,
height
,
grid_map
,
station_tracks
,
nodes_added
,
def
create_switches_at_stations
(
rail_trans
,
rail_array
,
width
,
height
,
grid_map
,
station_tracks
,
nodes_added
,
intern_nbr_of_switches_per_station_track
):
intern_nbr_of_switches_per_station_track
):
# generate switch based on switch slot list and connect them
for
city_loop
in
range
(
len
(
station_tracks
)):
for
city_loop
in
range
(
len
(
station_tracks
)):
datas
=
station_tracks
[
city_loop
]
datas
=
station_tracks
[
city_loop
]
for
data_loop
in
range
(
len
(
datas
)
-
1
):
if
len
(
datas
)
>
1
:
data
=
datas
[
data_loop
]
a
=
datas
[
0
]
data1
=
datas
[
data_loop
+
1
]
b
=
[]
if
len
(
data
)
>
2
and
len
(
data1
)
>
2
:
for
i
in
range
(
len
(
datas
)):
for
i
in
np
.
random
.
choice
(
min
(
len
(
data1
),
len
(
data
))
-
2
,
tmp
=
datas
[
i
]
intern_nbr_of_switches_per_station_track
):
if
len
(
tmp
)
>
0
:
GripMapOp
.
add_rail
(
width
,
height
,
grid_map
,
data
[
i
+
1
],
data1
[
i
+
1
],
data1
[
i
+
2
],
True
)
b
=
tmp
nodes_added
.
append
(
data
[
i
+
1
])
start_node
=
a
[
min
(
2
,
len
(
a
))]
nodes_added
.
append
(
data1
[
i
+
1
])
end_node
=
b
[
len
(
b
)
-
1
]
nodes_added
.
append
(
data1
[
i
+
2
])
rail_array
[
start_node
]
=
0
rail_array
[
end_node
]
=
0
connection
=
connect_from_nodes
(
rail_trans
,
rail_array
,
start_node
,
end_node
)
if
len
(
connection
)
>
0
:
nodes_added
.
append
(
start_node
)
nodes_added
.
append
(
end_node
)
return
nodes_added
return
nodes_added
def
calc_nbr_of_graphs
(
graph
):
def
calc_nbr_of_graphs
(
graph
):
...
@@ -392,13 +396,15 @@ def realistic_rail_generator(num_cities=5,
...
@@ -392,13 +396,15 @@ def realistic_rail_generator(num_cities=5,
generate_city_locations
,
generate_city_locations
,
intern_max_number_of_station_tracks
)
intern_max_number_of_station_tracks
)
# build switches
# build switches
# TODO remove true/false block
if
True
:
if
True
:
create_switches_at_stations
(
width
,
height
,
grid_map
,
station_tracks
,
nodes_added
,
create_switches_at_stations
(
rail_trans
,
rail_array
,
width
,
height
,
grid_map
,
station_tracks
,
nodes_added
,
intern_nbr_of_switches_per_station_track
)
intern_nbr_of_switches_per_station_track
)
# ----------------------------------------------------------------------------------
# ----------------------------------------------------------------------------------
# connect stations
# connect stations
if
True
:
# TODO remove true/false block
if
False
:
if
do_random_connect_stations
:
if
do_random_connect_stations
:
connect_random_stations
(
rail_trans
,
rail_array
,
s_nodes
,
e_nodes
,
nodes_added
,
connect_random_stations
(
rail_trans
,
rail_array
,
s_nodes
,
e_nodes
,
nodes_added
,
inter_connect_max_nbr_of_shortes_city
)
inter_connect_max_nbr_of_shortes_city
)
...
...
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