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
ac00c08e
Commit
ac00c08e
authored
5 years ago
by
Egli Adrian (IT-SCI-API-PFI)
Browse files
Options
Downloads
Patches
Plain Diff
chebyshev distance added
parent
7315db8e
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
examples/simple_example_city_railway_generator.py
+6
-3
6 additions, 3 deletions
examples/simple_example_city_railway_generator.py
flatland/core/grid/grid_utils.py
+16
-0
16 additions, 0 deletions
flatland/core/grid/grid_utils.py
with
22 additions
and
3 deletions
examples/simple_example_city_railway_generator.py
+
6
−
3
View file @
ac00c08e
...
...
@@ -17,9 +17,12 @@ if os.path.exists("./../render_output/"):
np
.
random
.
seed
(
itrials
)
# select distance function used in a-star path finding
dist_fun
=
Vec2d
.
get_euclidean_distance
if
np
.
random
.
choice
(
1
)
==
0
:
dist_fun
=
Vec2d
.
get_manhattan_distance
dist_fun
=
Vec2d
.
get_manhattan_distance
dfsel
=
itrials
%
3
if
dfsel
==
1
:
dist_fun
=
Vec2d
.
get_euclidean_distance
elif
dfsel
==
2
:
dist_fun
=
Vec2d
.
get_chebyshev_distance
# create RailEnv and use the city_generator to create a map
env
=
RailEnv
(
width
=
40
+
np
.
random
.
choice
(
100
),
...
...
This diff is collapsed.
Click to expand it.
flatland/core/grid/grid_utils.py
+
16
−
0
View file @
ac00c08e
...
...
@@ -71,6 +71,7 @@ class Vec2dOperations:
def
get_norm
(
node
:
Vector2D
)
->
float
:
"""
calculates the euclidean norm of the 2d vector
[see: https://lyfat.wordpress.com/2012/05/22/euclidean-vs-chebyshev-vs-manhattan-distance/]
:param node: tuple with coordinate (x,y) or 2d vector
:return:
...
...
@@ -95,6 +96,7 @@ class Vec2dOperations:
def
get_manhattan_distance
(
node_a
:
Vector2D
,
node_b
:
Vector2D
)
->
float
:
"""
calculates the manhattan distance of the 2d vector
[see: https://lyfat.wordpress.com/2012/05/22/euclidean-vs-chebyshev-vs-manhattan-distance/]
:param node: tuple with coordinate (x,y) or 2d vector
:return:
...
...
@@ -104,6 +106,20 @@ class Vec2dOperations:
delta
=
(
Vec2dOperations
.
subtract
(
node_b
,
node_a
))
return
np
.
abs
(
delta
[
0
])
+
np
.
abs
(
delta
[
1
])
@staticmethod
def
get_chebyshev_distance
(
node_a
:
Vector2D
,
node_b
:
Vector2D
)
->
float
:
"""
calculates the chebyshev norm of the 2d vector
[see: https://lyfat.wordpress.com/2012/05/22/euclidean-vs-chebyshev-vs-manhattan-distance/]
:param node: tuple with coordinate (x,y) or 2d vector
:return:
-------
returns the chebyshev distance
"""
delta
=
(
Vec2dOperations
.
subtract
(
node_b
,
node_a
))
return
max
(
np
.
abs
(
delta
[
0
]),
np
.
abs
(
delta
[
1
]))
@staticmethod
def
normalize
(
node
:
Vector2D
)
->
Tuple
[
float
,
float
]:
"""
...
...
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