Example #1
0
 public GraphEdge(GraphVertex startVertex, GraphVertex endVertex)
 {
     m_startVertex = startVertex;
     m_endVertex = endVertex;
     m_startVertex.AddSuccessor(this);
     m_endVertex.AddPredecessor(this);
 }
Example #2
0
        // 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;
        }
Example #3
0
        // Return the existing edge for the input vertexes.
        // If no add a new edge to the graph.
        private void AddEdge(GraphVertex startVertex, GraphVertex endVertex)
        {
            // Quickly check
            if (startVertex.GetSuccessorEdges().Count == 0 || endVertex.GetPredecessorEdges().Count == 0)
            {
                GraphEdge edge = new GraphEdge(startVertex, endVertex);
                m_NodeGraphEdgeList.Add(edge);
                return;
            }

            // Just need to check one vertex
            FRList<GraphEdge> sucessorGraphEdges = startVertex.GetSuccessorEdges();
            foreach (GraphEdge edge in sucessorGraphEdges)
            {
                if (edge.GetEndVertex() == endVertex)
                    return; // Do nothing if it exists.
            }

            // Add a new edge
            GraphEdge edge2 = new GraphEdge(startVertex, endVertex);
            m_NodeGraphEdgeList.Add(edge2);
        }