Exemplo n.º 1
0
        private void Testing(CycleEnum cycleEnum)
        {
            try
            {
                testPath = ReaderWriter.ReaderWriter.CreateTestFile(testsDictionary[cycleEnum]);

                reader = new ReaderWriter.ReaderGraph(testPath, false);
                graph  = reader.ReadFile();

                stringBuilder.AppendLine(cycleEnum.ToString());
                stringBuilder.AppendLine("Graph created.");
                stringBuilder.AppendLine(graph.ToString());

                stringBuilder.AppendLine("Is graph cyclic: " + graph.GetGraphProperty().GetIsCyclic());
                stringBuilder.AppendLine("Gridth: " + graph.GetGraphProperty().GetGirth());
            }
            catch (KeyNotFoundException)
            {
                throw new MyException.TestsException.TestsMissingTestException(cycleEnum.ToString());
            }
            catch (MyException.ReaderWriterException.ReaderWriterException e)
            {
                stringBuilder.AppendLine(e.Message);
            }
        }
        private void Testing(SmallestLastSequenceEnum smallestLastSequence)
        {
            try
            {
                testPath = ReaderWriter.ReaderWriter.CreateTestFile(testsDictionary[smallestLastSequence]);

                reader = new ReaderWriter.ReaderGraph(testPath, false);
                graph  = reader.ReadFile();

                SmallestLastSequence smallestLastSequenceAlgorithm = new SmallestLastSequence(graph);
                smallestLastSequenceAlgorithm.Color();

                stringBuilder.AppendLine(smallestLastSequence.ToString());
                stringBuilder.AppendLine("Graph colored.");
                stringBuilder.AppendLine(graph.GetColoredGraph().ToString());
            }
            catch (KeyNotFoundException)
            {
                throw new MyException.TestsException.TestsMissingTestException(smallestLastSequence.ToString());
            }
            catch (MyException.ReaderWriterException.ReaderWriterException e)
            {
                stringBuilder.AppendLine(e.Message);
            }
        }
Exemplo n.º 3
0
        private void Testing(ComplementEnum complementEnum)
        {
            try
            {
                testPath = ReaderWriter.ReaderWriter.CreateTestFile(testsDictionary[complementEnum]);

                reader = new ReaderWriter.ReaderGraph(testPath, false);
                graph  = reader.ReadFile();

                stringBuilder.AppendLine(complementEnum.ToString());
                stringBuilder.AppendLine("Graph created.");
                stringBuilder.AppendLine(graph.ToString());

                IGraphInterface graphComplement = GraphOperation.ComplementGraph(graph);

                stringBuilder.AppendLine("Complement graph.");
                stringBuilder.AppendLine(graphComplement.ToString());
            }
            catch (KeyNotFoundException)
            {
                throw new MyException.TestsException.TestsMissingTestException(complementEnum.ToString());
            }
            catch (MyException.ReaderWriterException.ReaderWriterException e)
            {
                stringBuilder.AppendLine(e.Message);
            }
        }
Exemplo n.º 4
0
        private void Testing(ClassEnum classEnum)
        {
            try
            {
                testPath = ReaderWriter.ReaderWriter.CreateTestFile(testsDictionary[classEnum]);

                reader = new ReaderWriter.ReaderGraph(testPath, false);
                graph  = reader.ReadFile();

                stringBuilder.AppendLine(classEnum.ToString());
                stringBuilder.AppendLine("Graph created.");
                stringBuilder.AppendLine(graph.ToString());

                GraphClass.GraphClassEnum graphClassEnum = GraphClass.GetGraphClass(graph);

                stringBuilder.AppendLine("Graph class: " + graphClassEnum.ToString());
            }
            catch (KeyNotFoundException)
            {
                throw new MyException.TestsException.TestsMissingTestException(classEnum.ToString());
            }
            catch (MyException.ReaderWriterException.ReaderWriterException e)
            {
                stringBuilder.AppendLine(e.Message);
            }
        }
