예제 #1
0
        public void Graph_BestLocalCostFunction_Success()
        {
            var loaderMock = new Mock <IDataLoader>();

            loaderMock.Setup(m => m.LoadData()).Returns(_dummyFile);

            var randomMock = new StubRandom()
            {
                NextInt32Int32 = (a, b) => 1
            };

            var graph = new MetisGraph(loaderMock.Object, randomMock);

            graph.InitializeGraph();
            graph.InitializeAnts(_optionTwoColors.NumberOfAnts);
            graph.ColorVerticesRandomly(_optionTwoColors.NumberOfPartitions);

            graph.Vertices[0].Color = 1;
            graph.Vertices[1].Color = 1;
            graph.Vertices[2].Color = 1;
            graph.Vertices[3].Color = 2;
            graph.Vertices[4].Color = 1;
            graph.Vertices[5].Color = 2;
            graph.Vertices[6].Color = 2;

            graph.CalculateLocalCostFunction();

            Assert.AreEqual(1D, graph.Vertices[0].LocalCost);
            Assert.AreEqual(0.75, graph.Vertices[1].LocalCost);
            Assert.AreEqual(0.75, graph.Vertices[2].LocalCost);
            Assert.AreEqual(0.5, graph.Vertices[3].LocalCost);
            Assert.AreEqual(0.75, graph.Vertices[4].LocalCost);
            Assert.AreEqual(0.75, graph.Vertices[5].LocalCost);
            Assert.AreEqual(1D, graph.Vertices[6].LocalCost);
        }
예제 #2
0
        public void GraphMetisTest_CalculateGlobalCostFunction_Success()
        {
            var loaderMock = new Mock <IDataLoader>();

            loaderMock.Setup(m => m.LoadData()).Returns(_metisTest);

            var randomMock = new StubRandom()
            {
                NextInt32Int32 = (a, b) => 1
            };

            var graph = new MetisGraph(loaderMock.Object, randomMock);

            graph.InitializeGraph();

            graph.Vertices[0].Color = 2;
            graph.Vertices[1].Color = 2;
            graph.Vertices[2].Color = 2;
            graph.Vertices[3].Color = 1;
            graph.Vertices[4].Color = 2;
            graph.Vertices[5].Color = 1;
            graph.Vertices[6].Color = 1;

            var globalCost = graph.GetGlobalCostFunction();

            Assert.AreEqual(3, globalCost);
        }
예제 #3
0
        public void Graph_KeepBalance_EquallyBalanced()
        {
            var loaderMock = new Mock <IDataLoader>();

            loaderMock.Setup(m => m.LoadData()).Returns(_dummyFile);

            var randomMock = new StubRandom()
            {
                NextInt32Int32 = (a, b) => 1
            };

            var graph = new MetisGraph(loaderMock.Object, randomMock);

            graph.InitializeGraph();
            graph.InitializeAnts(_optionTwoColors.NumberOfAnts);
            graph.ColorVerticesRandomly(_optionTwoColors.NumberOfPartitions);
            Vertex vertexWithAnt   = graph.MoveAntToAnyAdjacentVertex(0);
            int    oldColor        = vertexWithAnt.Color;
            int    vertexWithAntID = vertexWithAnt.ID;
            Vertex newVertex       = graph.ColorVertexWithBestColor(0);

            graph.KeepBalance(_optionTwoColors.NumberOfVerticesForBalance, vertexWithAntID, oldColor, newVertex.Color);

            var numberOfVerticesWithFirstColor  = graph.Vertices.Count(vertex => vertex.Color == 1);
            var numberOfVerticesWithSecondColor = graph.Vertices.Count(vertex => vertex.Color == 2);

            Assert.AreEqual(4, numberOfVerticesWithFirstColor);
            Assert.AreEqual(3, numberOfVerticesWithSecondColor);
        }
