My graph is
g = Graph[{1 <-> 2, 2 <-> 3, 3 <-> 4, 4 <-> 5, 5 <-> 6, 6 <-> 7,
7 <-> 0, 0 <-> 1, 6 <-> 8, 8 <-> 3, 3 <-> 9, 9 <-> 15, 15 <-> 14,
14 <-> 13, 13 <-> 2, 4 <-> 12, 12 <-> 11, 11 <-> 10, 10 <-> 9},
VertexLabels -> "Name"]
HighlightGraph[g, #, GraphHighlightStyle -> "Thick"] & /@
FindFundamentalCycles[g]
But actually this four cycle is expected.How can I get it?
This a bug of FindFundamentalCycles
or I have a bad comprehension about it?
Updat1:
I find a post same to me topic.But this solution will give a unexpected result.
Update2: I realize this is a unanswerable.Let's see a example:
We get g1
:
g1 = PlanarGraph[{2, 1, 3, 5, 4}, {1 <-> 2, 2 <-> 5, 5 <-> 4, 4 <-> 1,
1 <-> 3, 3 <-> 5},
VertexCoordinates -> {{0, 0}, {1, 0}, {1, 1}, {1, 2}, {2, 0}},
VertexLabels -> "Name"]
So as this topic.The cycle 1-2-5-3-1 and 1-4-5-3-1 is expected.And let change a layout:
g2 = PlanarGraph[{4, 1, 2, 5, 3}, {1 <-> 2, 2 <-> 5, 5 <-> 4, 4 <-> 1,
1 <-> 3, 3 <-> 5},
VertexCoordinates -> {{0, 0}, {1, 0}, {1, 1}, {1, 2}, {2, 0}},
VertexLabels -> "Name"]
In this layout,the cycle 1-2-5-4-1 and 1-3-5-2-1 is expected.Note the cylce 1-4-5-3-1 in this graph,is a Unexpected in this layout.But I just change the layout..
Since so,let we try to understand what is a fundamental cycles(cycle basis).The @Martin Büttner have a mention about this.Yeah.I think so now.This is a manual operation for the fundamental cycles by the FindSpanningTree
.
tree = FindSpanningTree[g];
edge = EdgeList@GraphDifference[g, tree];
HighlightGraph[g, FindCycle[EdgeAdd[tree, #]],
GraphHighlightStyle -> "Thick"] & /@ edge
We can see,this result is same to we use FindFundamentalCycles[]
and this rule apply to other graph.