Exemplo n.º 5
0
        private void Testing(SpanningTreeEnum spanningTreeEnum)
        {
            try
            {
                testPath = ReaderWriter.ReaderWriter.CreateTestFile(testsDictionary[spanningTreeEnum]);
                reader   = new ReaderWriter.ReaderGraph(testPath, false);
                graph    = reader.ReadFile();

                stringBuilder.AppendLine(spanningTreeEnum.ToString());
                stringBuilder.AppendLine("Graph created.");
                stringBuilder.AppendLine(graph.ToString());

                stringBuilder.AppendLine("SpanningTree: ");

                List <IEdgeInterface> spanningTreeList = graph.GetGraphProperty().GetSpanningTree();

                foreach (IEdgeInterface edge in spanningTreeList)
                {
                    stringBuilder.AppendLine(edge.ToString());
                }
            }
            catch (KeyNotFoundException)
            {
                throw new MyException.TestsException.TestsMissingTestException(spanningTreeEnum.ToString());
            }
            catch (MyException.ReaderWriterException.ReaderWriterException e)
            {
                stringBuilder.AppendLine(e.Message);
            }
        }
Exemplo n.º 6
0
        private void Testing(SubGraphEnum subGraphEnum)
        {
            try
            {
                testPath      = ReaderWriter.ReaderWriter.CreateTestFile(testsDictionary[subGraphEnum].Item1);
                countVertices = testsDictionary[subGraphEnum].Item2;

                reader = new ReaderWriter.ReaderGraph(testPath, false);
                graph  = reader.ReadFile();

                stringBuilder.AppendLine(subGraphEnum.ToString());
                stringBuilder.AppendLine("Graph created.");
                stringBuilder.AppendLine(graph.ToString());

                IGraphInterface subGraph = GraphOperation.SubGraph(graph, graph.AllVertices().Take(countVertices).ToList());

                stringBuilder.AppendLine("Subgraph created.");
                stringBuilder.AppendLine(subGraph.ToString());
            }
            catch (KeyNotFoundException)
            {
                throw new MyException.TestsException.TestsMissingTestException(subGraphEnum.ToString());
            }
            catch (MyException.ReaderWriterException.ReaderWriterException e)
            {
                stringBuilder.AppendLine(e.Message);
            }
        }
Exemplo n.º 7
0
        private void Testing(ChordalTestEnum chordalEnum)
        {
            try
            {
                testPath = ReaderWriter.ReaderWriter.CreateTestFile(testsDictionary[chordalEnum]);

                reader = new ReaderWriter.ReaderGraph(testPath, false);
                graph  = reader.ReadFile();

                stringBuilder.AppendLine(chordalEnum.ToString());
                stringBuilder.AppendLine("Graph created.");
                stringBuilder.AppendLine(graph.ToString());

                stringBuilder.AppendLine("isChordal " + graph.GetGraphProperty().GetIsChordal());

                foreach (IVertexInterface vertex in graph.GetGraphProperty().GetPerfectEliminationOrdering())
                {
                    stringBuilder.AppendLine("- " + vertex.GetIdentifier());
                }
            }
            catch (KeyNotFoundException)
            {
                throw new MyException.TestsException.TestsMissingTestException(chordalEnum.ToString());
            }
            catch (MyException.ReaderWriterException.ReaderWriterException e)
            {
                stringBuilder.AppendLine(e.Message);
            }
            catch (MyException.GraphException.GraphIsNotConnected e)
            {
                stringBuilder.AppendLine(e.Message);
            }
        }
        private void Testing(ConnectedSequentialEnum connectedSequential)
        {
            try
            {
                testPath = ReaderWriter.ReaderWriter.CreateTestFile(testsDictionary[connectedSequential]);

                reader = new ReaderWriter.ReaderGraph(testPath, false);
                graph  = reader.ReadFile();

                ConnectedSequential optimalAlgorithm = new ConnectedSequential(graph);
                optimalAlgorithm.Color();

                stringBuilder.AppendLine(connectedSequential.ToString());
                stringBuilder.AppendLine("Graph colored.");
                stringBuilder.AppendLine(graph.GetColoredGraph().ToString());
            }
            catch (KeyNotFoundException)
            {
                throw new MyException.TestsException.TestsMissingTestException(connectedSequential.ToString());
            }
            catch (MyException.ReaderWriterException.ReaderWriterException e)
            {
                stringBuilder.AppendLine(e.Message);
            }
        }
