-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy patha_star_finder.py
31 lines (20 loc) · 1013 Bytes
/
a_star_finder.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# -*- coding: utf-8 -*-
from funcy import first
from models import PathNode
from models import PathSpace
from pathfinding.path_finder import PathFinder
class AStarFinder(PathFinder):
def __init__(self, path_space: PathSpace) -> None:
super().__init__(path_space)
from_node = self._path_space.from_node
peer_node = first(from_node.get_peers())
connecting_edge = from_node.get_edge_to_(peer_node)
delta = self.get_air_distance(from_node, peer_node)
self.k = connecting_edge.cost * .5 / delta
def calculate_cost(self, pair_from: PathNode, pair_to: PathNode) -> float:
to_node = self._path_space.to_node
air_distance_from = self.get_air_distance(pair_from, to_node)
air_distance_to = self.get_air_distance(pair_to, to_node)
air_distance_delta = self.k * (air_distance_to - air_distance_from)
travel_cost = pair_from.get_cost_to_(pair_to)
return float(pair_from.cost + travel_cost + air_distance_delta)