我正在尝试通过有向 networkx 图模拟随机遍历。伪代码如下
Create graph G with nodes holding the value true or false.
// true -> visited, false -> not visited
pick random node N from G
save N.successors as templist
while true
nooptions = false
pick random node N from templist
while N from templist has been visited
remove N from templist
pick random node N from templist
if templist is empty
nooptions = true
break
if nooptions = true
break
save N.successors as templist
除了创建临时列表并删除元素(如果它们被标记为已访问)之外,是否有更有效的方法将路径标记为已行驶?
编辑
该算法的目标是在图中随机选择一个节点。选择该节点的随机后继/子节点。如果它未被访问,请到那里并将其标记为已访问。重复直到没有继任者/孩子或没有未访问的继任者/孩子