Esempio n. 1
0
        public void TestSecondClosed()
        {
            var weights       = WeightsHelper.CreateDirected(5, 10);
            var turnPenalties = new float[] { 0, 2, 2, 0 };

            var tour = new Tour(new int[] { 0 }, 0);
            var cost = tour.InsertCheapestDirected(weights, turnPenalties, 1);

            Assert.AreEqual(20, cost);
            Assert.AreEqual(new int[] { 0, 4 }, tour);

            tour = new Tour(new int[] { 1 }, 1);
            cost = tour.InsertCheapestDirected(weights, turnPenalties, 1);
            Assert.AreEqual(20, cost);
            Assert.AreEqual(new int[] { 0, 4 }, tour);

            tour = new Tour(new int[] { 2 }, 2);
            cost = tour.InsertCheapestDirected(weights, turnPenalties, 1);
            Assert.AreEqual(20, cost);
            Assert.AreEqual(new int[] { 0, 4 }, tour);

            tour = new Tour(new int[] { 3 }, 3);
            cost = tour.InsertCheapestDirected(weights, turnPenalties, 1);
            Assert.AreEqual(20, cost);
            Assert.AreEqual(new int[] { 0, 4 }, tour);
        }
Esempio n. 2
0
        public void TestTurnCostHandling()
        {
            var weights = WeightsHelper.CreateDirected(5, 10);

            weights.SetWeight(0, 1, 5);
            weights.SetWeight(1, 2, 5);
            weights.SetWeight(2, 3, 5);
            weights.SetWeight(3, 4, 5);
            var turnPenalties = new float[] { 0, 2, 2, 0 };

            var tour   = new Tour(new int[] { 1, 5, 13 }, null);
            var weight = tour.Weight(weights, turnPenalties);
            var cost   = tour.InsertCheapestDirected(weights, turnPenalties, 2);

            Assert.AreEqual(-2, cost);
            Assert.AreEqual(weight + cost, tour.Weight(weights, turnPenalties));
            Assert.AreEqual(new int[] { 1, 4, 8, 13 }, tour);

            tour   = new Tour(new int[] { 1, 5, 13 }, 13);
            weight = tour.Weight(weights, turnPenalties);
            cost   = tour.InsertCheapestDirected(weights, turnPenalties, 2);
            Assert.AreEqual(-2, cost);
            Assert.AreEqual(weight + cost, tour.Weight(weights, turnPenalties));
            Assert.AreEqual(new int[] { 1, 4, 8, 13 }, tour);

            tour   = new Tour(new int[] { 1, 5, 13 }, 1);
            weight = tour.Weight(weights, turnPenalties);
            cost   = tour.InsertCheapestDirected(weights, turnPenalties, 2);
            Assert.AreEqual(-4, cost);
            Assert.AreEqual(weight + cost, tour.Weight(weights, turnPenalties));
            Assert.AreEqual(new int[] { 1, 4, 8, 15 }, tour);
        }
Esempio n. 3
0
        public void TestThirdOpenFixed()
        {
            var weights       = WeightsHelper.CreateDirected(5, 10);
            var turnPenalties = new float[] { 0, 2, 2, 0 };

            var tour = new Tour(new int[] { 0, 8 }, 8);
            var cost = tour.InsertCheapestDirected(weights, turnPenalties, 1);

            Assert.AreEqual(10, cost);
            Assert.AreEqual(new int[] { 0, 4, 8 }, tour);

            tour = new Tour(new int[] { 0, 10 }, 10);
            cost = tour.InsertCheapestDirected(weights, turnPenalties, 1);
            Assert.AreEqual(10, cost);
            Assert.AreEqual(new int[] { 0, 4, 8 }, tour);
        }
Esempio n. 4
0
        public void TestWeight()
        {
            var weights       = WeightsHelper.CreateDirected(5, 10);
            var turnPenalties = new float[] { 0, 2, 2, 0 };

            // open ended.
            Assert.AreEqual(10, (new Tour(new int[] { 1, 9 }, null)).Weight(
                                weights, turnPenalties));
            Assert.AreEqual(22, (new Tour(new int[] { 1, 5, 9 }, null)).Weight(
                                weights, turnPenalties));

            // open but fixed ended.
            Assert.AreEqual(10, (new Tour(new int[] { 1, 9 }, 9)).Weight(
                                weights, turnPenalties));
            Assert.AreEqual(22, (new Tour(new int[] { 1, 5, 9 }, 9)).Weight(
                                weights, turnPenalties));

            // closed.
            Assert.AreEqual(24, (new Tour(new int[] { 1, 9 }, 1)).Weight(
                                weights, turnPenalties));
            Assert.AreEqual(36, (new Tour(new int[] { 1, 5, 9 }, 1)).Weight(
                                weights, turnPenalties));
        }