예제 #4
0
        public void Graph_UpdateLocalCostFunction_Success()
        {
            var loaderMock = new Mock <IDataLoader>();

            loaderMock.Setup(m => m.LoadData()).Returns(_dummyFile);

            var randomMock = new StubRandom()
            {
                NextInt32Int32 = (a, b) => 1
            };

            var graph = new MetisGraph(loaderMock.Object, randomMock);

            graph.InitializeGraph();
            graph.InitializeAnts(_optionTwoColors.NumberOfAnts);
            graph.ColorVerticesRandomly(_optionTwoColors.NumberOfPartitions);
            Vertex vertexWithAnt          = graph.MoveAntToAnyAdjacentVertex(0);
            int    oldColor               = vertexWithAnt.Color;
            int    vertexWithAntID        = vertexWithAnt.ID;
            Vertex vertexWithNewColor     = graph.ColorVertexWithBestColor(0);
            Vertex vertexWhichKeepBalance = graph.KeepBalance(_optionTwoColors.NumberOfVerticesForBalance, vertexWithAntID,
                                                              oldColor, vertexWithNewColor.Color);

            graph.UpdateLocalCostFunction(vertexWhichKeepBalance, vertexWithNewColor);

            Assert.AreEqual(0.5, graph.Vertices[0].LocalCost);
            Assert.AreEqual(0.5, graph.Vertices[1].LocalCost);
            Assert.AreEqual(0.25, graph.Vertices[2].LocalCost);
            Assert.AreEqual(0D, graph.Vertices[3].LocalCost);
            Assert.AreEqual(0.5, graph.Vertices[4].LocalCost);
            Assert.AreEqual(0.75, graph.Vertices[5].LocalCost);
            Assert.AreEqual(0, graph.Vertices[6].LocalCost);
        }
예제 #5
0
        public void Graph_KeepBalance_CorrectlyColored()
        {
            var loaderMock = new Mock <IDataLoader>();

            loaderMock.Setup(m => m.LoadData()).Returns(_dummyFile);

            var randomMock = new StubRandom()
            {
                NextInt32Int32 = (a, b) => 1
            };

            var graph = new MetisGraph(loaderMock.Object, randomMock);

            graph.InitializeGraph();
            graph.InitializeAnts(_optionTwoColors.NumberOfAnts);
            graph.ColorVerticesRandomly(_optionTwoColors.NumberOfPartitions);
            Vertex vertexWithAnt   = graph.MoveAntToAnyAdjacentVertex(0);
            int    oldColor        = vertexWithAnt.Color;
            int    vertexWithAntID = vertexWithAnt.ID;
            Vertex newVertex       = graph.ColorVertexWithBestColor(0);

            graph.KeepBalance(_optionTwoColors.NumberOfVerticesForBalance, vertexWithAntID, oldColor, newVertex.Color);

            Assert.AreEqual(2, graph.Vertices[0].Color);
            Assert.AreEqual(1, graph.Vertices[1].Color);
            Assert.AreEqual(2, graph.Vertices[2].Color);
            Assert.AreEqual(1, graph.Vertices[3].Color);
            Assert.AreEqual(1, graph.Vertices[4].Color);
            Assert.AreEqual(1, graph.Vertices[5].Color);
            Assert.AreEqual(2, graph.Vertices[6].Color);
        }
예제 #6
0
        public void Graph_ChnageVertexColorWithRandomColor_Success()
        {
            var loaderMock = new Mock <IDataLoader>();

            loaderMock.Setup(m => m.LoadData()).Returns(_dummyFile);

            var randomMock = new StubRandom()
            {
                NextInt32Int32 = (a, b) => 1
            };

            var graph = new MetisGraph(loaderMock.Object, randomMock);

            graph.InitializeGraph();
            graph.InitializeAnts(_optionTwoColors.NumberOfAnts);
            graph.ColorVerticesRandomly(_optionTwoColors.NumberOfPartitions);

            graph.ColorVertexWithRandomColor(0, _optionTwoColors.NumberOfPartitions);

            Assert.AreEqual(1, graph.Vertices[graph.Ants[0]].Color);

            graph.ColorVertexWithRandomColor(1, _optionTwoColors.NumberOfPartitions);

            Assert.AreEqual(1, graph.Vertices[graph.Ants[1]].Color);
        }
