예제 #1
0
        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);
                    }
                }
            }
        }
예제 #2
0
        public bool TopologySort()
        {
            m_TopologySortedNodeList.Clear();

            FRList<GraphVertex> ZeroPredecessorVertexList = new FRList<GraphVertex>();
            while (true)
            {
                ZeroPredecessorVertexList.Clear();
                foreach (GraphVertex curVertex in m_NodeGraphVertexMap.Values)
                {
                    if (curVertex.Valid() && curVertex.GetpredecessorCount() == 0)
                        ZeroPredecessorVertexList.Add(curVertex);
                }

                // There is no zero degree vertex.
                // 1. Finish all the vertex.
                // 2. The left vertex are circles.
                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);
                    }
                }
            }

            // If the sorted vertexes count isn't equal to the graph vertex count, that means there exist circle.
            Debug.Assert(m_TopologySortedNodeList.Count == m_NodeGraphVertexMap.Count);
            if (m_TopologySortedNodeList.Count != m_NodeGraphVertexMap.Count)
                return false;

            return true;
        }
예제 #3
0
        public void BuildGraph(FRList<Node> nodeList)
        {
            m_NodeGraphVertexMap.Clear();
            m_NodeGraphEdgeList.Clear();

            foreach (Node node in nodeList)
            {
                GraphVertex thisVertex = GetVertex(node);
                Constraint cons = node as Constraint;

                if (cons != null)
                {
                    FRList<Node> nodes = new FRList<Node>();
                    cons.GetPredecessor(nodes);
                    foreach (Node preNode in nodes)
                    {
                        GraphVertex preVertex = GetVertex(preNode);
                        AddEdge(preVertex, thisVertex);
                    }

                    nodes.Clear();
                    cons.GetSuccessor(nodes);
                    foreach (Node sucNode in nodes)
                    {
                        GraphVertex sucVertex = GetVertex(sucNode);
                        AddEdge(thisVertex, sucVertex);
                    }
                }
            }
        }