public static IEnumerable <int> GetExitNodes(this IGraph graph) { for (int i = 0; i < graph.NodeCount; i++) { if (!graph.IsNodeActive(i) || graph.Children(i).Count != 0) { continue; } yield return(i); } }
public static int GetExitNode(this IGraph graph) { // Should be the only node with outdegree 0 int result = -1; for (int i = 0; i < graph.NodeCount; i++) { if (!graph.IsNodeActive(i) || graph.Children(i).Count != 0) { continue; } if (result != -1) { throw new ControlFlowGraphException("Multiple exit nodes were found in graph!", graph); } result = i; // return result; } return(result); }
public static int OutDegree(this IGraph graph, int node) => graph.Children(node).Count;