예제 #7
0
        public void Graph_MoveAntToAnyAdjacentVertex_Success()
        {
            var loaderMock = new Mock <IDataLoader>();

            loaderMock.Setup(m => m.LoadData()).Returns(_dummyFile);

            var randomMock = new StubRandom()
            {
                NextInt32Int32 = (a, b) => 1
            };

            var graph = new MetisGraph(loaderMock.Object, randomMock);

            graph.InitializeGraph();
            graph.InitializeAnts(_optionTwoColors.NumberOfAnts);
            graph.ColorVerticesRandomly(_optionTwoColors.NumberOfPartitions);
            graph.CalculateLocalCostFunction();

            graph.MoveAntToAnyAdjacentVertex(0);

            Assert.AreEqual(4, graph.Vertices[graph.Ants[0]].ID);

            graph.MoveAntToAnyAdjacentVertex(1);

            Assert.AreEqual(5, graph.Vertices[graph.Ants[1]].ID);
        }
        public void Graph_Vertices_Initialized()
        {
            var loaderMock = new Mock <IDataLoader>();

            loaderMock.Setup(m => m.LoadData()).Returns(_dummyFile);
            var randomMock = new Mock <Random>();

            var graph = new MetisGraph(loaderMock.Object, randomMock.Object);

            graph.InitializeGraph();

            Assert.AreEqual(7, graph.Vertices.Length, "Not all vertices are initialized.");
        }
예제 #9
0
        public void MetisGraph_FirstLineRead_Success()
        {
            var loaderMock = new Mock <IDataLoader>();

            loaderMock.Setup(m => m.LoadData()).Returns(_dummyFile);
            var randomMock = new StubRandom();

            var graph = new MetisGraph(loaderMock.Object, randomMock);

            graph.InitializeGraph();

            Assert.AreEqual(7, graph.Vertices.Length, "The number of vertices weights is not correct.");
            Assert.AreEqual(11, graph.NumberOfEdges, "The number of edges is not correct.");
        }
예제 #10
0
        public void MetisGraph_FirstIteration_Success()
        {
            var loaderMock = new Mock <IDataLoader>();

            loaderMock.Setup(m => m.LoadData()).Returns(_dummyFile);

            var randomMock = new StubRandom()
            {
                NextInt32Int32 = (a, b) => 1
            };

            var graph = new MetisGraph(loaderMock.Object, randomMock);

            graph.InitializeGraph();
            graph.InitializeAnts(_optionTwoColors.NumberOfAnts);
            graph.ColorVerticesRandomly(_optionTwoColors.NumberOfPartitions);
            graph.CalculateLocalCostFunction();

            // First ant.
            Vertex vertexWithFirstAnt         = graph.MoveAntToVertexWithLowestCost(0);
            int    oldColorFirstAnt           = vertexWithFirstAnt.Color;
            int    vertexWithAntIDFirstAnt    = vertexWithFirstAnt.ID;
            Vertex vertexWithNewColorFirstAnt = graph.ColorVertexWithBestColor(0);

            Vertex vertexWhichKeepBalanceFirstAnt = graph.KeepBalance(_optionTwoColors.NumberOfVerticesForBalance,
                                                                      vertexWithAntIDFirstAnt, oldColorFirstAnt, vertexWithNewColorFirstAnt.Color);

            graph.UpdateLocalCostFunction(vertexWhichKeepBalanceFirstAnt, vertexWithNewColorFirstAnt);

            // Second ant.
            Vertex vertexWithSecondAnt         = graph.MoveAntToVertexWithLowestCost(1);
            int    oldColorSecondAnt           = vertexWithSecondAnt.Color;
            int    vertexWithAntIDSecondAnt    = vertexWithSecondAnt.ID;
            Vertex vertexWithNewColorSecondAnt = graph.ColorVertexWithBestColor(1);

            Vertex vertexWhichKeepBalanceSecondAnt = graph.KeepBalance(_optionTwoColors.NumberOfVerticesForBalance,
                                                                       vertexWithAntIDSecondAnt, oldColorSecondAnt, vertexWithNewColorSecondAnt.Color);

            graph.UpdateLocalCostFunction(vertexWhichKeepBalanceSecondAnt, vertexWithNewColorSecondAnt);

            Assert.AreEqual(3 / 4D, graph.Vertices[0].LocalCost);
            Assert.AreEqual(1D, graph.Vertices[1].LocalCost);
            Assert.AreEqual(3 / 4D, graph.Vertices[2].LocalCost);
            Assert.AreEqual(0.5, graph.Vertices[3].LocalCost);
            Assert.AreEqual(0.5, graph.Vertices[4].LocalCost);
            Assert.AreEqual(3 / 4D, graph.Vertices[5].LocalCost);
            Assert.AreEqual(3 / 4D, graph.Vertices[6].LocalCost);
        }