Exemplo n.º 9
0
        private void Testing(ModificationEnum modificationEnum)
        {
            try
            {
                testPath = ReaderWriter.ReaderWriter.CreateTestFile(testsDictionary[modificationEnum]);
                reader   = new ReaderWriter.ReaderGraph(testPath, false);
                graph    = reader.ReadFile();

                stringBuilder.AppendLine(modificationEnum.ToString());
                stringBuilder.AppendLine("Graph created.");
                stringBuilder.AppendLine(graph.ToString());

                switch (modificationEnum)
                {
                case ModificationEnum.valid:
                    Valid(graph);
                    break;

                case ModificationEnum.invalid:
                    Invalid(graph);
                    break;

                default:
                    throw new MyException.TestsException.TestsMissingTestException(modificationEnum.ToString());
                }

                stringBuilder.AppendLine("Graph modified.");
                stringBuilder.AppendLine(graph.ToString());
            }
            catch (KeyNotFoundException)
            {
                throw new MyException.TestsException.TestsMissingTestException(modificationEnum.ToString());
            }
        }
Exemplo n.º 10
0
        private void Testing(ComponentEnum componentEnum)
        {
            try
            {
                testPath = ReaderWriter.ReaderWriter.CreateTestFile(testsDictionary[componentEnum]);

                reader = new ReaderWriter.ReaderGraph(testPath, false);
                graph  = reader.ReadFile();

                stringBuilder.AppendLine(componentEnum.ToString());
                stringBuilder.AppendLine("Graph created.");
                stringBuilder.AppendLine(graph.ToString());

                stringBuilder.AppendLine("Number of components: " + graph.GetGraphProperty().GetCountComponents());
                stringBuilder.AppendLine("Is graph connected: " + graph.GetGraphProperty().GetIsConnected());
                stringBuilder.AppendLine("Circuit rank: " + graph.GetGraphProperty().GetCircuitRank());

                graphComponentList = graph.GetGraphProperty().GetComponents();

                foreach (Graph graphComponent in graphComponentList)
                {
                    stringBuilder.AppendLine("Graph component.");
                    stringBuilder.AppendLine(graphComponent.ToString());
                }
            }
            catch (KeyNotFoundException)
            {
                throw new MyException.TestsException.TestsMissingTestException(componentEnum.ToString());
            }
            catch (MyException.ReaderWriterException.ReaderWriterException e)
            {
                stringBuilder.AppendLine(e.Message);
            }
        }
        private void Testing(GreedyIndependentSetEnum greedyIndependentSet)
        {
            try
            {
                testPath = ReaderWriter.ReaderWriter.CreateTestFile(testsDictionary[greedyIndependentSet]);

                reader = new ReaderWriter.ReaderGraph(testPath, false);
                graph  = reader.ReadFile();

                GreedyIndependentSet greedyIndependentSetAlgorithm = new GreedyIndependentSet(graph);
                greedyIndependentSetAlgorithm.Color();

                stringBuilder.AppendLine(greedyIndependentSetAlgorithm.ToString());
                stringBuilder.AppendLine("Graph colored.");
                stringBuilder.AppendLine(graph.GetColoredGraph().ToString());
            }
            catch (KeyNotFoundException)
            {
                throw new MyException.TestsException.TestsMissingTestException(greedyIndependentSet.ToString());
            }
            catch (MyException.ReaderWriterException.ReaderWriterException e)
            {
                stringBuilder.AppendLine(e.Message);
            }
        }
