bfs_implementation #10
35
src/bfs.py
35
src/bfs.py
@ -42,7 +42,7 @@ class BFS:
|
|||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def tempfunc(self, elem):
|
def goal_path(self, elem):
|
||||||
path = []
|
path = []
|
||||||
|
|
||||||
while elem.parent:
|
while elem.parent:
|
||||||
@ -53,34 +53,23 @@ class BFS:
|
|||||||
return path
|
return path
|
||||||
|
|
||||||
def search(self, istate, goaltest):
|
def search(self, istate, goaltest):
|
||||||
node = Node([istate[0], istate[1], istate[2]])
|
x, y, rotation = istate
|
||||||
fringe = []
|
start_node = Node((x, y, rotation))
|
||||||
fringe.append(node)
|
|
||||||
fringe_states = [fringe[0].state]
|
|
||||||
|
|
||||||
#fringe_state = [fringe[0].state]
|
self.fringe.append(start_node)
|
||||||
#visited = []
|
|
||||||
explored_states = []
|
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
if not fringe:
|
if len(self.fringe) == 0:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
elem = fringe.pop(0)
|
elem = self.fringe.pop(0)
|
||||||
temp = copy.copy(elem)
|
|
||||||
fringe_states.pop(0)
|
|
||||||
|
|
||||||
# DESTINATION
|
|
||||||
if elem.state[0] == goaltest[0] and elem.state[1] == goaltest[1]:
|
if elem.state[0] == goaltest[0] and elem.state[1] == goaltest[1]:
|
||||||
return self.tempfunc(elem)
|
return self.goal_path(elem)
|
||||||
|
|
||||||
explored_states.append(elem.state) #elem.state(?)
|
self.explored.append(elem.state)
|
||||||
|
|
||||||
for (action, state) in self.successor(temp):
|
for (action, state) in self.successor(elem.state):
|
||||||
print
|
if state not in self.explored:
|
||||||
if (state not in fringe_states) and (state not in explored_states):
|
x = Node(state, elem, action)
|
||||||
x = Node([state[0][0], state[1], state[2]])
|
self.fringe.append(x)
|
||||||
x.parent = elem
|
|
||||||
x.action = action
|
|
||||||
fringe.append(x)
|
|
||||||
fringe_states.append(x.state)
|
|
Loading…
Reference in New Issue
Block a user