I don't understand why, but the GraphLayout style "CircularEmbedding" doesn't place the vertices/edges of a Hamiltonian cycle on the circle. Is there any way I can force it to do this? I haven't been able to find an answer online, so any help would be appreciated.

For reference, I'm trying to produce images of some cages where a Hamiltonian cycle is placed on the circle.

  • $\begingroup$ IGraphM might have a solution $\endgroup$ – user6014 Apr 11 at 17:14

As of Mathematica 11.3, GraphLayout -> "CircularEmbedding" will place the vertices around a circle in the same order as they appear in VertexList[graph].

Thus, you need to reorder the vertices according to the Hamiltonian cycle.


g = GraphData["DodecahedralGraph"];

 FindHamiltonianCycle[g][[1, All, 1]],
 GraphLayout -> "CircularEmbedding"

enter image description here

Now that 12.0 is out in the cloud, it is good to mention that 12.0 requires

GraphLayout -> {"CircularEmbedding", "OptimalOrder" -> False}

In 12.0, vertices are reordered by "CircularEmbedding" to obtain a nicer layout with fewer crossing edges. "OptimalOrder" -> False disabled this reordering so that we can use our own order (in this case the Hamiltonian cycle).

The IGraph/M way of doing it is the following, if you prefer it:

IGLayoutCircle@IGReorderVertices[FindHamiltonianCycle[g][[1, All, 1]], g]

enter image description here

IGReorderVertices will preserve graph properties (including styling) when reordering vertices.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.