Пример #1
0
        private void Invalid(IGraphInterface graph)
        {
            // Variable
            List <IVertexInterface> vertexList           = graph.AllVertices();
            List <IVertexInterface> vertexNot2DegreeList = new List <IVertexInterface>();

            vertexNot2DegreeList = vertexList.Where(v => graph.CountNeighbours(v) != 2).ToList();
            IEdgeInterface edge = new Edge(vertexList.First(), graph.Neighbours(vertexList.First()).First());

            // Vertex add
            stringBuilder.AppendLine("Vertex add");
            stringBuilder.AppendLine("Vertex exists");
            try { graph.VertexAdd(vertexList.First()); }
            catch (MyException.GraphException.GraphException e) { stringBuilder.AppendLine(e.Message); }

            // Vertex delete
            stringBuilder.AppendLine("Vertex delete");
            stringBuilder.AppendLine("Vertex doesn't exist");
            try { graph.VertexDelete(new Vertex()); }
            catch (MyException.GraphException.GraphException e) { stringBuilder.AppendLine(e.Message); }

            // Vertex contract
            stringBuilder.AppendLine("Vertex contract");
            stringBuilder.AppendLine("Vertex doesn't exist");
            try { graph.VertexContraction(new Vertex()); }
            catch (MyException.GraphException.GraphException e) { stringBuilder.AppendLine(e.Message); }

            // Vertex suppression
            stringBuilder.AppendLine("Vertex suppression");
            stringBuilder.AppendLine("Vertex doesn't exist");
            try { graph.VertexSuppression(new Vertex()); }
            catch (MyException.GraphException.GraphException e) { stringBuilder.AppendLine(e.Message); }
            stringBuilder.AppendLine("Invalid vertex degree");
            try { graph.VertexSuppression(vertexNot2DegreeList.First()); }
            catch (MyException.GraphException.GraphException e) { stringBuilder.AppendLine(e.Message); }

            // Vertex expansion
            stringBuilder.AppendLine("Vertex expansion");
            stringBuilder.AppendLine("Vertex doesn't exist");
            try { graph.VertexExpansion(new Vertex()); }
            catch (MyException.GraphException.GraphException e) { stringBuilder.AppendLine(e.Message); }

            // Edge add
            stringBuilder.AppendLine("Edge add");
            stringBuilder.AppendLine("Edge exists");
            try { graph.EdgeAdd(edge); }
            catch (MyException.GraphException.GraphException e) { stringBuilder.AppendLine(e.Message); }

            // Edge delete
            stringBuilder.AppendLine("Edge delete");
            stringBuilder.AppendLine("Edge doesn't exist");
            try { graph.EdgeDelete(new Edge(new Vertex(), new Vertex())); }
            catch (MyException.GraphException.GraphException e) { stringBuilder.AppendLine(e.Message); }

            // Edge contract
            stringBuilder.AppendLine("Edge contract");
            stringBuilder.AppendLine("Edge doesn't exist");
            try { graph.EdgeContraction(new Edge(new Vertex(), new Vertex())); }
            catch (MyException.GraphException.GraphException e) { stringBuilder.AppendLine(e.Message); }

            // Edge subdivision
            stringBuilder.AppendLine("Edge subdivision");
            stringBuilder.AppendLine("Edge doesn't exist");
            try { graph.EdgeSubdivision(new Edge(new Vertex(), new Vertex())); }
            catch (MyException.GraphException.GraphException e) { stringBuilder.AppendLine(e.Message); }
        }
