Exemplo n.º 1
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);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
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);
        }
Exemplo n.º 8
0
        public void RollTestMockRandom()
        {
            var generator = new StubRandom();
            var die       = new Die(generator, DieShape.D6);

            die.Roll();

            Assert.True(die.FaceValue == StubRandom.DEFAULT_VALUE);
        }
Exemplo n.º 9
0
        public void AddDieTest()
        {
            var generator = new StubRandom();
            var die       = new Die(generator);
            var shaker    = new Shaker();

            shaker.AddDie(die);
            Assert.True(shaker.Dice.Count == 1);
        }
Exemplo n.º 10
0
        public void ShakeTest()
        {
            var generator = new StubRandom();
            var die       = new Die(generator);
            var shaker    = new Shaker();

            shaker.AddDie(die);
            shaker.Shake();
            Assert.True(shaker.Dice.First().FaceValue == StubRandom.DEFAULT_VALUE);
        }
Exemplo n.º 11
0
        public void ShakeTest()
        {
            var  generator = new StubRandom();
            Game game      = new Game(generator);

            game.Shake();

            Assert.True(game.Die1.FaceValue != null);
            Assert.True(game.Die2.FaceValue != null);
        }
        public void DimacsGraph_Vertices_Initialized()
        {
            var loaderMock = new Mock <IDataLoader>();

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

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

            graph.InitializeGraph();

            Assert.AreEqual(11, graph.Vertices.Length, "Not all vertices are initialized.");
        }
        public void DimacsGraph_MaxNumberOfAdjacentVertices_Correct()
        {
            var loaderMock = new Mock <IDataLoader>();

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

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

            graph.InitializeGraph();

            Assert.AreEqual(5, graph.MaxNumberOfAdjacentVertices, "The number of maximum adjacent vertices of one vertex is not calculatef correctly.");
        }
Exemplo n.º 14
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.");
        }
Exemplo n.º 15
0
        public void DimacsMyciel4_GetSumOfOptimalityCriterion_34()
        {
            var loaderMock = new Mock <IDataLoader>();

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

            var graph = new DimacsGraph(loaderMock.Object);

            graph.InitializeGraph();

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

            var options = new BaseOptions(numberOfIterations: 100, numberOfRegions: 2, alfa: 1, beta: 5, ro: 0.6, delta: 0.1D);

            var fragment = new UnweightedAntSystemFragmentFake(randomMock, options, graph);

            fragment.ClearTreil();
            fragment.Treil[0].Add(new Vertex(4, 1));
            fragment.Treil[0].Add(new Vertex(8, 1));
            fragment.Treil[0].Add(new Vertex(9, 1));
            fragment.Treil[0].Add(new Vertex(11, 1));
            fragment.Treil[0].Add(new Vertex(12, 1));
            fragment.Treil[0].Add(new Vertex(14, 1));
            fragment.Treil[0].Add(new Vertex(17, 1));
            fragment.Treil[0].Add(new Vertex(18, 1));
            fragment.Treil[0].Add(new Vertex(19, 1));
            fragment.Treil[0].Add(new Vertex(21, 1));
            fragment.Treil[0].Add(new Vertex(22, 1));

            fragment.Treil[1].Add(new Vertex(0, 1));
            fragment.Treil[1].Add(new Vertex(1, 1));
            fragment.Treil[1].Add(new Vertex(2, 1));
            fragment.Treil[1].Add(new Vertex(3, 1));
            fragment.Treil[1].Add(new Vertex(5, 1));
            fragment.Treil[1].Add(new Vertex(6, 1));
            fragment.Treil[1].Add(new Vertex(7, 1));
            fragment.Treil[1].Add(new Vertex(10, 1));
            fragment.Treil[1].Add(new Vertex(13, 1));
            fragment.Treil[1].Add(new Vertex(15, 1));
            fragment.Treil[1].Add(new Vertex(16, 1));
            fragment.Treil[1].Add(new Vertex(20, 1));

            var globalCost = fragment.SumOfOptimalityCriterion;

            Assert.AreEqual(34, globalCost);
        }
Exemplo n.º 16
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);
        }
Exemplo n.º 17
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);
        }
Exemplo n.º 18
0
        public void GraphQueen5_5_CalculateGlobalCostFunction_Success()
        {
            var loaderMock = new Mock <IDataLoader>();

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

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

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

            graph.InitializeGraph();

            graph.Vertices[0].Color  = 2;
            graph.Vertices[1].Color  = 2;
            graph.Vertices[2].Color  = 1;
            graph.Vertices[3].Color  = 1;
            graph.Vertices[4].Color  = 1;
            graph.Vertices[5].Color  = 2;
            graph.Vertices[6].Color  = 2;
            graph.Vertices[7].Color  = 1;
            graph.Vertices[8].Color  = 2;
            graph.Vertices[9].Color  = 2;
            graph.Vertices[10].Color = 1;
            graph.Vertices[11].Color = 1;
            graph.Vertices[12].Color = 2;
            graph.Vertices[13].Color = 2;
            graph.Vertices[14].Color = 2;
            graph.Vertices[15].Color = 2;
            graph.Vertices[16].Color = 1;
            graph.Vertices[17].Color = 1;
            graph.Vertices[18].Color = 2;
            graph.Vertices[19].Color = 2;
            graph.Vertices[20].Color = 2;
            graph.Vertices[21].Color = 1;
            graph.Vertices[22].Color = 1;
            graph.Vertices[23].Color = 1;
            graph.Vertices[24].Color = 1;

            var globalCost = graph.GetGlobalCostFunction();

            Assert.AreEqual(84, globalCost);
        }
Exemplo n.º 19
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]);
        }
Exemplo n.º 20
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);
        }
Exemplo n.º 21
0
        public void GraphMyciel4_CalculateGlobalCostFunction_28()
        {
            var loaderMock = new Mock <IDataLoader>();

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

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

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

            graph.InitializeGraph();

            graph.Vertices[0].Color  = 1;
            graph.Vertices[1].Color  = 1;
            graph.Vertices[2].Color  = 1;
            graph.Vertices[3].Color  = 0;
            graph.Vertices[4].Color  = 1;
            graph.Vertices[5].Color  = 0;
            graph.Vertices[6].Color  = 0;
            graph.Vertices[7].Color  = 0;
            graph.Vertices[8].Color  = 0;
            graph.Vertices[9].Color  = 0;
            graph.Vertices[10].Color = 0;
            graph.Vertices[11].Color = 0;
            graph.Vertices[12].Color = 1;
            graph.Vertices[13].Color = 1;
            graph.Vertices[14].Color = 1;
            graph.Vertices[15].Color = 0;
            graph.Vertices[16].Color = 0;
            graph.Vertices[17].Color = 1;
            graph.Vertices[18].Color = 1;
            graph.Vertices[19].Color = 1;
            graph.Vertices[20].Color = 0;
            graph.Vertices[21].Color = 0;
            graph.Vertices[22].Color = 1;

            var globalCost = graph.GetGlobalCostFunction();

            Assert.AreEqual(28, globalCost);
        }
Exemplo n.º 22
0
        public void Graph_VerticesWeights_Initalized()
        {
            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(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);
        }
Exemplo n.º 23
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);
        }
Exemplo n.º 24
0
        public void RollTestInvalidSides()
        {
            var generator = new StubRandom();

            Assert.Throws <ArgumentException>(() => new Die(generator, 0));
        }
Exemplo n.º 25
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);
        }