graphlib
graphlib copied to clipboard
Incorrect behaviour in findCycles (unexistent edges)
I found a strange case where findeCycles
returns a wrong response.
This is what g.edges()
show:
[ { v: '3', w: '1' },
{ v: '9', w: '5' },
{ v: '8', w: '9' },
{ v: '18', w: '6' },
{ v: '19', w: '4' },
{ v: '19', w: '5' },
{ v: '21', w: '6' },
{ v: '21', w: '9' },
{ v: '23', w: '22' },
{ v: '23', w: '21' },
{ v: '23', w: '10' },
{ v: '18', w: '23' },
{ v: '18', w: '7' },
{ v: '27', w: '21' },
{ v: '27', w: '19' },
{ v: '27', w: '18' },
{ v: '5', w: '6' },
{ v: '5', w: '27' },
{ v: '49', w: '27' },
{ v: '4', w: '54' },
{ v: '3', w: '21' },
{ v: '4', w: '55' },
{ v: '55', w: '56' },
{ v: '53', w: '56' },
{ v: '54', w: '56' },
{ v: '52', w: '56' },
{ v: '50', w: '56' },
{ v: '51', w: '56' },
{ v: '3', w: '55' },
{ v: '35', w: '26' },
{ v: '1', w: '59' },
{ v: '2', w: '59' },
{ v: '2', w: '58' },
{ v: '1', w: '58' },
{ v: '1', w: '56' },
{ v: '2', w: '56' },
{ v: '59', w: '1' },
{ v: '58', w: '1' },
{ v: '35', w: '1' },
{ v: '57', w: '1' },
{ v: '56', w: '1' },
{ v: '1', w: '53' },
{ v: '2', w: '53' },
{ v: '58', w: '2' },
{ v: '59', w: '2' },
{ v: '57', w: '2' },
{ v: '56', w: '2' },
{ v: '35', w: '2' },
{ v: '3', w: '2' },
{ v: '1', w: '55' },
{ v: '2', w: '55' },
{ v: '59', w: '6' },
{ v: '58', w: '6' },
{ v: '57', w: '6' },
{ v: '56', w: '6' },
{ v: '35', w: '6' },
{ v: '3', w: '6' },
{ v: '2', w: '54' },
{ v: '1', w: '54' },
{ v: '59', w: '54' },
{ v: '3', w: '54' },
{ v: '58', w: '54' },
{ v: '57', w: '54' },
{ v: '56', w: '54' },
{ v: '35', w: '54' } ]
And this is what alg.findCycles(g)
returns:
[ [ '59', '58', '55', '54', '2', '56', '53', '1' ], [ '19', '23', '18', '27', '5', '9', '21' ] ]
As you can see, most of edges are fine compared to the cycles found, but by example, there is not a relation between '59' and '58'!
I am not sure why it is happening, but I will let this case here, maybe someone will found what is happening here.
@ErunamoJAZZ It seems to me that although 59
and 58
are not directly connected, they still form a cycle through their connections to 1
:
{ v: '1', w: '58' },
{ v: '58', w: '1' },
{ v: '1', w: '59' },
{ v: '59', w: '1' },
Please correct me if I'm wrong but I think the result is correct.
Nice, it is true that it could explain why the algorithm found that response, thank you antoinerg. But anyway, it is an unexpected behavior of what I understand for a cycle over a directed graph.
In this function I thought in a simple cycle or directed cycle, not in a circuit (following the terms used in wikipedia https://en.wikipedia.org/wiki/Cycle_(graph_theory) ).
So, even knowing why, it still being a wrong result for our usercase.