Пример #2
0
        public void EdgeAdd(IEdgeInterface edge)
        {
            // Variable
            IVertexInterface vertex1 = graph.GetVertexByUserName(edge.GetVertex1().GetUserName());
            IVertexInterface vertex2 = graph.GetVertexByUserName(edge.GetVertex2().GetUserName());

            // Component
            if (componentsList != null)
            {
                // Need change => copies of component
                if (countComponents > 1)
                {
                    // Get component which contains the vertex
                    bool            inSameComponent  = false;
                    IGraphInterface myComponentGraph = null;
                    foreach (IGraphInterface componentGraph in componentsList)
                    {
                        if (componentGraph.ExistsUserName(vertex1.GetUserName()))
                        {
                            if (componentGraph.ExistsUserName(vertex2.GetUserName()))
                            {
                                inSameComponent  = true;
                                myComponentGraph = componentGraph;
                            }

                            break;
                        }
                    }

                    if (!inSameComponent)
                    {
                        componentsList  = null;
                        countComponents = null;
                        isConnected     = null;
                    }
                    else
                    {
                        myComponentGraph.EdgeAdd(new Edge(myComponentGraph.GetVertexByUserName(vertex1.GetUserName()), myComponentGraph.GetVertexByUserName(vertex2.GetUserName())));
                    }
                }
                else
                {
                    //componentsList = componentsList;
                    //countComponents = countComponents;
                    //isConnected = isConnected;
                }
            }

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

            // IntegralInvariants
            circuitRank = null;
            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 (maximumVertexDegree.HasValue)
                {
                    if (countNeighbourVertex1 > maximumVertexDegree)
                    {
                        maximumVertexDegree = countNeighbourVertex1;
                    }
                    if (countNeighbourVertex2 > maximumVertexDegree)
                    {
                        maximumVertexDegree = countNeighbourVertex2;
                    }
                }

                if (minimumVertexDegree.HasValue)
                {
                    if (((countNeighbourVertex1 - 1) == minimumVertexDegree) ||
                        ((countNeighbourVertex2 - 1) == minimumVertexDegree))
                    {
                        minimumVertexDegree = null;
                    }
                }

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

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

            // GraphClass
            graphClass = GraphClass.GraphClass.GraphClassEnum.undefined;
        }
Пример #3
0
        private void Valid(IGraphInterface graph)
        {
            // Variable
            List <IVertexInterface> vertexList = graph.AllVertices();

            graph.VertexContraction(vertexList.First());
            vertexList = graph.AllVertices();

            graph.VertexSuppression(vertexList.First());
            vertexList = graph.AllVertices();

            graph.VertexExpansion(vertexList.First());
            vertexList = graph.AllVertices();

            graph.VertexSuppression(vertexList.Last());
            vertexList = graph.AllVertices();

            graph.VertexDelete(vertexList.First());
            vertexList = graph.AllVertices();

            graph.VertexSuppression(vertexList.Last());
            vertexList = graph.AllVertices();

            IVertexInterface v1 = new Vertex("V1");

            graph.VertexAdd(v1);
            vertexList = graph.AllVertices();

            graph.EdgeAdd(new Edge(vertexList.First(), v1));
            vertexList = graph.AllVertices();

            graph.VertexContraction(v1);
            vertexList = graph.AllVertices();

            graph.EdgeSubdivision(new Edge(vertexList.First(), vertexList.Skip(1).First()));
            vertexList = graph.AllVertices();

            graph.EdgeAdd(new Edge(vertexList.First(), vertexList.Skip(1).First()));
            vertexList = graph.AllVertices();

            graph.EdgeContraction(new Edge(vertexList.First(), vertexList.Skip(1).First()));
            vertexList = graph.AllVertices();

            graph.EdgeDelete(new Edge(vertexList.First(), vertexList.Skip(1).First()));
            vertexList = graph.AllVertices();

            graph.VertexDelete(vertexList.Skip(1).First());
            vertexList = graph.AllVertices();

            graph.VertexSuppression(vertexList.First());
            vertexList = graph.AllVertices();

            graph.VertexDelete(vertexList.First());
            vertexList = graph.AllVertices();

            graph.VertexExpansion(vertexList.First());
            vertexList = graph.AllVertices();

            graph.EdgeContraction(new Edge(vertexList.First(), vertexList.Skip(1).First()));
            vertexList = graph.AllVertices();

            IVertexInterface v2 = new Vertex("V2");

            graph.VertexAdd(v2);
            vertexList = graph.AllVertices();

            graph.VertexDelete(vertexList.Skip(1).First());

            graph.VertexAdd(new Vertex("V3"));
        }