public void Test1MoveImpossible() { // create the problem and make sure 0->1->2->3->4 is the solution. var objective = new TSPTWObjective(); var problem = TSPTWHelper.CreateTSPTW(0, 0, 5, 10); problem.Times[0][1] = 1; problem.Times[0][3] = 2; problem.Times[1][2] = 1; problem.Times[2][3] = 1; problem.Times[3][4] = 1; problem.Times[4][0] = 1; problem.Times[3][1] = 100; problem.Windows[3] = new TimeWindow() { Min = 1, Max = 2 }; problem.Windows[2] = new TimeWindow() { Min = 11, Max = 12 }; var route = new Optimization.Tours.Tour(new int[] { 0, 3, 2, 1, 4 }, 0); var localSearch = new Local2Opt(); var delta = 0.0f; Assert.IsFalse(localSearch.Apply(problem, objective, route, out delta)); }
public void Test1MoveImpossible() { // create the problem and make sure 0->1->2->3->4 is the solution. var objective = new TSPTWObjective(); var problem = TSPTWHelper.CreateDirectedTSPTW(0, 0, 5, 10, 1); problem.Times.SetWeight(0, 1, 1); problem.Times.SetWeight(0, 3, 2); problem.Times.SetWeight(1, 2, 1); problem.Times.SetWeight(2, 3, 1); problem.Times.SetWeight(3, 4, 1); problem.Times.SetWeight(4, 0, 1); problem.Times.SetWeight(3, 1, 100); problem.Windows[3] = new TimeWindow() { Min = 1, Max = 2 }; problem.Windows[2] = new TimeWindow() { Min = 11, Max = 12 }; var route = new Optimization.Tours.Tour(new int[] { 0, 13, 9, 4, 16 }, 0); var localSearch = new Local2Opt(); var delta = 0.0f; Assert.IsFalse(localSearch.Apply(problem, objective, route, out delta)); }
public void Test1MovePossible() { // create the problem and make sure 0->1->2->3->4 is the solution. var objective = new TSPTWObjective(); var problem = TSPTWHelper.CreateTSPTW(0, 0, 5, 10); problem.Times[0][1] = 1; problem.Times[1][2] = 1; problem.Times[2][3] = 1; problem.Times[3][4] = 1; problem.Times[4][0] = 1; problem.Times[3][1] = 100; var route = new Optimization.Tours.Tour(new int[] { 0, 3, 2, 1, 4 }, 0); var localSearch = new Local2Opt(); var delta = 0.0f; Assert.IsTrue(localSearch.Apply(problem, objective, route, out delta)); // test result. Assert.AreEqual(36, delta); Assert.AreEqual(new int[] { 0, 1, 2, 3, 4 }, route.ToArray()); }
public void Test1MovePossible() { // create the problem and make sure 0->1->2->3->4 is the solution. var objective = new TSPTWObjective(); var problem = TSPTWHelper.CreateDirectedTSPTW(0, 0, 5, 10, 1); problem.Times.SetWeight(0, 1, 1); problem.Times.SetWeight(1, 2, 1); problem.Times.SetWeight(2, 3, 1); problem.Times.SetWeight(3, 4, 1); problem.Times.SetWeight(4, 0, 1); problem.Times.SetWeight(3, 1, 100); var route = new Optimization.Tours.Tour(new int[] { 0, 13, 9, 5, 17 }, 0); var localSearch = new Local2Opt(); var delta = 0.0f; Assert.IsTrue(localSearch.Apply(problem, objective, route, out delta)); // test result. Assert.AreEqual(42, delta); Assert.AreEqual(new int[] { 0, 4, 8, 12, 17 }, route.ToArray()); }