我需要为欧拉路径设置动画。我在任何给定的图形上都有用于随机游走的代码,但是我无法制定出代表我想要的特定游走的程序。
这是我随机行走的代码
Cammino[g_] =
Block[{graph = g, start, path},
start = RandomChoice[VertexList[graph]];
path = NestList[RandomChoice[AdjacencyList[graph, #]] &, start,
RandomInteger[{2, 30}]];
ListAnimate[
Table[Graph[graph,
VertexStyle ->
Append[Map[Rule[#, Pink] &, Union[path[[1 ;; v]]]],
path[[v]] -> Red],
EdgeStyle ->
Evaluate[(UndirectedEdge[#1, #2] -> Directive[Red, Thick]) & @@@
Partition[path[[1 ;; v]], 2, 1]], VertexSize -> Large], {v,
Length[path]}]]]
这是我对欧拉循环的尝试
Euleriano[g_] =
Block[{grafo = g, inizio, cammino},
inizio = FindEulerianCycle[grafo][[1]][[1]][[1]];
cammino =
NestList[RandomChoice[AdjacencyList[grafo, #]] &, inizio,
RandomInteger[{2, 30}]];
ListAnimate[
Table[Graph[grafo,
VertexStyle ->
Append[Map[Rule[#, Pink] &, Union[cammino[[1 ;; v]]]],
cammino[[v]] -> Red],
EdgeStyle ->
Evaluate[(UndirectedEdge[#1, #2] -> Directive[Red, Thick]) & @@@
Partition[cammino[[1 ;; v]], 2, 1]],
VertexSize -> Large], {v, Length[cammino]}]]]
为澄清起见,cammino = walk,inizio = start,grafo = graph。 我认为我必须在第二段代码中更改“ cammino”的定义,以使步伐遵循使用Mathematica函数FindEulerianCycle []获得的步伐。我的问题是我该怎么做。