public void TestOneShiftViolatedBackward() { // 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.MoveViolatedBackward(problem, objective, route, out delta)); // shifts 2 after 0. // test result. Assert.AreEqual(1, delta); Assert.AreEqual(new int[] { 0, 2, 1, 3, 4 }, route.ToArray()); // create a route with one shift. route = new Optimization.Tours.Tour(new int[] { 0, 4, 1, 3, 2 }, 0); // apply the 1-shift local search, it should find the customer to replocate. Assert.IsTrue(localSearch.MoveViolatedBackward(problem, objective, route, out delta)); // shifts 2 after 0 // test result. Assert.AreEqual(5, delta); Assert.AreEqual(new int[] { 0, 2, 4, 1, 3 }, 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.MoveViolatedBackward(problem, objective, route, out delta)); }