예제 #11
0
        public void Graph_GetConnectedVertcies_Success()
        {
            var loaderMock = new Mock <IDataLoader>();

            loaderMock.Setup(m => m.LoadData()).Returns(_dummyFile);

            var randomMock = new StubRandom()
            {
                NextInt32Int32 = (a, b) => 1
            };

            var graph = new MetisGraph(loaderMock.Object, randomMock);

            graph.InitializeGraph();

            // [0] 5 1 3 2 2 1
            Assert.AreEqual(4, graph.Vertices[0].ConnectedEdges.ElementAt(0).Key);
            Assert.AreEqual(2, graph.Vertices[0].ConnectedEdges.ElementAt(1).Key);
            Assert.AreEqual(1, graph.Vertices[0].ConnectedEdges.ElementAt(2).Key);
            // [1] 1 1 3 2 4 1
            Assert.AreEqual(0, graph.Vertices[1].ConnectedEdges.ElementAt(0).Key);
            Assert.AreEqual(2, graph.Vertices[1].ConnectedEdges.ElementAt(1).Key);
            Assert.AreEqual(3, graph.Vertices[1].ConnectedEdges.ElementAt(2).Key);
            // [2] 5 3 4 2 2 2 1 2
            Assert.AreEqual(4, graph.Vertices[2].ConnectedEdges.ElementAt(0).Key);
            Assert.AreEqual(3, graph.Vertices[2].ConnectedEdges.ElementAt(1).Key);
            Assert.AreEqual(1, graph.Vertices[2].ConnectedEdges.ElementAt(2).Key);
            Assert.AreEqual(0, graph.Vertices[2].ConnectedEdges.ElementAt(3).Key);
            // [3] 2 1 3 2 6 2 7 5
            Assert.AreEqual(1, graph.Vertices[3].ConnectedEdges.ElementAt(0).Key);
            Assert.AreEqual(2, graph.Vertices[3].ConnectedEdges.ElementAt(1).Key);
            Assert.AreEqual(5, graph.Vertices[3].ConnectedEdges.ElementAt(2).Key);
            Assert.AreEqual(6, graph.Vertices[3].ConnectedEdges.ElementAt(3).Key);
            // [4] 1 1 3 3 6 2
            Assert.AreEqual(0, graph.Vertices[4].ConnectedEdges.ElementAt(0).Key);
            Assert.AreEqual(2, graph.Vertices[4].ConnectedEdges.ElementAt(1).Key);
            Assert.AreEqual(5, graph.Vertices[4].ConnectedEdges.ElementAt(2).Key);
            // [5] 5 2 4 2 7 6
            Assert.AreEqual(4, graph.Vertices[5].ConnectedEdges.ElementAt(0).Key);
            Assert.AreEqual(3, graph.Vertices[5].ConnectedEdges.ElementAt(1).Key);
            Assert.AreEqual(6, graph.Vertices[5].ConnectedEdges.ElementAt(2).Key);
            // [6] 6 6 4 5
            Assert.AreEqual(5, graph.Vertices[6].ConnectedEdges.ElementAt(0).Key);
            Assert.AreEqual(3, graph.Vertices[6].ConnectedEdges.ElementAt(1).Key);
        }
