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
pranjal_dhole
Flatland
Commits
de946638
Commit
de946638
authored
3 years ago
by
nimishsantosh107
Browse files
Options
Downloads
Patches
Plain Diff
line generators sample orientations fix, rail_from_manual_spec fix
parent
7e4db340
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
flatland/envs/line_generators.py
+14
-3
14 additions, 3 deletions
flatland/envs/line_generators.py
flatland/envs/rail_generators.py
+8
-9
8 additions, 9 deletions
flatland/envs/rail_generators.py
with
22 additions
and
12 deletions
flatland/envs/line_generators.py
+
14
−
3
View file @
de946638
...
@@ -67,6 +67,15 @@ class SparseLineGen(BaseLineGen):
...
@@ -67,6 +67,15 @@ class SparseLineGen(BaseLineGen):
:param seed: Initiate random seed generator
:param seed: Initiate random seed generator
"""
"""
def
decide_orientation
(
self
,
rail
,
start
,
target
,
possible_orientations
,
np_random
:
RandomState
)
->
int
:
feasible_orientations
=
[]
for
orientation
in
possible_orientations
:
if
rail
.
check_path_exists
(
start
[
0
],
orientation
,
target
[
0
]):
feasible_orientations
.
append
(
orientation
)
return
np_random
.
choice
(
feasible_orientations
)
def
generate
(
self
,
rail
:
GridTransitionMap
,
num_agents
:
int
,
hints
:
dict
,
num_resets
:
int
,
def
generate
(
self
,
rail
:
GridTransitionMap
,
num_agents
:
int
,
hints
:
dict
,
num_resets
:
int
,
np_random
:
RandomState
)
->
Line
:
np_random
:
RandomState
)
->
Line
:
"""
"""
...
@@ -116,7 +125,8 @@ class SparseLineGen(BaseLineGen):
...
@@ -116,7 +125,8 @@ class SparseLineGen(BaseLineGen):
agent_start
=
train_stations
[
city1
][
agent_start_idx
]
agent_start
=
train_stations
[
city1
][
agent_start_idx
]
agent_target
=
train_stations
[
city2
][
agent_target_idx
]
agent_target
=
train_stations
[
city2
][
agent_target_idx
]
agent_orientation
=
np_random
.
choice
(
city1_possible_orientations
)
agent_orientation
=
self
.
decide_orientation
(
rail
,
agent_start
,
agent_target
,
city1_possible_orientations
,
np_random
)
else
:
else
:
...
@@ -125,8 +135,9 @@ class SparseLineGen(BaseLineGen):
...
@@ -125,8 +135,9 @@ class SparseLineGen(BaseLineGen):
agent_start
=
train_stations
[
city2
][
agent_start_idx
]
agent_start
=
train_stations
[
city2
][
agent_start_idx
]
agent_target
=
train_stations
[
city1
][
agent_target_idx
]
agent_target
=
train_stations
[
city1
][
agent_target_idx
]
agent_orientation
=
np_random
.
choice
(
city2_possible_orientations
)
agent_orientation
=
self
.
decide_orientation
(
rail
,
agent_start
,
agent_target
,
city2_possible_orientations
,
np_random
)
# agent1 details
# agent1 details
...
...
This diff is collapsed.
Click to expand it.
flatland/envs/rail_generators.py
+
8
−
9
View file @
de946638
...
@@ -67,7 +67,7 @@ class EmptyRailGen(RailGen):
...
@@ -67,7 +67,7 @@ class EmptyRailGen(RailGen):
return
grid_map
,
None
return
grid_map
,
None
def
rail_from_manual_specifications_generator
(
rail_spec
):
def
rail_from_manual_specifications_generator
(
rail_spec
,
optionals
):
"""
"""
Utility to convert a rail given by manual specification as a map of tuples
Utility to convert a rail given by manual specification as a map of tuples
(cell_type, rotation), to a transition map with the correct 16-bit
(cell_type, rotation), to a transition map with the correct 16-bit
...
@@ -107,7 +107,7 @@ def rail_from_manual_specifications_generator(rail_spec):
...
@@ -107,7 +107,7 @@ def rail_from_manual_specifications_generator(rail_spec):
effective_transition_cell
=
rail_env_transitions
.
rotate_transition
(
basic_type_of_cell_
,
rotation_cell_
)
effective_transition_cell
=
rail_env_transitions
.
rotate_transition
(
basic_type_of_cell_
,
rotation_cell_
)
rail
.
set_transitions
((
r
,
c
),
effective_transition_cell
)
rail
.
set_transitions
((
r
,
c
),
effective_transition_cell
)
return
[
rail
,
None
]
return
[
rail
,
optionals
]
return
generator
return
generator
...
@@ -285,15 +285,14 @@ class SparseRailGen(RailGen):
...
@@ -285,15 +285,14 @@ class SparseRailGen(RailGen):
# Fix all transition elements
# Fix all transition elements
self
.
_fix_transitions
(
city_cells
,
inter_city_lines
,
grid_map
,
vector_field
)
self
.
_fix_transitions
(
city_cells
,
inter_city_lines
,
grid_map
,
vector_field
)
return
grid_map
,
{
'
agents_hints
'
:
{
return
grid_map
,
{
'
agents_hints
'
:
{
'
num_agents
'
:
num_agents
,
'
city_positions
'
:
city_positions
,
'
city_positions
'
:
city_positions
,
'
train_stations
'
:
train_stations
,
'
train_stations
'
:
train_stations
,
'
city_orientations
'
:
city_orientations
'
city_orientations
'
:
city_orientations
}}
}}
def
_generate_random_city_positions
(
self
,
num_cities
:
int
,
city_radius
:
int
,
width
:
int
,
def
_generate_random_city_positions
(
self
,
num_cities
:
int
,
city_radius
:
int
,
width
:
int
,
height
:
int
,
np_random
:
RandomState
=
None
)
->
(
height
:
int
,
np_random
:
RandomState
=
None
)
->
Tuple
[
IntVector2DArray
,
IntVector2DArray
)
:
IntVector2DArray
,
IntVector2DArray
]
:
"""
"""
Distribute the cities randomly in the environment while respecting city sizes and guaranteeing that they
Distribute the cities randomly in the environment while respecting city sizes and guaranteeing that they
don
'
t overlap.
don
'
t overlap.
...
@@ -352,7 +351,7 @@ class SparseRailGen(RailGen):
...
@@ -352,7 +351,7 @@ class SparseRailGen(RailGen):
return
city_positions
return
city_positions
def
_generate_evenly_distr_city_positions
(
self
,
num_cities
:
int
,
city_radius
:
int
,
width
:
int
,
height
:
int
def
_generate_evenly_distr_city_positions
(
self
,
num_cities
:
int
,
city_radius
:
int
,
width
:
int
,
height
:
int
)
->
(
IntVector2DArray
,
IntVector2DArray
)
:
)
->
Tuple
[
IntVector2DArray
,
IntVector2DArray
]
:
"""
"""
Distribute the cities in an evenly spaced grid
Distribute the cities in an evenly spaced grid
...
@@ -399,11 +398,11 @@ class SparseRailGen(RailGen):
...
@@ -399,11 +398,11 @@ class SparseRailGen(RailGen):
def
_generate_city_connection_points
(
self
,
city_positions
:
IntVector2DArray
,
city_radius
:
int
,
def
_generate_city_connection_points
(
self
,
city_positions
:
IntVector2DArray
,
city_radius
:
int
,
vector_field
:
IntVector2DArray
,
rails_between_cities
:
int
,
vector_field
:
IntVector2DArray
,
rails_between_cities
:
int
,
rail_pairs_in_city
:
int
=
1
,
np_random
:
RandomState
=
None
)
->
(
rail_pairs_in_city
:
int
=
1
,
np_random
:
RandomState
=
None
)
->
Tuple
[
List
[
List
[
List
[
IntVector2D
]]],
List
[
List
[
List
[
IntVector2D
]]],
List
[
List
[
List
[
IntVector2D
]]],
List
[
List
[
List
[
IntVector2D
]]],
List
[
np
.
ndarray
],
List
[
np
.
ndarray
],
List
[
Grid4TransitionsEnum
]
)
:
List
[
Grid4TransitionsEnum
]
]
:
"""
"""
Generate the city connection points. Internal connection points are used to generate the parallel paths
Generate the city connection points. Internal connection points are used to generate the parallel paths
within the city.
within the city.
...
@@ -609,7 +608,7 @@ class SparseRailGen(RailGen):
...
@@ -609,7 +608,7 @@ class SparseRailGen(RailGen):
def
_build_inner_cities
(
self
,
city_positions
:
IntVector2DArray
,
inner_connection_points
:
List
[
List
[
List
[
IntVector2D
]]],
def
_build_inner_cities
(
self
,
city_positions
:
IntVector2DArray
,
inner_connection_points
:
List
[
List
[
List
[
IntVector2D
]]],
outer_connection_points
:
List
[
List
[
List
[
IntVector2D
]]],
rail_trans
:
RailEnvTransitions
,
outer_connection_points
:
List
[
List
[
List
[
IntVector2D
]]],
rail_trans
:
RailEnvTransitions
,
grid_map
:
GridTransitionMap
)
->
(
List
[
IntVector2DArray
],
List
[
List
[
List
[
IntVector2D
]]]
)
:
grid_map
:
GridTransitionMap
)
->
Tuple
[
List
[
IntVector2DArray
],
List
[
List
[
List
[
IntVector2D
]]]
]
:
"""
"""
Set the parallel tracks within the city. The center track of the city is of the length of the city, the lenght
Set the parallel tracks within the city. The center track of the city is of the length of the city, the lenght
of the tracks decrease by 2 for every parallel track away from the center
of the tracks decrease by 2 for every parallel track away from the center
...
...
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