fix: resolve comparing object with list; add fringe_state
This commit is contained in:
parent
d2f973307f
commit
3a8a7fdb14
@ -29,6 +29,7 @@ class Search:
|
|||||||
angle = istate[2]
|
angle = istate[2]
|
||||||
|
|
||||||
fringe = [Node([x, y, angle])] # queue (moves/states to check)
|
fringe = [Node([x, y, angle])] # queue (moves/states to check)
|
||||||
|
fringe_state = [fringe[0].state]
|
||||||
explored = []
|
explored = []
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
@ -36,13 +37,13 @@ class Search:
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
elem = fringe.pop(0)
|
elem = fringe.pop(0)
|
||||||
|
fringe_state.pop(0)
|
||||||
|
|
||||||
# if goal_test(elem.state):
|
# if goal_test(elem.state):
|
||||||
# return
|
# return
|
||||||
# print(elem.state[0], elem.state[1], elem.state[2])
|
# 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
|
if elem.state[0] == goaltest[0] and elem.state[1] == goaltest[1]: # checks if we reached the given point
|
||||||
steps = []
|
steps = []
|
||||||
|
|
||||||
while elem.parent != '':
|
while elem.parent != '':
|
||||||
steps.append([elem.action, elem.state[0], elem.state[1]]) # should return only elem.action in prod
|
steps.append([elem.action, elem.state[0], elem.state[1]]) # should return only elem.action in prod
|
||||||
elem = elem.parent
|
elem = elem.parent
|
||||||
@ -51,17 +52,19 @@ class Search:
|
|||||||
print(steps) # only for dev
|
print(steps) # only for dev
|
||||||
return steps
|
return steps
|
||||||
|
|
||||||
explored.append(elem)
|
explored.append(elem.state)
|
||||||
|
|
||||||
for (action, state_x, state_y, state_angle) in self.succ(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
|
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 = Node([state_x, state_y, state_angle])
|
||||||
x.parent = elem
|
x.parent = elem
|
||||||
x.action = action
|
x.action = action
|
||||||
fringe.append(x)
|
fringe.append(x)
|
||||||
|
fringe_state.append(x.state)
|
||||||
|
|
||||||
|
|
||||||
se = Search(50)
|
se = Search(50)
|
||||||
se.graphsearch(istate=[50, 50, 0], goaltest=[250, 100])
|
se.graphsearch(istate=[50, 50, 0], goaltest=[150, 250])
|
||||||
|
Loading…
Reference in New Issue
Block a user