예제 #12
0
        public void Graph_InitializeAntsSeparately_Success()
        {
            var loaderMock = new Mock <IDataLoader>();

            loaderMock.Setup(m => m.LoadData()).Returns(_dummyFile);
            var randomMock = new StubRandom()
            {
                NextInt32Int32 = (a, b) => 1
            };

            var graph = new MetisGraph(loaderMock.Object, randomMock);

            graph.InitializeGraph();
            graph.InitializeAnts(_optionTwoColors.NumberOfAnts);

            Assert.AreEqual(0, graph.Ants[0]);
            Assert.AreEqual(6, graph.Ants[1]);
        }
        public void Graph_VerticesWeights_Initalized()
        {
            var loaderMock = new Mock <IDataLoader>();

            loaderMock.Setup(m => m.LoadData()).Returns(_dummyFile);
            var randomMock = new Mock <Random>();

            var graph = new MetisGraph(loaderMock.Object, randomMock.Object);

            graph.InitializeGraph();

            Assert.AreEqual(4, graph.Vertices[0].Weight);
            Assert.AreEqual(2, graph.Vertices[1].Weight);
            Assert.AreEqual(5, graph.Vertices[2].Weight);
            Assert.AreEqual(3, graph.Vertices[3].Weight);
            Assert.AreEqual(1, graph.Vertices[4].Weight);
            Assert.AreEqual(6, graph.Vertices[5].Weight);
            Assert.AreEqual(2, graph.Vertices[6].Weight);
        }
예제 #14
0
        public void Graph_GlobalCostFunction_OneColor()
        {
            var loaderMock = new Mock <IDataLoader>();

            loaderMock.Setup(m => m.LoadData()).Returns(_dummyFile);

            var randomMock = new StubRandom()
            {
                NextInt32Int32 = (a, b) => 1
            };

            var graph = new MetisGraph(loaderMock.Object, randomMock);

            graph.InitializeGraph();
            graph.ColorVerticesRandomly(_optionOneColors.NumberOfPartitions);
            var globalCost = graph.GetGlobalCostFunction();

            Assert.AreEqual(0, globalCost);
        }
        public void Graph_InitializeEdgesSeparately_Success()
        {
            var loaderMock = new Mock <IDataLoader>();

            loaderMock.Setup(m => m.LoadData()).Returns(_dummyFile);
            var randomMock = new Mock <Random>();

            var graph = new MetisGraph(loaderMock.Object, randomMock.Object);

            graph.InitializeGraph();

            // [0] 5 1 3 2 2 1
            Assert.AreEqual(1, graph.Vertices[0].ConnectedEdges.ElementAt(0).Value);
            Assert.AreEqual(2, graph.Vertices[0].ConnectedEdges.ElementAt(1).Value);
            Assert.AreEqual(1, graph.Vertices[0].ConnectedEdges.ElementAt(2).Value);
            // [1] 1 1 3 2 4 1
            Assert.AreEqual(1, graph.Vertices[1].ConnectedEdges.ElementAt(0).Value);
            Assert.AreEqual(2, graph.Vertices[1].ConnectedEdges.ElementAt(1).Value);
            Assert.AreEqual(1, graph.Vertices[1].ConnectedEdges.ElementAt(2).Value);
            // [2] 5 3 4 2 2 2 1 2
            Assert.AreEqual(3, graph.Vertices[2].ConnectedEdges.ElementAt(0).Value);
            Assert.AreEqual(2, graph.Vertices[2].ConnectedEdges.ElementAt(1).Value);
            Assert.AreEqual(2, graph.Vertices[2].ConnectedEdges.ElementAt(2).Value);
            Assert.AreEqual(2, graph.Vertices[2].ConnectedEdges.ElementAt(3).Value);
            // [3] 2 1 3 2 6 2 7 5
            Assert.AreEqual(1, graph.Vertices[3].ConnectedEdges.ElementAt(0).Value);
            Assert.AreEqual(2, graph.Vertices[3].ConnectedEdges.ElementAt(1).Value);
            Assert.AreEqual(2, graph.Vertices[3].ConnectedEdges.ElementAt(2).Value);
            Assert.AreEqual(5, graph.Vertices[3].ConnectedEdges.ElementAt(3).Value);
            // [4] 1 1 3 3 6 2
            Assert.AreEqual(1, graph.Vertices[4].ConnectedEdges.ElementAt(0).Value);
            Assert.AreEqual(3, graph.Vertices[4].ConnectedEdges.ElementAt(1).Value);
            Assert.AreEqual(2, graph.Vertices[4].ConnectedEdges.ElementAt(2).Value);
            // [5] 5 2 4 2 7 6
            Assert.AreEqual(2, graph.Vertices[5].ConnectedEdges.ElementAt(0).Value);
            Assert.AreEqual(2, graph.Vertices[5].ConnectedEdges.ElementAt(1).Value);
            Assert.AreEqual(6, graph.Vertices[5].ConnectedEdges.ElementAt(2).Value);
            // [6] 6 6 4 5
            Assert.AreEqual(6, graph.Vertices[6].ConnectedEdges.ElementAt(0).Value);
            Assert.AreEqual(5, graph.Vertices[6].ConnectedEdges.ElementAt(1).Value);
        }
