How to identify if a set of nodes are circularly linked.
For example, let us take four NODES A,B,C,D
If A is linked to B and
B is linked to C and
C is linked to D and
D is linked A, as below,
-------> A -> B -> C -> D –
If i have a reference to node B and want to check whether there is a circular link or not, how to do it ?
You’ll need to traverse the graph and see if you can find a path that comes back to B (or whereever you started) again. The User Guide has examples of how to traverse graphs.
If you want to prevent users from drawing links that would result in cycles, you can just set GoDocument.ValidCycle to GoDocumentValidCycle.NotDirected. You might want to check the other values of that enum too.
If you are wondering if you could use GoDocument.MakesDirectedCycle, I believe you can’t, since it just tries to see if adding a link would create a cycle, not whether there is one already.