Changeset 10744 for stable/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Manipulators/PotvinPairwiseOneLevelExchangeManipulator.cs
- Timestamp:
- 04/14/14 10:04:43 (11 years ago)
- Location:
- stable
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
stable
- Property svn:mergeinfo changed
/trunk/sources merged: 10435,10460,10475,10651-10652
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Problems.VehicleRouting
- Property svn:mergeinfo changed
/trunk/sources/HeuristicLab.Problems.VehicleRouting merged: 10435,10460,10475,10651
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Manipulators/PotvinPairwiseOneLevelExchangeManipulator.cs
r9456 r10744 25 25 using HeuristicLab.Problems.VehicleRouting.ProblemInstances; 26 26 using HeuristicLab.Problems.VehicleRouting.Variants; 27 using HeuristicLab.Problems.VehicleRouting.Interfaces; 27 28 28 29 namespace HeuristicLab.Problems.VehicleRouting.Encodings.Potvin { … … 43 44 } 44 45 45 public bool PairwiseMove(PotvinEncoding individual, int city, bool allowInfeasible) {46 public static bool PairwiseMove(PotvinEncoding individual, IVRPProblemInstance instance, int city, bool allowInfeasible) { 46 47 bool success; 47 48 48 IPickupAndDeliveryProblemInstance pdp = ProblemInstance as IPickupAndDeliveryProblemInstance;49 IPickupAndDeliveryProblemInstance pdp = instance as IPickupAndDeliveryProblemInstance; 49 50 50 51 if (pdp != null) { … … 64 65 65 66 int source, target; 66 if ( ProblemInstance.GetDemand(city) >= 0) {67 if (instance.GetDemand(city) >= 0) { 67 68 source = city; 68 69 target = dest; … … 80 81 if (tourIdx != routeToAvoid) { 81 82 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); 85 86 86 87 double delta = evalNew.Quality - eval.Quality; 87 88 88 89 if (delta < bestQuality && 89 ( ProblemInstance.Feasible(evalNew) || allowInfeasible)) {90 (instance.Feasible(evalNew) || allowInfeasible)) { 90 91 bestQuality = delta; 91 92 bestTour = tourIdx; … … 127 128 } 128 129 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 129 151 protected override void Manipulate(IRandom random, PotvinEncoding individual) { 130 152 bool allowInfeasible = AllowInfeasibleSolutions.Value.Value; 153 131 154 IPickupAndDeliveryProblemInstance pdp = ProblemInstance as IPickupAndDeliveryProblemInstance; 132 155 133 156 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); 151 158 } 152 159 }
Note: See TracChangeset
for help on using the changeset viewer.