예제 #16
0
        public void Graph_RandomColorEachVertex_ThreeColors()
        {
            var loaderMock = new Mock <IDataLoader>();

            loaderMock.Setup(m => m.LoadData()).Returns(_dummyFile);

            var randomMock = new StubRandom()
            {
                NextInt32Int32 = (a, b) => 1
            };

            var graph = new MetisGraph(loaderMock.Object, randomMock);

            graph.InitializeGraph();
            graph.ColorVerticesRandomly(_optionThreeColors.NumberOfPartitions);

            Assert.AreEqual(1, graph.Vertices[0].Color);
            Assert.AreEqual(1, graph.Vertices[1].Color);
            Assert.AreEqual(3, graph.Vertices[2].Color);
            Assert.AreEqual(2, graph.Vertices[3].Color);
            Assert.AreEqual(1, graph.Vertices[4].Color);
            Assert.AreEqual(3, graph.Vertices[5].Color);
            Assert.AreEqual(2, graph.Vertices[6].Color);
        }
예제 #17
0
        // part -t 0 -i "Graphs\DIMACS\myciel3.col" -a 1 -p 2 -c 0.9 -m 0.85 -s 6 -d 100
        // part -t 0 -i "Graphs\DIMACS\le450_15b.col" -a 5 -p 29 -c 0.9 -m 0.85 -s 6 -d 1
        // part -t 1 -i "Graphs\manual.txt" -a 1 -p 2 -c 0.9 -m 0.85 -s 4 -d 100
        static int Main(string[] args)
        {
            XmlConfigurator.Configure();

            Func <PartitionGraphOptions, int> partitionFunc = options =>
            {
                var rnd         = new Random(Environment.TickCount);
                var fileWriter  = new FileWriter("graph.json");
                var exportGraph = new GephiFileExport(fileWriter, Path.GetFileNameWithoutExtension(options.InputGraphFilePath));

                var       fileLoader = new FileLoader(options.InputGraphFilePath);
                BaseGraph graph;
                switch (options.ImportGraphFileType)
                {
                case GraphInputFileType.Dimacs:
                    graph = new DimacsGraph(fileLoader, rnd);
                    break;

                case GraphInputFileType.Metis:
                    graph = new MetisGraph(fileLoader, rnd);
                    break;

                case GraphInputFileType.MetisUnweighted:
                    graph = new MetisUnweightedGraph(fileLoader, rnd);
                    break;

                default:
                    throw new ApplicationException("Graph file format is not suppoted.");
                }

                var graphOptions = new Options(options.NumberOfAnts, options.NumberOfPartitions, options.ColoringProbability,
                                               options.MovingProbability, options.NumberOfVerticesForBalance, options.NumberOfIterations);

                ResultData resultData = Algorithm.Run(graph, graphOptions, rnd, exportGraph);
                return(resultData.BestCost);
            };

            var result = Parser.Default.ParseArguments <PartitionGraphOptions>(args);

            var exitCode = result.MapResult(options =>
            {
                if (options.Verbose)
                {
                    Console.WriteLine("Write additional information.");
                }
                else
                {
                    Console.WriteLine("Processing...");

                    var stopwatch = new Stopwatch();
                    stopwatch.Start();

                    var bestCost = partitionFunc(options);

                    stopwatch.Stop();
                    Log.Warn($"Algoritham run time: {stopwatch.ElapsedMilliseconds}");
                    Log.Warn($"Best cost: {bestCost}");

                    Console.WriteLine($"{args[0]} | {bestCost}");
                }
                return(0);
            }, errors => 1);

            return(exitCode);
        }
