示例#1
0
        public void TestFixedViolatedUnmovableCustomerValidForward()
        {
            // 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.Apply(problem, objective, route, out delta)); // shifts 3 after 2

            // test result.
            Assert.AreEqual(23, delta);
            Assert.AreEqual(new int[] { 0, 1, 2, 3, 4 }, route.ToArray());
        }
示例#2
0
        public void Test2TwoShiftsClosed()
        {
            // create the problem and make sure 0->1->2->3->4 is the solution.
            var problem = TSPHelper.CreateTSP(0, 0, 5, 10);

            problem.Weights[0][1] = 1;
            problem.Weights[1][2] = 1;
            problem.Weights[2][3] = 1;
            problem.Weights[3][4] = 1;
            problem.Weights[4][0] = 1;

            // create a route with one shift.
            var 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.
            var localSearch = new Local1Shift();
            var delta       = 0.0f;

            localSearch.Apply(problem, new TSPObjective(), route, out delta);

            // test result.
            Assert.AreEqual(-45, delta);
            Assert.AreEqual(new int[] { 0, 1, 2, 3, 4 }, route.ToArray());
        }