Free cookie consent management tool by TermsFeed Policy Generator

Changeset 6966 for branches/VRP


Ignore:
Timestamp:
11/08/11 12:46:51 (13 years ago)
Author:
svonolfe
Message:

Improved compatibility of pairwise operators (#1177)

Location:
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Manipulators
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Manipulators/PotvinPairwiseOneLevelExchangeManipulator.cs

    r6960 r6966  
    133133    protected override void Manipulate(IRandom random, PotvinEncoding individual) {
    134134      bool allowInfeasible = AllowInfeasibleSolutions.Value.Value;
     135      IPickupAndDeliveryProblemInstance pdp = ProblemInstance as IPickupAndDeliveryProblemInstance;
    135136
    136       int selectedIndex = SelectRandomTourBiasedByLength(random, individual);
    137       if (selectedIndex >= 0) {
    138         Tour route1 =
    139           individual.Tours[selectedIndex];
     137      if (pdp != null) {
     138        int selectedIndex = SelectRandomTourBiasedByLength(random, individual);
     139        if (selectedIndex >= 0) {
     140          Tour route1 =
     141            individual.Tours[selectedIndex];
    140142
    141         int count = route1.Stops.Count;
     143          int count = route1.Stops.Count;
    142144
    143         if (count > 0) {
    144           int i = random.Next(0, count);
    145           int city = route1.Stops[i];
     145          if (count > 0) {
     146            int i = random.Next(0, count);
     147            int city = route1.Stops[i];
    146148
    147           if (!PairwiseMove(individual, city, allowInfeasible))
    148             i++;
     149            if (!PairwiseMove(individual, city, allowInfeasible))
     150              i++;
    149151
    150           count = route1.Stops.Count;
     152            count = route1.Stops.Count;
     153          }
    151154        }
    152155      }
  • branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Manipulators/PotvinPairwiseTwoLevelExchangeManipulator.cs

    r6960 r6966  
    125125    }
    126126
    127     protected override void Manipulate(IRandom random, PotvinEncoding individual) {     
     127    protected override void Manipulate(IRandom random, PotvinEncoding individual) {
    128128      bool allowInfeasible = AllowInfeasibleSolutions.Value.Value;
    129129      IPickupAndDeliveryProblemInstance pdp = ProblemInstance as IPickupAndDeliveryProblemInstance;
    130130
    131       int selectedIndex = SelectRandomTourBiasedByLength(random, individual);
    132       if (selectedIndex >= 0) {
    133         bool performed = false;
    134         Tour route1 = individual.Tours[selectedIndex];
     131      if (pdp != null) {
     132        int selectedIndex = SelectRandomTourBiasedByLength(random, individual);
     133        if (selectedIndex >= 0) {
     134          bool performed = false;
     135          Tour route1 = individual.Tours[selectedIndex];
    135136
    136         if (route1.Stops.Count > 0) {
    137           //randomize customer selection
    138           Permutation perm = new Permutation(PermutationTypes.Absolute, route1.Stops.Count, random);
    139           int customer1Position = 0;
     137          if (route1.Stops.Count > 0) {
     138            //randomize customer selection
     139            Permutation perm = new Permutation(PermutationTypes.Absolute, route1.Stops.Count, random);
     140            int customer1Position = 0;
    140141
    141           while (customer1Position < route1.Stops.Count) {
    142             performed = false;
     142            while (customer1Position < route1.Stops.Count) {
     143              performed = false;
    143144
    144             int customer1 = route1.Stops[perm[customer1Position]];
    145             int customer2 = -1;
     145              int customer1 = route1.Stops[perm[customer1Position]];
     146              int customer2 = -1;
    146147
    147             for (int i = 0; i < individual.Tours.Count; i++) {
    148               if (i != selectedIndex) {
    149                 Tour tour = individual.Tours[i];
    150                 for (int customer2Position = 0; customer2Position < tour.Stops.Count; customer2Position++) {
    151                   customer2 = tour.Stops[customer2Position];
     148              for (int i = 0; i < individual.Tours.Count; i++) {
     149                if (i != selectedIndex) {
     150                  Tour tour = individual.Tours[i];
     151                  for (int customer2Position = 0; customer2Position < tour.Stops.Count; customer2Position++) {
     152                    customer2 = tour.Stops[customer2Position];
    152153
    153                   if (pdp.GetPickupDeliveryLocation(customer1) != customer2) {
    154                     PotvinEncoding result = ReplacePair(individual, customer2, customer1, allowInfeasible);
    155                     if (result != null) {
    156                       VRPToursParameter.ActualValue = result;
    157                       individual = result;
     154                    if (pdp.GetPickupDeliveryLocation(customer1) != customer2) {
     155                      PotvinEncoding result = ReplacePair(individual, customer2, customer1, allowInfeasible);
     156                      if (result != null) {
     157                        VRPToursParameter.ActualValue = result;
     158                        individual = result;
    158159
    159                       route1 = individual.Tours[selectedIndex];
    160                       performed = true;
    161                       break;
     160                        route1 = individual.Tours[selectedIndex];
     161                        performed = true;
     162                        break;
     163                      }
    162164                    }
    163165                  }
    164166                }
     167
     168                if (performed) {
     169                  break;
     170                }
    165171              }
    166172
    167               if (performed) {
     173              if (!performed)
     174                customer1Position++;
     175              else
    168176                break;
    169               }
    170177            }
    171 
    172             if (!performed)
    173               customer1Position++;
    174             else
    175               break;
    176178          }
    177179        }
Note: See TracChangeset for help on using the changeset viewer.