Menu

[solved]-Class Node Def Init Self State Cost Totalcost H Fvalues X Y Px Py Selfstate State Selfcost Q39020234

class Node: def __init__(self, state, cost, total_cost,h, f_values, x, y,px,py): self.state = state self.cost = cost self.total_cost = total_cost self.f_values = f_values self.x = x self.y = y self.px=px self.py=py self.h=h self.next = Noneclass PriorityQueue: def __init__(self): self.front = self.rear = None # Returns a boolean value indicating whether the queue is empty def isEmpty(self): return self.front == None # Adds the given item to the queue by inserting it in the proper # position based on the given priority. The new node is appended to # the end of the linked list def enqueue(self, state, cost, total_cost, h, f_values, x, y, bx, by): newNode = Node(state, cost, total_cost, h, f_values, x, y, bx, by) if not self.rear: self.front = self.rear = newNode return if self.front.f_values > newNode.f_values: newNode.next = self.front self.front = newNode return if self.front.f_values == newNode.f_values: #inserted at begginning if it is farthest away from start if self.front.total_cost < newNode.total_cost and self.front.h > newNode.h: print(‘settling besed off of g value and h value’) newNode.next = self.front self.front = newNode if self.front.total_cost < newNode.total_cost or self.front.h > newNode.h: print(‘settling tie’) newNode.next = self.front self.front = newNode newNode.next = self.front self.front = newNode return previous = None current = self.front while (current and newNode.f_values > current.f_values): previous = current current = current.next if current: previous.next = newNode newNode.next = current else: self.rear.next = newNode self.rear = newNode # Removes and returns the next item from the queue, which is the # item with the lowest priority. def dequeue(self): if self.isEmpty(): print(‘Queue is empty’) return temp = self.front self.front = self.front.next if self.front == None: self.rear = None return temp.x, temp.y, temp.f_values, temp.total_cost, temp.h def delete_open_list(self, x,y): # Store head node temp = self.front # If head node itself holds the key to be deleted if (temp is not None): if temp.x == x and temp.y == y: self.front = temp.next temp = None return # Search for the key to be deleted, keep track of the # previous node as we need to change ‘prev.next’ while (temp is not None): if temp.x == x and temp.y ==y: break prev = temp temp = temp.next # if key was not present in linked list if (temp == None): return # Unlink the node from linked list prev.next = temp.next temp = None

I am trying to implement a delete function in mypriority queue in PYTHON its not working correctly its thedelete_open_list function

Expert Answer


Answer to class Node: def __init__(self, state, cost, total_cost,h, f_values, x, y,px,py): self.state = state self.cost = cost se… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *