public void RemoveNode(IGraphNode node) { if (node.Equals(Activity.Start) || node.Equals(Activity.End)) { return; } foreach (IGraphEdge edge in node.GetRegisteredConnections()) { RemoveEdge(edge); } while (nodes.Remove(node)) { ; } node.Destroy(); Analyze(); }
private bool PathExists(IGraph graph, Dictionary <IGraphNode, IMaybe <IGraphNode> > previousNodeFor) { if (!graph.IsEmpty()) { IGraphNode finish = graph.Finish(); return(previousNodeFor[finish].HasValue() || finish.Equals(graph.Start())); } return(false); }
public Connection(IGraphNode start, IGraphNode end) { if (start.Equals(Activity.End)) { throw new Exception("Forbidden: END node cannot be connection's start node."); } if (end.Equals(Activity.Start)) { throw new Exception("Forbidden: START node cannot be connection's end node."); } Validate(start, end); startNode = start; start.RegisterConnection(this); endNode = end; end.RegisterConnection(this); }
private void Validate(IGraphNode controlNode, IGraphNode validatedNode) { if (controlNode.Equals(validatedNode)) { throw new Exception("Forbidden: Creating such a connection would result in a cycle"); } else { foreach (IGraphEdge edge in validatedNode.GetRegisteredConnections()) { if (edge.GetStartNode().Equals(validatedNode)) { Validate(controlNode, edge.GetEndNode()); } } } }
private void CalcIDoms() { OrderNodes(); List <IGraphNode> lstNodes = colOrderedIDoms.GetLstKeys(); while (true) { bool changed = false; foreach (IGraphNode node in lstNodes) { IGraphNode idom = null; if (!setRoots.Contains(node)) { foreach (var pred in node.GetPredecessors()) { if (colOrderedIDoms.GetWithKey(pred) != null) { idom = GetCommonIDom(idom, pred, colOrderedIDoms); if (idom == null) { break; } } } } // no idom found: merging point of two trees if (idom == null) { idom = node; } IGraphNode oldidom = colOrderedIDoms.PutWithKey(idom, node); if (!idom.Equals(oldidom)) { // oldidom is null iff the node is touched for the first time changed = true; } } if (!changed) { break; } } }
public virtual bool IsDominator(IGraphNode node, IGraphNode dom) { while (!node.Equals(dom)) { IGraphNode idom = colOrderedIDoms.GetWithKey(node); if (idom == node) { return(false); } else if (idom == null) { // root node or merging point throw new Exception("Inconsistent idom sequence discovered!"); } else { node = idom; } } return(true); }