Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/14/14 10:04:43 (11 years ago)
Author:
pfleck
Message:

#2152: merged r10435, r10460, r10475, r10651,r10652 into stable

Location:
stable
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.Problems.VehicleRouting

  • stable/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Manipulators/PotvinPairwiseOneLevelExchangeManipulator.cs

    r9456 r10744  
    2525using HeuristicLab.Problems.VehicleRouting.ProblemInstances;
    2626using HeuristicLab.Problems.VehicleRouting.Variants;
     27using HeuristicLab.Problems.VehicleRouting.Interfaces;
    2728
    2829namespace HeuristicLab.Problems.VehicleRouting.Encodings.Potvin {
     
    4344    }
    4445
    45     public bool PairwiseMove(PotvinEncoding individual, int city, bool allowInfeasible) {
     46    public static bool PairwiseMove(PotvinEncoding individual, IVRPProblemInstance instance, int city, bool allowInfeasible) {
    4647      bool success;
    4748
    48       IPickupAndDeliveryProblemInstance pdp = ProblemInstance as IPickupAndDeliveryProblemInstance;
     49      IPickupAndDeliveryProblemInstance pdp = instance as IPickupAndDeliveryProblemInstance;
    4950
    5051      if (pdp != null) {
     
    6465
    6566        int source, target;
    66         if (ProblemInstance.GetDemand(city) >= 0) {
     67        if (instance.GetDemand(city) >= 0) {
    6768          source = city;
    6869          target = dest;
     
    8081          if (tourIdx != routeToAvoid) {
    8182            Tour tour = individual.Tours[tourIdx];
    82             VRPEvaluation eval = ProblemInstance.EvaluateTour(tour, individual);
    83             individual.InsertPair(tour, source, target, ProblemInstance);
    84             VRPEvaluation evalNew = ProblemInstance.EvaluateTour(tour, individual);
     83            VRPEvaluation eval = instance.EvaluateTour(tour, individual);
     84            individual.InsertPair(tour, source, target, instance);
     85            VRPEvaluation evalNew = instance.EvaluateTour(tour, individual);
    8586
    8687            double delta = evalNew.Quality - eval.Quality;
    8788
    8889            if (delta < bestQuality &&
    89                (ProblemInstance.Feasible(evalNew) || allowInfeasible)) {
     90               (instance.Feasible(evalNew) || allowInfeasible)) {
    9091              bestQuality = delta;
    9192              bestTour = tourIdx;
     
    127128    }
    128129
     130    public static void ApplyManipulation(IRandom random, PotvinEncoding individual, IPickupAndDeliveryProblemInstance pdp, bool allowInfeasible) {
     131      int selectedIndex = SelectRandomTourBiasedByLength(random, individual, pdp);
     132      if (selectedIndex >= 0) {
     133        Tour route1 =
     134          individual.Tours[selectedIndex];
     135
     136        int count = route1.Stops.Count;
     137
     138        if (count > 0) {
     139          int i = random.Next(0, count);
     140          int city = route1.Stops[i];
     141
     142          if (!PairwiseMove(individual, pdp, city, allowInfeasible))
     143            i++;
     144
     145          count = route1.Stops.Count;
     146        }
     147      }
     148    }
     149
     150
    129151    protected override void Manipulate(IRandom random, PotvinEncoding individual) {
    130152      bool allowInfeasible = AllowInfeasibleSolutions.Value.Value;
     153
    131154      IPickupAndDeliveryProblemInstance pdp = ProblemInstance as IPickupAndDeliveryProblemInstance;
    132155
    133156      if (pdp != null) {
    134         int selectedIndex = SelectRandomTourBiasedByLength(random, individual);
    135         if (selectedIndex >= 0) {
    136           Tour route1 =
    137             individual.Tours[selectedIndex];
    138 
    139           int count = route1.Stops.Count;
    140 
    141           if (count > 0) {
    142             int i = random.Next(0, count);
    143             int city = route1.Stops[i];
    144 
    145             if (!PairwiseMove(individual, city, allowInfeasible))
    146               i++;
    147 
    148             count = route1.Stops.Count;
    149           }
    150         }
     157        ApplyManipulation(random, individual, pdp, allowInfeasible);
    151158      }
    152159    }
Note: See TracChangeset for help on using the changeset viewer.