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
41c723ff
Commit
41c723ff
authored
5 years ago
by
u229589
Browse files
Options
Downloads
Patches
Plain Diff
remove quick_path
parent
5c71f961
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
flatland/core/grid/grid4_utils.py
+0
-28
0 additions, 28 deletions
flatland/core/grid/grid4_utils.py
flatland/envs/grid4_generators_utils.py
+1
-60
1 addition, 60 deletions
flatland/envs/grid4_generators_utils.py
with
1 addition
and
88 deletions
flatland/core/grid/grid4_utils.py
+
0
−
28
View file @
41c723ff
...
...
@@ -58,31 +58,3 @@ def direction_to_point(pos1: IntVector2D, pos2: IntVector2D) -> Grid4Transitions
return
Grid4TransitionsEnum
.
WEST
else
:
return
Grid4TransitionsEnum
.
EAST
def
directions_of_vector
(
pos1
:
IntVector2D
,
pos2
:
IntVector2D
)
->
(
Grid4TransitionsEnum
,
Grid4TransitionsEnum
):
diff_vec
=
np
.
array
((
pos1
[
0
]
-
pos2
[
0
],
pos1
[
1
]
-
pos2
[
1
]))
axis
=
np
.
argmax
(
np
.
power
(
diff_vec
,
2
))
direction
=
np
.
sign
(
diff_vec
)
if
axis
==
0
:
if
direction
[
0
]
>
0
:
if
direction
[
1
]
>
0
:
return
Grid4TransitionsEnum
.
NORTH
,
Grid4TransitionsEnum
.
WEST
else
:
return
Grid4TransitionsEnum
.
NORTH
,
Grid4TransitionsEnum
.
EAST
else
:
if
direction
[
1
]
>
0
:
return
Grid4TransitionsEnum
.
SOUTH
,
Grid4TransitionsEnum
.
WEST
else
:
return
Grid4TransitionsEnum
.
SOUTH
,
Grid4TransitionsEnum
.
EAST
else
:
if
direction
[
1
]
>
0
:
if
direction
[
0
]
>
0
:
return
Grid4TransitionsEnum
.
WEST
,
Grid4TransitionsEnum
.
NORTH
else
:
return
Grid4TransitionsEnum
.
WEST
,
Grid4TransitionsEnum
.
SOUTH
else
:
if
direction
[
0
]
>
0
:
return
Grid4TransitionsEnum
.
EAST
,
Grid4TransitionsEnum
.
NORTH
else
:
return
Grid4TransitionsEnum
.
EAST
,
Grid4TransitionsEnum
.
SOUTH
This diff is collapsed.
Click to expand it.
flatland/envs/grid4_generators_utils.py
+
1
−
60
View file @
41c723ff
...
...
@@ -9,8 +9,7 @@ import numpy as np
from
flatland.core.grid.grid4
import
Grid4TransitionsEnum
from
flatland.core.grid.grid4_astar
import
a_star
from
flatland.core.grid.grid4_utils
import
get_direction
,
mirror
,
get_new_position
,
directions_of_vector
,
\
direction_to_point
from
flatland.core.grid.grid4_utils
import
get_direction
,
mirror
,
direction_to_point
from
flatland.core.grid.grid_utils
import
IntVector2D
,
IntVector2DDistance
,
IntVector2DArray
from
flatland.core.grid.grid_utils
import
Vec2dOperations
as
Vec2d
from
flatland.core.transition_map
import
GridTransitionMap
,
RailEnvTransitions
...
...
@@ -38,7 +37,6 @@ def connect_rail_in_grid_map(grid_map: GridTransitionMap, start: IntVector2D, en
path
:
IntVector2DArray
=
a_star
(
grid_map
,
start
,
end
,
a_star_distance_function
,
respect_transition_validity
,
forbidden_cells
)
# path: IntVector2DArray = quick_path(grid_map, start, end, forbidden_cells=forbidden_cells)
if
len
(
path
)
<
2
:
print
(
"
No path found
"
,
path
)
return
[]
...
...
@@ -128,60 +126,3 @@ def connect_straight_line_in_grid_map(grid_map: GridTransitionMap, start: IntVec
grid_map
.
grid
[
cell
]
=
transition
return
path
def
quick_path
(
grid_map
:
GridTransitionMap
,
start
:
IntVector2D
,
end
:
IntVector2D
,
forbidden_cells
:
IntVector2DArray
=
None
)
->
IntVector2DArray
:
"""
Quick path connecting algorithm with simple heuristic to always follow largest value of vector towards target.
When obstacle is encountered second direction of vector is chosen.
"""
(
height
,
width
)
=
np
.
shape
(
grid_map
.
grid
)
def
_next_legal_step
(
position
,
old_direction
,
target
):
if
old_direction
is
not
None
:
mirror_direction
=
Grid4TransitionsEnum
(
mirror
(
old_direction
))
else
:
mirror_direction
=
4
closest_direction
,
second_closest_direction
=
directions_of_vector
(
current_cell
,
target
)
if
closest_direction
==
mirror_direction
:
closest_direction
=
second_closest_direction
next_position
=
get_new_position
(
position
,
closest_direction
)
direction_tries
=
1
# Necessary to overcome city boarder
if
next_position
==
target
:
return
next_position
,
closest_direction
while
(
not
np
.
array_equal
(
next_position
,
np
.
clip
(
next_position
,
[
0
,
0
],
[
height
-
1
,
width
-
1
]))
or
(
forbidden_cells
is
not
None
and
next_position
in
forbidden_cells
)):
if
direction_tries
>
1
:
closest_direction
=
(
closest_direction
+
1
)
%
4
if
closest_direction
==
mirror_direction
:
closest_direction
=
(
closest_direction
+
1
)
%
4
if
direction_tries
>
3
:
return
None
,
None
else
:
closest_direction
=
second_closest_direction
if
closest_direction
==
mirror_direction
:
closest_direction
=
(
closest_direction
+
1
)
%
4
next_position
=
get_new_position
(
position
,
closest_direction
)
direction_tries
+=
1
return
next_position
,
closest_direction
current_cell
=
start
path
=
[
current_cell
]
current_direction
=
None
while
current_cell
!=
end
:
current_cell
,
current_direction
=
_next_legal_step
(
current_cell
,
current_direction
,
end
)
if
current_cell
is
not
None
:
path
.
append
(
current_cell
)
return
path
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