private static IEnumerable<DirectedEdge> FindSequence(Subgraph graph) { GraphComponent.SetVisited(graph.GetEdgeEnumerator(), false); var startNode = FindLowestDegreeNode(graph); var list = startNode.OutEdges.Edges; var ie = list.GetEnumerator(); ie.MoveNext(); var startDE = ie.Current; var startDESym = startDE.Sym; var seq = new LinkedList<DirectedEdge>(); var pos = AddReverseSubpath(startDESym, null, seq, false); while (pos != null) { DirectedEdge prev = pos.Value; DirectedEdge unvisitedOutDE = FindUnvisitedBestOrientedDE(prev.FromNode); if (unvisitedOutDE != null) { DirectedEdge toInsert = unvisitedOutDE.Sym; pos = AddReverseSubpath(toInsert, pos, seq, true); } else pos = pos.Previous; } /* * At this point, we have a valid sequence of graph DirectedEdges, but it * is not necessarily appropriately oriented relative to the underlying geometry. */ return Orient(seq/*new ArrayList(seq.CastPlatform())*/); }
private static Node FindLowestDegreeNode(Subgraph graph) { int minDegree = Int32.MaxValue; Node minDegreeNode = null; IEnumerator<Node> i = graph.GetNodeEnumerator(); while (i.MoveNext()) { Node node = i.Current; if (minDegreeNode == null || node.Degree < minDegree) { minDegree = node.Degree; minDegreeNode = node; } } return minDegreeNode; }
/// <summary> /// Tests whether a complete unique path exists in a graph /// using Euler's Theorem. /// </summary> /// <param name="graph">The <see cref="Subgraph" /> containing the edges.</param> /// <returns><c>true</c> if a sequence exists.</returns> private static bool HasSequence(Subgraph graph) { int oddDegreeCount = 0; IEnumerator i = graph.GetNodeEnumerator(); while(i.MoveNext()) { Node node = (Node) i.Current; if (node.Degree % 2 == 1) oddDegreeCount++; } return oddDegreeCount <= 2; }