public void TestWindowsValidOnlyWithWait() { // create problem. var problem = TSPTWHelper.CreateDirectedTSPTW(0, 0, 5, 10, 1); problem.Windows[1] = new TimeWindow() { Min = 5, Max = 15 }; problem.Windows[2] = new TimeWindow() { Min = 15, Max = 25 }; problem.Windows[3] = new TimeWindow() { Min = 35, // wait here until it's '35'. Max = 45 }; problem.Windows[4] = new TimeWindow() { Min = 45, Max = 55 }; // calculate objective function. var objective = new TSPTWFeasibleObjective(); Assert.AreEqual(0, objective.Calculate(problem, new Optimization.Tours.Tour(new int[] { 0, 4, 8, 12, 16 }))); }
public void TestWindowsOneInvalid() { // create problem. var problem = TSPTWHelper.CreateDirectedTSPTW(0, 0, 5, 10, 1); problem.Windows[1] = new TimeWindow() { Min = 5, Max = 15 }; problem.Windows[2] = new TimeWindow() { Min = 15, Max = 25 }; problem.Windows[3] = new TimeWindow() { Min = 25, Max = 29 // invalid max. }; problem.Windows[4] = new TimeWindow() { Min = 35, Max = 45 }; // calculate objective function. var objective = new TSPTWFeasibleObjective(); Assert.AreEqual(1, objective.Calculate(problem, new Optimization.Tours.Tour(new int[] { 0, 4, 8, 12, 16 }))); }
public void TestOneShiftNonViolatedForward() { // create the problem and make sure 0->1->2->3->4 is the solution. var objective = new TSPTWFeasibleObjective(); var problem = TSPTWHelper.CreateTSPTW(0, 0, 5, 2); problem.Windows[2] = new TimeWindow() { Min = 1, Max = 3 }; // create a route with one shift. var route = new Optimization.Tours.Tour(new int[] { 0, 1, 2, 3, 4 }, 0); // apply the 1-shift local search, it should find the customer to replocate. var localSearch = new Local1Shift <TSPTWFeasibleObjective>(); var delta = 0.0f; Assert.IsTrue(localSearch.MoveNonViolatedForward(problem, objective, route, out delta)); // shifts 1 after 2. // test result. Assert.AreEqual(1, delta); Assert.AreEqual(new int[] { 0, 2, 1, 3, 4 }, route.ToArray()); // create a feasible route. route = new Optimization.Tours.Tour(new int[] { 0, 2, 4, 1, 3 }, 0); // apply the 1-shift local search, it should find the customer to replocate. Assert.IsFalse(localSearch.MoveNonViolatedForward(problem, objective, route, out delta)); }
public void TestFixedViolatedUnmovableCustomerValidBackward() { // create the problem and make sure 0->1->2->3->4 is the solution. var objective = new TSPTWFeasibleObjective(); var problem = TSPTWHelper.CreateTSPTW(0, 4, 5, 10); problem.Times[0][1] = 2; problem.Times[1][2] = 2; problem.Times[2][3] = 2; problem.Times[3][4] = 2; problem.Times[4][0] = 2; problem.Windows[4] = new TimeWindow() { Min = 7, Max = 9 }; // create a route with one shift. var route = new Optimization.Tours.Tour(new int[] { 0, 1, 3, 2, 4 }, 0); // apply the 1-shift local search, it should find the customer to replocate. var localSearch = new Local1Shift <TSPTWFeasibleObjective>(); var delta = 0.0f; Assert.IsTrue(localSearch.MoveNonViolatedBackward(problem, objective, route, out delta)); // shifts 2 after 1 // test result. Assert.AreEqual(23, delta); Assert.AreEqual(new int[] { 0, 1, 2, 3, 4 }, route.ToArray()); }
public void TestWindowsValid() { // create problem. var problem = TSPTWHelper.CreateTSPTW(0, 0, 5, 10); problem.Windows[1] = new TimeWindow() { Min = 5, Max = 15 }; problem.Windows[2] = new TimeWindow() { Min = 15, Max = 25 }; problem.Windows[3] = new TimeWindow() { Min = 25, Max = 35 }; problem.Windows[4] = new TimeWindow() { Min = 35, Max = 45 }; // calculate objective function. var objective = new TSPTWFeasibleObjective(); Assert.AreEqual(0, objective.Calculate(problem, new Optimization.Tours.Tour(new int[] { 0, 1, 2, 3, 4 }))); }
public void TestNoWindows() { // create problem. var problem = TSPTWHelper.CreateDirectedTSPTW(0, 0, 5, 10, 1); // calculate objective function. var objective = new TSPTWFeasibleObjective(); Assert.AreEqual(0, objective.Calculate(problem, new Optimization.Tours.Tour(new int[] { 0, 4, 8, 12, 16 }))); }
public void TestOneShiftViolatedForward() { // create the problem and make sure 0->1->2->3->4 is the solution. var objective = new TSPTWFeasibleObjective(); var problem = TSPTWHelper.CreateDirectedTSPTW(0, 0, 5, 10, 1); problem.Times.SetWeight(0, 3, 1, 1, 1, 1); // [0][3] = 1; problem.Times.SetWeight(3, 1, 1, 1, 1, 1); // [3][1] = 1; problem.Windows[1] = new TimeWindow() { Min = 1, Max = 3 }; problem.Windows[3] = new TimeWindow() { Min = 0, Max = 2 }; // create a route with one shift. var route = new Optimization.Tours.Tour(new int[] { 0, 4, 12, 8, 16 }, 0); // apply the 1-shift local search, it should find the customer to replocate. var localSearch = new Local1Shift <TSPTWFeasibleObjective>(); var delta = 0.0f; Assert.IsTrue(localSearch.MoveViolatedForward(problem, objective, route, out delta)); // shifts 4 after 12. // test result. Assert.AreEqual(25, delta); Assert.AreEqual(new int[] { 0, 12, 4, 8, 16 }, route.ToArray()); // create a feasible route. route = new Optimization.Tours.Tour(new int[] { 0, 12, 4, 8, 16 }, 0); // apply the 1-shift local search, it should find the customer to replocate. Assert.IsFalse(localSearch.MoveViolatedForward(problem, objective, route, out delta)); }