示例#1
0
        /// <summary>
        /// Adds an edge connecting two vertices and recalculates their respective connected
        /// subgraphs if needed.
        /// </summary>
        /// <param name="vertex1">The first vertex.</param>
        /// <param name="vertex2">The second vertex.</param>
        private void AddEdgeBetweenVertices(Vertex vertex1, Vertex vertex2)
        {
            // Connect vertices
            vertex1.ConnectToVertex(vertex2);

            // If the two vertices were not part of the same connected subgraph until now,
            // recalculate the new connected subgraph and assign it to all vertices that belong to
            // it
            ConnectedSubgraph mainGraph = _connectedSubgraphs[vertex1];

            if (mainGraph != _connectedSubgraphs[vertex2])
            {
                mainGraph.RecalculateConnectedVertices();
                foreach (Vertex connectedVertex in mainGraph.ConnectedVertices)
                {
                    _connectedSubgraphs[connectedVertex] = mainGraph;
                }
            }
            else if (mainGraph.CheckWillConnectStrongly(vertex1, vertex2))
                mainGraph.RecalculateConnectedVertices();
        }