Exemplo n.º 12
0
        private void Testing(DegreeSequenceEnum degreeSequenceEnum)
        {
            try
            {
                testPath = ReaderWriter.ReaderWriter.CreateTestFile(testsDictionary[degreeSequenceEnum]);

                reader = new ReaderWriter.ReaderGraph(testPath, false);
                graph  = reader.ReadFile();

                stringBuilder.AppendLine(degreeSequenceEnum.ToString());
                stringBuilder.AppendLine("Graph created.");
                stringBuilder.AppendLine(graph.ToString());

                // Sorted
                List <int> degreeSequenceList = graph.GetGraphProperty().GetDegreeSequenceInt(true);

                stringBuilder.AppendLine("Degree sequence");
                foreach (int degree in degreeSequenceList)
                {
                    stringBuilder.Append(degree + " ");
                }

                stringBuilder.AppendLine("");
                stringBuilder.AppendLine("Minimum vertex degree: " + graph.GetGraphProperty().GetMinimumVertexDegree());
                stringBuilder.AppendLine("Maximum vertex degree: " + graph.GetGraphProperty().GetMaximumVertexDegree());
                stringBuilder.AppendLine("Average vertex degree: " + graph.GetGraphProperty().GetAverageVertexDegree());
                stringBuilder.AppendLine("Is graph regular: " + graph.GetGraphProperty().GetIsRegular());

                graph.GetGraphProperty().Reset();

                // Unsorted
                degreeSequenceList = graph.GetGraphProperty().GetDegreeSequenceInt(false);

                stringBuilder.AppendLine("Degree sequence");
                foreach (int degree in degreeSequenceList)
                {
                    stringBuilder.Append(degree + " ");
                }

                stringBuilder.AppendLine("");
                stringBuilder.AppendLine("Minimum vertex degree: " + graph.GetGraphProperty().GetMinimumVertexDegree());
                stringBuilder.AppendLine("Maximum vertex degree: " + graph.GetGraphProperty().GetMaximumVertexDegree());
                stringBuilder.AppendLine("Average vertex degree: " + graph.GetGraphProperty().GetAverageVertexDegree());
                stringBuilder.AppendLine("Is graph regular: " + graph.GetGraphProperty().GetIsRegular());
            }
            catch (KeyNotFoundException)
            {
                throw new MyException.TestsException.TestsMissingTestException(degreeSequenceEnum.ToString());
            }
            catch (MyException.ReaderWriterException.ReaderWriterException e)
            {
                stringBuilder.AppendLine(e.Message);
            }
        }
Exemplo n.º 13
0
        private void Testing(ColoredGraphEnum coloredGraphEnum)
        {
            try
            {
                testPath = ReaderWriter.ReaderWriter.CreateTestFile(testsDictionary[coloredGraphEnum]);
                reader   = new ReaderWriter.ReaderGraph(testPath, false);
                graph    = reader.ReadFile();

                stringBuilder.AppendLine(coloredGraphEnum.ToString());
                stringBuilder.AppendLine("Graph created.");
                stringBuilder.AppendLine(graph.ToString());

                switch (coloredGraphEnum)
                {
                case ColoredGraphEnum.valid:
                    Valid(graph);
                    stringBuilder.AppendLine("Graph modified.");
                    break;

                case ColoredGraphEnum.invalid:
                    Invalid(graph);
                    stringBuilder.AppendLine("Graph modified.");
                    break;

                case ColoredGraphEnum.interchange1:
                case ColoredGraphEnum.interchange2:
                case ColoredGraphEnum.interchange3:
                case ColoredGraphEnum.interchange4:
                case ColoredGraphEnum.interchange5:
                    graph.GetColoredGraph().GreedyColoring(graph.AllVertices(), GraphColoringAlgorithm.GraphColoringAlgorithm.GraphColoringAlgorithInterchangeEnum.interchange);
                    stringBuilder.AppendLine("Graph colored.");
                    break;

                default:
                    throw new MyException.TestsException.TestsMissingTestException(coloredGraphEnum.ToString());
                }

                stringBuilder.AppendLine(graph.GetColoredGraph().ToString());
            }
            catch (KeyNotFoundException)
            {
                throw new MyException.TestsException.TestsMissingTestException(coloredGraphEnum.ToString());
            }
            catch (MyException.GraphException.GraphException e)
            {
                stringBuilder.AppendLine(e.ToString());
            }
        }
