Ignore:
Timestamp:
05/10/12 15:31:22 (7 years ago)
Author:
svonolfe
Message:

Improved PDP moves (#1177)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Moves/PickupDelivery/PDShift/PotvinPDShiftMoveMaker.cs

    r7080 r7791  
    3030using HeuristicLab.Problems.VehicleRouting.Interfaces;
    3131using HeuristicLab.Problems.VehicleRouting.Variants;
     32using System.Collections.Generic;
    3233
    3334namespace HeuristicLab.Problems.VehicleRouting.Encodings.Potvin {
     
    6061
    6162    public static void Apply(PotvinEncoding solution, PotvinPDShiftMove move, IVRPProblemInstance problemInstance) {
    62       if (move.Tour >= solution.Tours.Count)
     63      bool newTour = false;
     64
     65      if (move.Tour >= solution.Tours.Count) {
    6366        solution.Tours.Add(new Tour());
     67        newTour = true;
     68      }
    6469      Tour tour = solution.Tours[move.Tour];
    6570
     
    8085      }
    8186
     87      if (newTour) {
     88        List<int> vehicles = new List<int>();
     89        for (int i = move.Tour; i < problemInstance.Vehicles.Value; i++) {
     90          vehicles.Add(solution.GetVehicleAssignment(i));
     91        }
     92
     93        double bestQuality = double.MaxValue;
     94        int bestVehicle = -1;
     95
     96        int originalVehicle = solution.GetVehicleAssignment(move.Tour);
     97        foreach (int vehicle in vehicles) {
     98          solution.VehicleAssignment[move.Tour] = vehicle;
     99
     100          double quality = problemInstance.EvaluateTour(tour, solution).Quality;
     101          if (quality < bestQuality) {
     102            bestQuality = quality;
     103            bestVehicle = vehicle;
     104          }
     105        }
     106
     107        solution.VehicleAssignment[move.Tour] = originalVehicle;
     108
     109        int index = -1;
     110        for (int i = move.Tour; i < solution.VehicleAssignment.Length; i++) {
     111          if (solution.VehicleAssignment[i] == bestVehicle) {
     112            index = i;
     113            break;
     114          }
     115        }
     116        solution.VehicleAssignment[index] = originalVehicle;
     117        solution.VehicleAssignment[move.Tour] = bestVehicle;
     118      }
     119
    82120      solution.Repair();
    83121    }
Note: See TracChangeset for help on using the changeset viewer.