MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / calculate_heuristic

Method calculate_heuristic

graphs/greedy_best_first.py:74–81  ·  view source on GitHub ↗

The heuristic here is the Manhattan Distance Could elaborate to offer more than one choice

(self)

Source from the content-addressed store, hash-verified

72 self.f_cost = self.calculate_heuristic()
73
74 def calculate_heuristic(self) -> float:
75 """
76 The heuristic here is the Manhattan Distance
77 Could elaborate to offer more than one choice
78 """
79 dx = abs(self.pos_x - self.goal_x)
80 dy = abs(self.pos_y - self.goal_y)
81 return dx + dy
82
83 def __lt__(self, other) -> bool:
84 return self.f_cost < other.f_cost

Callers 1

__init__Method · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected