Exemplo n.º 1
0
        /// <summary>
        /// Remove an edge
        /// Deinitialize colored graph
        /// If the edge does not exist in the graph throws GraphEdgeDoesntExistException
        /// </summary>
        /// <param name="edge">edge</param>
        public void EdgeDelete(IEdgeInterface edge)
        {
            if (!ExistsEdge(edge))
            {
                throw new MyException.GraphException.GraphEdgeDoesntExistException();
            }

            // Variable
            adjacencyList.TryGetValue(ConvertVertexToVertexExtended(edge.GetVertex1()), out HashSet <VertexExtended> neighbooursHashSet);
            neighbooursHashSet.Remove(ConvertVertexToVertexExtended(edge.GetVertex2()));

            adjacencyList.TryGetValue(ConvertVertexToVertexExtended(edge.GetVertex2()), out neighbooursHashSet);
            neighbooursHashSet.Remove(ConvertVertexToVertexExtended(edge.GetVertex1()));

            SetCanDeIncreaseCountEdges(true);
            GetGraphProperty().DecrementCountEdges();
            SetCanDeIncreaseCountEdges(false);

            // ColoredGraph
            if (coloredGraph.GetIsInitializedColoredGraph())
            {
                coloredGraph.DeinitializationColoredGraph();
            }

            // GraphProperty
            GetGraphProperty().EdgeDelete(edge);
        }
Exemplo n.º 2
0
        public void EdgeContraction(IEdgeInterface edge)
        {
            // Component
            if (componentsList != null)
            {
                componentsList  = null;
                countComponents = null;
                isConnected     = null;
            }

            // Properties
            if (isCyclic != null && !(bool)isCyclic)
            {
                isCyclic = false;
            }
            else
            {
                isCyclic = null;
            }
            isEulerian = EulerianGraphEnum.undefined;

            // IntegralInvariants
            circuitRank = null;
            if (girth != null && girth > 2)
            {
                girth = null;
            }
            cayleysFormula = null;

            // SequencesAndPolynomialsOthers
            if (isConnected != null && !(bool)isConnected)
            {
                spanningTreeBFS = spanningTreeBFS = new List <IEdgeInterface>();
            }
            else
            {
                spanningTreeBFS = null;
            }
            matching    = null;
            cutVertices = null;
            bridges     = null;

            // DegreeSequence
            degreeSequence         = null;
            maximumVertexDegree    = null;
            minimumVertexDegree    = null;
            averageVertexDegree    = null;
            medianVertexDegree     = null;
            isDegreeSequenceSorted = false;
            isRegular = null;

            // Chordal
            isChordal = null;
            perfectEliminationOrderingList = null;
            righNeighborhoodDictionary     = null;

            // GraphClass
            graphClass = GraphClass.GraphClass.GraphClassEnum.undefined;
        }
Exemplo n.º 3
0
        public bool Equals(IEdgeInterface edge)
        {
            if ((edge.GetVertex1().Equals(vertex1) && edge.GetVertex2().Equals(vertex2)) ||
                (edge.GetVertex1().Equals(vertex2) && edge.GetVertex2().Equals(vertex1)))
            {
                return(true);
            }

            return(false);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Return true if an edge exists in the graph, otherwise false
        /// Time complexity: O(1)
        /// </summary>
        /// <param name="edge">edge</param>
        /// <returns>true if the edge exists in the graph, otherwise false</returns>
        public bool ExistsEdge(IEdgeInterface edge)
        {
            if (!ExistsVertex(edge.GetVertex1()) || !ExistsVertex(edge.GetVertex2()))
            {
                return(false);
            }

            adjacencyList.TryGetValue(ConvertVertexToVertexExtended(edge.GetVertex1()), out HashSet <VertexExtended> neighboursList);

            if (neighboursList == null)
            {
                return(false);
            }

            return(neighboursList.Contains(ConvertVertexToVertexExtended(edge.GetVertex2())));
        }
Exemplo n.º 5
0
        /// <summary>
        /// Contract an edge
        /// Deinitialize coloredGraph
        /// If the edge does not exist in the graph throws GraphEdgeDoesntExistException
        /// </summary>
        /// <param name="edge">edge</param>
        public void EdgeContraction(IEdgeInterface edge)
        {
            if (!ExistsEdge(edge))
            {
                throw new MyException.GraphException.GraphEdgeDoesntExistException();
            }

            // Variable
            int neighbours1Count, neighbours2Count, neighboursCount;
            List <IVertexInterface> neighboursVertex1List, neighboursVertex2List, neighboursList;

            EdgeDelete(edge);

            neighboursVertex1List = Neighbours(edge.GetVertex1());
            neighboursVertex2List = Neighbours(edge.GetVertex2());
            neighbours1Count      = neighboursVertex1List.Count;
            neighbours2Count      = neighboursVertex2List.Count;

            neighboursList  = neighboursVertex1List.Union(neighboursVertex2List).ToList();
            neighboursCount = neighboursList.Count;

            IVertexInterface newVertex = new Vertex(edge.GetVertex1().GetUserName() + edge.GetVertex2().GetUserName());

            // Add vertex
            VertexAdd(newVertex);

            // Delete vertices
            VertexDelete(edge.GetVertex1());
            VertexDelete(edge.GetVertex2());

            // Add edges
            foreach (IVertexInterface neighbour in neighboursList)
            {
                EdgeAdd(new Edge(newVertex, neighbour));
            }

            // ColoredGraph
            if (coloredGraph.GetIsInitializedColoredGraph())
            {
                coloredGraph.DeinitializationColoredGraph();
            }

            // GraphProperty
            GetGraphProperty().EdgeContraction(edge);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Add an edge
        /// Deinitialize colored graph
        /// If the edge exists in the graph throws GraphEdgeAlreadyExistsException
        /// </summary>
        /// <param name="edge">edge</param>
        public void EdgeAdd(IEdgeInterface edge)
        {
            if (ExistsEdge(edge))
            {
                throw new MyException.GraphException.GraphEdgeAlreadyExistsException();
            }

            AddEdgeToAdjacencyList(edge);

            // ColoredGraph
            if (coloredGraph.GetIsInitializedColoredGraph())
            {
                coloredGraph.DeinitializationColoredGraph();
            }

            // GraphProperty
            GetGraphProperty().EdgeAdd(edge);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Add a new edge
        /// If any vertex does not exist throws GraphVertexDoesntExist
        /// If vertex1 = vertex2 throws GraphInvalidVertexException
        /// If the edge already exists throws GraphDupliciteEdge
        /// </summary>
        /// <param name="vertex1">first vertex</param>
        /// <param name="vertex2">second vertex</param>
        protected void AddEdgeToAdjacencyList(IEdgeInterface edge)
        {
            // Variable
            IVertexInterface vertex;
            IVertexInterface vertex1 = edge.GetVertex1();
            IVertexInterface vertex2 = edge.GetVertex2();

            // If vertex1 is vertex2
            if (vertex1 == vertex2)
            {
                throw new MyException.GraphException.GraphInvalidVertexException();
            }

            // Symmetry
            for (int i = 0; i < 2; i++)
            {
                if (!adjacencyList.TryGetValue(ConvertVertexToVertexExtended(vertex1), out HashSet <VertexExtended> adjacencyHashSetVertexExtended))
                {
                    throw new MyException.GraphException.GraphVertexDoesntExistException();
                }

                if (adjacencyHashSetVertexExtended.Contains(ConvertVertexToVertexExtended(vertex2)))
                {
                    return;
                }
                // throw new MyException.GraphDupliciteEdge();

                adjacencyHashSetVertexExtended.Add(ConvertVertexToVertexExtended(vertex2));

                // Swap variables
                vertex  = vertex1;
                vertex1 = vertex2;
                vertex2 = vertex;
            }

            SetCanDeIncreaseCountEdges(true);
            graphProperty.IncrementCountEdges();
            SetCanDeIncreaseCountEdges(false);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Subdivide an edge
        /// Deinitialize colored graph
        /// If the edge does not exist in the graph throws GraphEdgeDoesntExistException
        /// </summary>
        /// <param name="edge">edge</param>
        public void EdgeSubdivision(IEdgeInterface edge)
        {
            if (!ExistsEdge(edge))
            {
                throw new MyException.GraphException.GraphEdgeDoesntExistException();
            }

            EdgeDelete(edge);

            IVertexInterface newVertex = new Vertex();

            VertexAdd(newVertex);
            EdgeAdd(new Edge(edge.GetVertex1(), newVertex));
            EdgeAdd(new Edge(newVertex, edge.GetVertex2()));

            // ColoredGraph
            if (coloredGraph.GetIsInitializedColoredGraph())
            {
                coloredGraph.DeinitializationColoredGraph();
            }

            // GraphProperty
            GetGraphProperty().EdgeSubdivision(edge);
        }
Exemplo n.º 9
0
        public void EdgeSubdivision(IEdgeInterface edge)
        {
            // Variable
            IVertexInterface vertex1 = graph.GetVertexByUserName(edge.GetVertex1().GetUserName());
            IVertexInterface vertex2 = graph.GetVertexByUserName(edge.GetVertex2().GetUserName());

            // Component
            if (componentsList != null)
            {
                if (countComponents > 1)
                {
                    // Get component which contains the vertex
                    IGraphInterface myComponentGraph = null;
                    foreach (IGraphInterface componentGraph in componentsList)
                    {
                        if (componentGraph.ExistsUserName(vertex1.GetUserName()))
                        {
                            myComponentGraph = componentGraph;
                            break;
                        }
                    }

                    myComponentGraph.EdgeSubdivision(new Edge(myComponentGraph.GetVertexByUserName(vertex1.GetUserName()), myComponentGraph.GetVertexByUserName(vertex2.GetUserName())));
                }
                else
                {
                    //componentsList = componentsList;
                    //countComponents = countComponents;
                    //isConnected = isConnected;
                }
            }

            // Properties
            //isCyclic = isCyclic;
            //isEulerian = isEulerian;

            // IntegralInvariants
            //circuitRank = circuitRank;
            if (girth.HasValue && girth > 2)
            {
                girth = null;
            }
            cayleysFormula = null;

            // SequencesAndPolynomialsOthers
            if (isConnected != null && !(bool)isConnected)
            {
                spanningTreeBFS = spanningTreeBFS = new List <IEdgeInterface>();
            }
            else
            {
                spanningTreeBFS = null;
            }
            matching    = null;
            cutVertices = null;
            bridges     = null;

            // DegreeSequence
            degreeSequence         = null;
            maximumVertexDegree    = null;
            minimumVertexDegree    = null;
            averageVertexDegree    = null;
            medianVertexDegree     = null;
            isDegreeSequenceSorted = false;
            isRegular = null;

            // Chordal
            if (isChordal.HasValue && (bool)isChordal)
            {
                isChordal = null;
                perfectEliminationOrderingList = null;
                righNeighborhoodDictionary     = null;
            }

            // GraphClass
            graphClass = GraphClass.GraphClass.GraphClassEnum.undefined;
        }
Exemplo n.º 10
0
        public void EdgeDelete(IEdgeInterface edge)
        {
            // Variable
            IVertexInterface vertex1 = graph.GetVertexByUserName(edge.GetVertex1().GetUserName());
            IVertexInterface vertex2 = graph.GetVertexByUserName(edge.GetVertex2().GetUserName());

            // Component
            if (componentsList != null)
            {
                if (countComponents > 1)
                {
                    // Get component which contains the vertex
                    IGraphInterface myComponentGraph = null;
                    foreach (IGraphInterface componentGraph in componentsList)
                    {
                        if (componentGraph.ExistsUserName(vertex1.GetUserName()))
                        {
                            myComponentGraph = componentGraph;
                            break;
                        }
                    }

                    myComponentGraph.EdgeDelete(new Edge(myComponentGraph.GetVertexByUserName(vertex1.GetUserName()), myComponentGraph.GetVertexByUserName(vertex2.GetUserName())));

                    componentsList  = null;
                    countComponents = null;
                    isConnected     = null;
                }
                else
                {
                    if (bridges != null)
                    {
                        // The edge is a bridge
                        if (bridges.Any(e => ((e.GetVertex1().Equals(vertex1) && e.GetVertex2().Equals(vertex2)) ||
                                              (e.GetVertex1().Equals(vertex2) && e.GetVertex2().Equals(vertex1)))))
                        {
                            componentsList  = null;
                            countComponents = null;
                            isConnected     = null;
                        }
                        // The edge isn't a bridge
                        else
                        {
                            //componentsList = componentsList;
                            //countComponents = countComponents;
                            //isConnected = isConnected;
                        }
                    }
                }
            }

            // Properties
            if (isCyclic != null && !(bool)isCyclic)
            {
                isCyclic = false;
            }
            else
            {
                isCyclic = null;
            }
            if (isEulerian == EulerianGraphEnum.eulerian)
            {
                isEulerian = EulerianGraphEnum.semiEulerian;
            }
            else
            {
                isEulerian = EulerianGraphEnum.undefined;
            }

            // IntegralInvariants
            circuitRank = null;
            if (girth != null && girth > 2)
            {
                girth = null;
            }
            //cayleysFormula = cayleysFormula;

            // SequencesAndPolynomialsOthers
            if (isConnected != null && !(bool)isConnected)
            {
                spanningTreeBFS = spanningTreeBFS = new List <IEdgeInterface>();
            }
            else
            {
                spanningTreeBFS = null;
            }
            matching    = null;
            cutVertices = null;
            bridges     = null;

            // DegreeSequence
            if (degreeSequence != null)
            {
                int countNeighbourVertex1 = graph.CountNeighbours(vertex1);
                int countNeighbourVertex2 = graph.CountNeighbours(vertex2);
                if (!isDegreeSequenceSorted)
                {
                    // Variable
                    int index1, index2;

                    index1 = degreeSequenceInt.FindIndex(i => i == (countNeighbourVertex1 + 1));
                    degreeSequenceInt[index1] = countNeighbourVertex1;
                    index2 = degreeSequenceInt.FindIndex(i => i == (countNeighbourVertex2 + 1));
                    degreeSequenceInt[index2] = countNeighbourVertex2;

                    index1 = degreeSequence.FindIndex(p => p.Key == vertex1);
                    index2 = degreeSequence.FindIndex(p => p.Key == vertex2);
                    degreeSequence[index1] = new KeyValuePair <IVertexInterface, int>(vertex1, countNeighbourVertex1);
                    degreeSequence[index2] = new KeyValuePair <IVertexInterface, int>(vertex2, countNeighbourVertex2);
                }
                else
                {
                    degreeSequence         = null;
                    degreeSequenceVertex   = null;
                    degreeSequenceInt      = null;
                    isDegreeSequenceSorted = false;
                }

                if (minimumVertexDegree.HasValue)
                {
                    if (countNeighbourVertex1 < minimumVertexDegree)
                    {
                        minimumVertexDegree = countNeighbourVertex1;
                    }
                    if (countNeighbourVertex2 < minimumVertexDegree)
                    {
                        minimumVertexDegree = countNeighbourVertex2;
                    }
                }

                if (maximumVertexDegree.HasValue)
                {
                    if (((countNeighbourVertex1 + 1) == maximumVertexDegree) ||
                        ((countNeighbourVertex2 + 1) == maximumVertexDegree))
                    {
                        maximumVertexDegree = null;
                    }
                }

                averageVertexDegree = null;
                medianVertexDegree  = null;
                isRegular           = null;
            }

            // Chordal
            isChordal = null;
            perfectEliminationOrderingList = null;
            righNeighborhoodDictionary     = null;

            // GraphClass
            graphClass = GraphClass.GraphClass.GraphClassEnum.undefined;
        }