changed A*

This commit is contained in:
s481872 2024-04-27 22:59:39 +02:00
parent a1e68006b4
commit 52ede8588c
2 changed files with 10 additions and 1 deletions

View File

@ -280,6 +280,7 @@ class Garbagetruck:
temp = self.getPosition()[:] temp = self.getPosition()[:]
temp.append(self.getOrientation()) temp.append(self.getOrientation())
initial = Node(temp) initial = Node(temp)
initial.setCost(0)
fringe.append((0, initial)) # (priority, node) fringe.append((0, initial)) # (priority, node)
while True: while True:
@ -309,7 +310,8 @@ class Garbagetruck:
x = Node(wynik["result"]) x = Node(wynik["result"])
x.setParent(elem) x.setParent(elem)
x.setAction(wynik["action"]) 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)) heapq.heappush(fringe, (priority, x))
def executeMovement(self): def executeMovement(self):

View File

@ -3,6 +3,7 @@ class Node:
self.state = state self.state = state
self.action = "" self.action = ""
self.parent: Node = None self.parent: Node = None
self.cost = 0
def getState(self): def getState(self):
return self.state return self.state
@ -21,5 +22,11 @@ class Node:
self.parent = parent self.parent = parent
return self return self
def getCost(self):
return self.cost
def setCost(self, cost):
self.cost = cost
def __lt__(self, other): def __lt__(self, other):
return self.getState() < other.getState() return self.getState() < other.getState()