python实现 深度优先算法
来源:互联网 发布:北京哪里体检好 知乎 编辑:程序博客网 时间:2024/06/05 06:47
python 小程序,实现简单的dfs算法
from game import Directions
from util import Stack
stack = Stack()
fatherStack = Stack()
moveDir = [] # record the pacman move direction
result = [] # the correct lines
temp = {}
startState = problem.getStartState() # start the position
moveStart = [startState, Directions.STOP, 0]
stack.push(moveStart)
fatherStack.push(moveStart)
flag = False
while True:
if stack.isEmpty():
print "can not find food"
if flag==False:
movement = stack.pop()
fatherNode = fatherStack.pop()
else:
fatherNode = fatherStack.pop()
movement = stack.pop()
while True:
temp = moveDir.pop()
if temp == fatherNode:
moveDir.append(temp)
break
if problem.isGoalState(movement[0]):
moveDir.append(movement)
for each in moveDir:
result.append(each[1])
return result[1:]
moveDir.append(movement)
nextMovements = problem.getSuccessors(movement[0])
if nextMovements != None:
for i in nextMovements:
print i
if i[0] not in problem._visitedlist:
fatherStack.push(movement)
stack.push(i)
else:
flag = True
- python实现 深度优先算法
- 深度优先算法生成迷宫——Python实现
- 深度优先算法实现代码
- java实现深度优先算法
- python算法-深度优先搜索算法
- python深度优先与广度优先的遍历算法比较
- Python实现文件夹深度优先遍历
- 深度、广度优先遍历算法C实现
- 深度优先遍历算法--非递归实现
- 深度、广度优先遍历算法C实现
- 图的遍历之深度优先搜索算法&&广度优先优先算法的实现
- Python 深度优先
- 深度优先搜索算法
- 深度优先搜索算法
- 深度优先算法
- 深度优先搜索算法
- 深度优先搜索算法
- 深度优先搜索算法
- Linux+Apache+PHP+MYSQL环境配置学习笔记
- Linux实现函数和全局变量的#ifdef功能
- oracle数据操作
- MFC 基础(实例)
- windows mobile的3G连接,自动拨号问题?
- python实现 深度优先算法
- SEO真谛:转化率才是王道
- 关于延时打印的问题
- a星算法
- 开源的android项目
- DLNA说:以后不再需要路由器了
- PHP文件操作
- Smarty缓存的学习
- aspxgridview.selection.count问题