예제 #18
0
        public void Graph_AntOneFullRun()
        {
            var loaderMock = new Mock <IDataLoader>();

            loaderMock.Setup(m => m.LoadData()).Returns(_dummyFile);

            var randomMock = new StubRandom()
            {
                NextInt32Int32 = (a, b) => 1
            };

            var graph = new MetisGraph(loaderMock.Object, randomMock);

            graph.InitializeGraph();
            graph.InitializeAnts(_optionTwoColors.NumberOfAnts);
            graph.ColorVerticesRandomly(_optionTwoColors.NumberOfPartitions);
            graph.CalculateLocalCostFunction();

            Assert.AreEqual(1 / 2D, graph.Vertices[0].LocalCost);
            Assert.AreEqual(3 / 4D, graph.Vertices[1].LocalCost);
            Assert.AreEqual(1 / 4D, graph.Vertices[2].LocalCost);
            Assert.AreEqual(1 / 2D, graph.Vertices[3].LocalCost);
            Assert.AreEqual(1 / 2D, graph.Vertices[4].LocalCost);
            Assert.AreEqual(1 / 2D, graph.Vertices[5].LocalCost);
            Assert.AreEqual(1 / 2D, graph.Vertices[6].LocalCost);


            var globalCost = graph.GetGlobalCostFunction();

            Assert.AreEqual(7, globalCost);

            Vertex vertexWithAnt = graph.MoveAntToVertexWithLowestCost(0);

            Assert.AreEqual(2, vertexWithAnt.ID);

            int    oldColor           = vertexWithAnt.Color;
            int    vertexWithAntID    = vertexWithAnt.ID;
            Vertex vertexWithNewColor = graph.ColorVertexWithBestColor(0);

            Assert.AreEqual(1, vertexWithNewColor.Color);

            Vertex vertexWhichKeepBalance = graph.KeepBalance(_optionTwoColors.NumberOfVerticesForBalance, vertexWithAntID, oldColor, vertexWithNewColor.Color);

            Assert.AreEqual(2, graph.Vertices[0].Color);
            Assert.AreEqual(1, graph.Vertices[1].Color);
            Assert.AreEqual(1, graph.Vertices[2].Color);
            Assert.AreEqual(1, graph.Vertices[3].Color);
            Assert.AreEqual(2, graph.Vertices[4].Color);
            Assert.AreEqual(1, graph.Vertices[5].Color);
            Assert.AreEqual(2, graph.Vertices[6].Color);

            graph.UpdateLocalCostFunction(vertexWhichKeepBalance, vertexWithNewColor);

            Assert.AreEqual(0.5, graph.Vertices[0].LocalCost);
            Assert.AreEqual(0.75, graph.Vertices[1].LocalCost);
            Assert.AreEqual(0.5, graph.Vertices[2].LocalCost);
            Assert.AreEqual(0.75, graph.Vertices[3].LocalCost);
            Assert.AreEqual(0.5, graph.Vertices[4].LocalCost);
            Assert.AreEqual(0.5, graph.Vertices[5].LocalCost);
            Assert.AreEqual(0.5, graph.Vertices[6].LocalCost);

            var globalCostAfterMove = graph.GetGlobalCostFunction();

            Assert.AreEqual(6, globalCostAfterMove);
        }