From 3a8a7fdb14faf6574773872636e191e754afd772 Mon Sep 17 00:00:00 2001 From: mikoMaz Date: Sun, 16 Apr 2023 18:42:56 +0200 Subject: [PATCH] fix: resolve comparing object with list; add fringe_state --- graph_search.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/graph_search.py b/graph_search.py index 0c149529..14638220 100644 --- a/graph_search.py +++ b/graph_search.py @@ -29,6 +29,7 @@ class Search: angle = istate[2] fringe = [Node([x, y, angle])] # queue (moves/states to check) + fringe_state = [fringe[0].state] explored = [] while True: @@ -36,13 +37,13 @@ class Search: return False elem = fringe.pop(0) + fringe_state.pop(0) # if goal_test(elem.state): # return # print(elem.state[0], elem.state[1], elem.state[2]) if elem.state[0] == goaltest[0] and elem.state[1] == goaltest[1]: # checks if we reached the given point steps = [] - while elem.parent != '': steps.append([elem.action, elem.state[0], elem.state[1]]) # should return only elem.action in prod elem = elem.parent @@ -51,17 +52,19 @@ class Search: print(steps) # only for dev return steps - explored.append(elem) + explored.append(elem.state) for (action, state_x, state_y, state_angle) in self.succ(elem.state): - if state_x < 0 or state_y < 0: # check if any of the values is negative + if state_x < 0 or state_y < 0: # check if any of the values are negative continue - if [state_x, state_y, state_angle] not in fringe and [state_x, state_y, state_angle] not in explored: + if [state_x, state_y, state_angle] not in fringe_state and \ + [state_x, state_y, state_angle] not in explored: x = Node([state_x, state_y, state_angle]) x.parent = elem x.action = action fringe.append(x) + fringe_state.append(x.state) se = Search(50) -se.graphsearch(istate=[50, 50, 0], goaltest=[250, 100]) +se.graphsearch(istate=[50, 50, 0], goaltest=[150, 250])