예제 #1
0
        public void RouteCostTest()
        {
            // Arrange
            DataImporter dataImporter = new DataImporter();

            // Act
            // Parse vrp file and create DepotManager
            dataImporter.ImportFromFile(@".\A-n37-k6.vrp");

            // Get DepotManager from DataImporter
            DepotManager dm = dataImporter.GetManager();

            List <int[]> locations = new List <int[]>();

            int[] tmp1 = { 7, 25, 35, 16 };
            locations.Add(tmp1);

            int[] tmp2 = { 18, 31, 19, 9, 21, 26 };
            locations.Add(tmp2);

            int[] tmp3 = { 14, 6, 36, 29, 24 };
            locations.Add(tmp3);

            int[] tmp4 = { 33, 2, 28, 23, 22, 12, 11, 10, 4 };
            locations.Add(tmp4);

            int[] tmp5 = { 13, 30, 15, 32, 27 };
            locations.Add(tmp5);

            int[] tmp6 = { 20, 8, 5, 3, 1, 34, 17 };
            locations.Add(tmp6);

            int totalCost = 0;

            Node depot = dm.Depot;

            foreach (int[] tmp in locations)
            {
                Truck truck = new Truck(depot, 0);

                for (int i = tmp.Length - 1; i >= 0; i--)
                {
                    truck.AddNodeAfter(truck.Head, dm.GetClient(tmp[i]));
                }

                totalCost += truck.CalcCost();
            }

            // Assert
            Assert.AreEqual(949, totalCost);
        }