I'm 赵一开, a developer.
人智作业中坑爹的手绘A搜索算法图的题目催生了这篇文章...
用Python的Pydot库。
import pydot
dot = pydot.Dot()
while True:
OPEN = sorted(OPEN, key=f)
if isGoal(OPEN[0])
break
for n in expand(OPEN[0]):
OPEN.append(n)
dot.add_edge(pydot.Edge(toStr(OPEN[0]), toStr(n)))
OPEN = OPEN[1:]
dot.write_png('out.png')
f为启发函数。
对于N=5,K=3的MC问题,画出来的图大概长这样(每个节点的意义为“(M, C, 方向, 深度), f”):
Unable to load comments, check your (GFW Free) Internet connectivity.