Skip to content
Snippets Groups Projects
Commit ac00c08e authored by Egli Adrian (IT-SCI-API-PFI)'s avatar Egli Adrian (IT-SCI-API-PFI)
Browse files

chebyshev distance added

parent 7315db8e
No related branches found
No related tags found
No related merge requests found
......@@ -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),
......
......@@ -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]:
"""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment