public void Graph_ChnageVertexColorWithBestColor_Success() { var loaderMock = new Mock <IDataLoader>(); loaderMock.Setup(m => m.LoadData()).Returns(_dummyFile); var randomMock = new Mock <Random>(); randomMock.Setup(s => s.Next(It.IsAny <int>(), It.IsAny <int>())).Returns(1); var graph = new DimacsGraph(loaderMock.Object, randomMock.Object); graph.InitializeGraph(); graph.InitializeAnts(_optionTwoColors.NumberOfAnts); graph.ColorVerticesRandomly(_optionTwoColors.NumberOfPartitions); graph.CalculateLocalCostFunction(); graph.MoveAntToVertexWithLowestCost(0); graph.ColorVertexWithBestColor(0); Assert.AreEqual(1, graph.Vertices[graph.Ants[0]].Color); graph.MoveAntToVertexWithLowestCost(1); graph.ColorVertexWithBestColor(1); Assert.AreEqual(2, graph.Vertices[graph.Ants[1]].Color); }
public void MetisGraph_FirstIteration_Success() { var loaderMock = new Mock <IDataLoader>(); loaderMock.Setup(m => m.LoadData()).Returns(_dummyFile); var randomMock = new Mock <Random>(); randomMock.Setup(s => s.Next(It.IsAny <int>(), It.IsAny <int>())).Returns(1); var graph = new DimacsGraph(loaderMock.Object, randomMock.Object); 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); }
public void Graph_AntOneFullRun() { var loaderMock = new Mock <IDataLoader>(); loaderMock.Setup(m => m.LoadData()).Returns(_dummyFile); var randomMock = new Mock <Random>(); randomMock.Setup(s => s.Next(It.IsAny <int>(), It.IsAny <int>())).Returns(1); var graph = new DimacsGraph(loaderMock.Object, randomMock.Object); 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); }