Exemplo n.º 14
0
        private void Testing(ConverterGraphToDotEnum converterGraphToDotEnum)
        {
            try
            {
                // Variable
                ConvertGraphToDot convertGraphToDot;

                testPath = ReaderWriter.ReaderWriter.CreateTestFile(testsDictionary[converterGraphToDotEnum]);

                reader = new ReaderWriter.ReaderGraph(testPath, false);
                graph  = reader.ReadFile();

                List <Graph.IGraphInterface> graphList = graph.GetGraphProperty().GetComponents();

                stringBuilder.AppendLine(converterGraphToDotEnum.ToString());
                stringBuilder.AppendLine(graph.ToString());

                stringBuilder.AppendLine("Standard graph");
                convertGraphToDot = new ConvertGraphToDot(graphList, false, true, true, true, true);
                stringBuilder.AppendLine(convertGraphToDot.Convert());

                stringBuilder.AppendLine("Uncolored schedule");
                convertGraphToDot = new ConvertGraphToDot(graphList, true, true, true, true, true);
                stringBuilder.AppendLine(convertGraphToDot.Convert());

                GraphColoringAlgorithm.SequenceAlgorithm.LargestFirstSequence.LargestFirstSequence largestFirstSequence;
                foreach (Graph.IGraphInterface graph in graphList)
                {
                    largestFirstSequence = new GraphColoringAlgorithm.SequenceAlgorithm.LargestFirstSequence.LargestFirstSequence(graph, GraphColoringAlgorithm.GraphColoringAlgorithm.GraphColoringAlgorithInterchangeEnum.none);
                    largestFirstSequence.Color();
                }

                stringBuilder.AppendLine("Colored schedule");
                convertGraphToDot = new ConvertGraphToDot(graphList, true, true, true, true, true);
                stringBuilder.AppendLine(convertGraphToDot.Convert());
            }
            catch (KeyNotFoundException)
            {
                throw new MyException.TestsException.TestsMissingTestException(converterGraphToDotEnum.ToString());
            }
            catch (MyException.ReaderWriterException.ReaderWriterException e)
            {
                stringBuilder.AppendLine(e.Message);
            }
        }
Exemplo n.º 15
0
        private void Testing(BridgesCutVerticesEnum bridgesCutVerticesEnum)
        {
            try
            {
                testPath = ReaderWriter.ReaderWriter.CreateTestFile(testsDictionary[bridgesCutVerticesEnum]);

                reader = new ReaderWriter.ReaderGraph(testPath, false);
                graph  = reader.ReadFile();

                stringBuilder.AppendLine(bridgesCutVerticesEnum.ToString());
                stringBuilder.AppendLine("Graph created.");
                stringBuilder.AppendLine(graph.ToString());

                stringBuilder.AppendLine("Number of cut vertices: " + graph.GetGraphProperty().GetCutVertices().Count);
                stringBuilder.AppendLine("Cut vertices: ");
                graph.GetGraphProperty().GetCutVertices().ForEach(x => { stringBuilder.AppendLine(x.GetUserName()); });
                stringBuilder.AppendLine("Number of bridges: " + graph.GetGraphProperty().GetBridges().Count);
                stringBuilder.AppendLine("Bridges: ");
                graph.GetGraphProperty().GetBridges().ForEach(x => { stringBuilder.AppendLine(x.GetVertex1().GetUserName() + " " + x.GetVertex2().GetUserName()); });

                graph.GetGraphProperty().Reset();
                stringBuilder.AppendLine("Number of cut vertices: " + graph.GetGraphProperty().GetCutVertices().Count);
                stringBuilder.AppendLine("Number of bridges: " + graph.GetGraphProperty().GetBridges().Count);
            }
            catch (KeyNotFoundException)
            {
                throw new MyException.TestsException.TestsMissingTestException(bridgesCutVerticesEnum.ToString());
            }
            catch (MyException.ReaderWriterException.ReaderWriterException e)
            {
                stringBuilder.AppendLine(e.Message);
            }
            catch (MyException.GraphException.GraphIsNotConnected e)
            {
                stringBuilder.AppendLine(e.Message);
            }
        }