python - BFS and UCS algorithms. My BFS implementation works but my UCS doesn't. Can't figure out why -
as long not mistaken, ucs same bfs difference instead of expanding shallowest node, expands node lowest path cost. (also using priorityqueue instead of queue that)so copied bfs code, created map keep track of each node's path cost , changed way items being pushed/popped in queue/priority queue. note: getsuccessors(state) returns list of triples (state, action, cost) these both of implementations: bfs: def breadthfirstsearch(problem): """search shallowest nodes in search tree first.""" queue=queue() objectqueue=queue() visited=set() actions=[] flag=0 objectmap={} actionmap={} start=problem.getstartstate() objectmap[start]=start queue.push(start) objectqueue.push(start) if problem.isgoalstate(start): return actions while queue: parent=queue.pop() object=objectqueue.pop() if parent in visited: continue visited.add(parent) if problem.isgoalst...