public void AddNode(Node node) { if (!IsExist(node)) { if (node.GetFragment() != this) node.SetFragment(this); m_NodeList.Add(node); m_bIsGraphDirty = true; } }
public void GetImmediatePredecessors(Node node, FRList<Node> immediatePres) { if (immediatePres == null) return; if (!IsExist(node)) return; UpdateNodeGraph(); m_Graph.GetImmediatePredecessors(node, immediatePres); }
// Return the existing vertex for the node. // If no, add a new vertex to graph. private GraphVertex GetVertex(Node node) { if(m_NodeGraphVertexMap.ContainsKey(node)) { GraphVertex vertex = m_NodeGraphVertexMap[node]; return vertex; // Return the existing one } // Create a new vertex for this node. GraphVertex newVertex = new GraphVertex(node); // Add it to the cache m_NodeGraphVertexMap.Add(node, newVertex); return newVertex; }
public bool IsNodeVertexValid(Node node) { GraphVertex vertex = null; if (m_NodeGraphVertexMap.ContainsKey(node)) vertex = m_NodeGraphVertexMap[node]; if (vertex == null) return false; return vertex.Valid(); }
public void InvalidatePredecessors(Node node) { GraphVertex thisVertex = null; if(m_NodeGraphVertexMap.ContainsKey(node)) thisVertex = m_NodeGraphVertexMap[node]; if (thisVertex == null) return; FRList<GraphVertex> ZeroPredecessorVertexList = new FRList<GraphVertex>(); while (true) { ZeroPredecessorVertexList.Clear(); foreach (GraphVertex curVertex in m_NodeGraphVertexMap.Values) { // Don't invalidate the input node vertex if (curVertex.Valid() && curVertex != thisVertex && curVertex.GetpredecessorCount() == 0) ZeroPredecessorVertexList.Add(curVertex); } // There is no zero degree vertex. if (ZeroPredecessorVertexList.Count == 0) break; foreach (GraphVertex vertex in ZeroPredecessorVertexList) { m_TopologySortedNodeList.Add(vertex.GetNode()); // In valid the vertex and edges. vertex.SetValid(false); foreach (GraphEdge edge in vertex.GetSuccessorEdges()) { edge.SetValid(false); } } } }
public void GetImmediateSuccessors(Node node, FRList<Node> immediateSucs) { GraphVertex vertex = null; if (!m_NodeGraphVertexMap.ContainsKey(node)) return; vertex = m_NodeGraphVertexMap[node]; foreach (GraphEdge edge in vertex.GetSuccessorEdges()) { Node sucNode = edge.GetEndVertex().GetNode(); Debug.Assert(sucNode != node); if (!immediateSucs.Contains(sucNode)) immediateSucs.Add(sucNode); } }
public void GetImmediatePredecessors(Node node, FRList<Node> immediatePres) { GraphVertex vertex = null; if (!m_NodeGraphVertexMap.ContainsKey(node)) return; vertex = m_NodeGraphVertexMap[node]; foreach(GraphEdge edge in vertex.GetPredecessorEdges()) { Node preNode = edge.GetStartVertex().GetNode(); Debug.Assert(preNode != node); if (!immediatePres.Contains(preNode)) immediatePres.Add(preNode); } }
public GraphVertex(Node node) { m_Node = node; m_PredecessorGraphEdges = new FRList<GraphEdge>(); m_SucessorGraphEdges = new FRList<GraphEdge>(); }
private bool IsExist(Node node) { foreach(Node curNode in m_NodeList) { if (curNode == node) return true; } return false; }
// bClearRelatedNodes indicates whether remove the related nodes // or just remove the input one. public void RemoveNode(Node node, bool bClearRelatedNodes) { if (!IsExist(node)) return; if(!bClearRelatedNodes) { m_NodeList.Remove(node); } else { FRList<Node> deletedNodeList = new FRList<Node>(); FRList<Node> dieNominateList = new FRList<Node>(); deletedNodeList.Add(node); dieNominateList.Add(node); while (dieNominateList.Count > 0) { Node tmpNode = dieNominateList[0]; dieNominateList.Remove(tmpNode); if (deletedNodeList.Contains(tmpNode) || tmpNode.IsDeletable(deletedNodeList)) { if (!deletedNodeList.Contains(tmpNode)) deletedNodeList.Add(tmpNode); FRList<Node> nodeNominates = new FRList<Node>(); tmpNode.GetDeleteNominates(nodeNominates); foreach (Node item in nodeNominates) { if (!dieNominateList.Contains(item)) dieNominateList.Add(item); } } } // Delete the nodes in the data model foreach (Node delNode in deletedNodeList) m_NodeList.Remove(delNode); } m_bIsGraphDirty = true; }
public bool IsFirstPriorToSecond(Node firstNode, Node secondNode) { if (firstNode != null || secondNode != null) return false; if (!IsExist(firstNode) || !IsExist(secondNode)) return false; UpdateNodeGraph(); m_Graph.ValidateAll(); m_Graph.InvalidatePredecessors(firstNode); bool bRet = (m_Graph.IsNodeVertexValid(secondNode) == true); return bRet; }