From 52ede8588cc428f587c03a3493ea57ff27e2e860 Mon Sep 17 00:00:00 2001 From: s481872 Date: Sat, 27 Apr 2024 22:59:39 +0200 Subject: [PATCH] changed A* --- classes/Garbagetruck.py | 4 +++- classes/Node.py | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/classes/Garbagetruck.py b/classes/Garbagetruck.py index 35ac6e0..d9821cb 100644 --- a/classes/Garbagetruck.py +++ b/classes/Garbagetruck.py @@ -280,6 +280,7 @@ class Garbagetruck: temp = self.getPosition()[:] temp.append(self.getOrientation()) initial = Node(temp) + initial.setCost(0) fringe.append((0, initial)) # (priority, node) while True: @@ -309,7 +310,8 @@ class Garbagetruck: x = Node(wynik["result"]) x.setParent(elem) x.setAction(wynik["action"]) - priority = cost(x.getState()) + heuristic(x.getState()) + x.setCost(elem.getCost() + cost(x.getState())) + priority = x.getCost() + heuristic(x.getState()) heapq.heappush(fringe, (priority, x)) def executeMovement(self): diff --git a/classes/Node.py b/classes/Node.py index 0ec3034..75c4ff1 100644 --- a/classes/Node.py +++ b/classes/Node.py @@ -3,6 +3,7 @@ class Node: self.state = state self.action = "" self.parent: Node = None + self.cost = 0 def getState(self): return self.state @@ -21,5 +22,11 @@ class Node: self.parent = parent return self + def getCost(self): + return self.cost + + def setCost(self, cost): + self.cost = cost + def __lt__(self, other): return self.getState() < other.getState() \ No newline at end of file