Changeset 11202 for branches/HiveStatistics/sources/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Manipulators/PotvinPairwiseTwoLevelExchangeManipulator.cs
- Timestamp:
- 07/18/14 12:01:13 (10 years ago)
- Location:
- branches/HiveStatistics/sources
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HiveStatistics/sources
- Property svn:ignore
-
old new 8 8 FxCopResults.txt 9 9 Google.ProtocolBuffers-0.9.1.dll 10 Google.ProtocolBuffers-2.4.1.473.dll 10 11 HeuristicLab 3.3.5.1.ReSharper.user 11 12 HeuristicLab 3.3.6.0.ReSharper.user 12 13 HeuristicLab.4.5.resharper.user 13 14 HeuristicLab.ExtLibs.6.0.ReSharper.user 15 HeuristicLab.Scripting.Development 14 16 HeuristicLab.resharper.user 15 17 ProtoGen.exe … … 17 19 _ReSharper.HeuristicLab 18 20 _ReSharper.HeuristicLab 3.3 21 _ReSharper.HeuristicLab 3.3 Tests 19 22 _ReSharper.HeuristicLab.ExtLibs 20 23 bin 21 24 protoc.exe 22 _ReSharper.HeuristicLab 3.3 Tests23 Google.ProtocolBuffers-2.4.1.473.dll
-
- Property svn:mergeinfo changed
- Property svn:ignore
-
branches/HiveStatistics/sources/HeuristicLab.Problems.VehicleRouting
- Property svn:mergeinfo changed
-
branches/HiveStatistics/sources/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Manipulators/PotvinPairwiseTwoLevelExchangeManipulator.cs
r8231 r11202 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 2Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 26 26 using HeuristicLab.Problems.VehicleRouting.ProblemInstances; 27 27 using HeuristicLab.Problems.VehicleRouting.Variants; 28 using HeuristicLab.Problems.VehicleRouting.Interfaces; 28 29 29 30 namespace HeuristicLab.Problems.VehicleRouting.Encodings.Potvin { … … 44 45 } 45 46 46 private PotvinEncoding ReplacePair(PotvinEncoding individual, int replaced, int replacing, bool allowInfeasible) {47 private static PotvinEncoding ReplacePair(PotvinEncoding individual, IVRPProblemInstance instance, int replaced, int replacing, bool allowInfeasible) { 47 48 individual = individual.Clone() as PotvinEncoding; 48 IPickupAndDeliveryProblemInstance pdp = ProblemInstance as IPickupAndDeliveryProblemInstance;49 IPickupAndDeliveryProblemInstance pdp = instance as IPickupAndDeliveryProblemInstance; 49 50 50 51 int replacedDest = pdp.GetPickupDeliveryLocation(replaced); … … 76 77 77 78 replacedSourceTour.Stops[replacedSourceTour.Stops.IndexOf(replacedSource)] = replacingSource; 78 if (!allowInfeasible && ! ProblemInstance.TourFeasible(replacedSourceTour, individual))79 if (!allowInfeasible && !instance.TourFeasible(replacedSourceTour, individual)) 79 80 return null; 80 81 81 82 replacedTargetTour.Stops[replacedTargetTour.Stops.IndexOf(replacedTarget)] = replacingTarget; 82 if (!allowInfeasible && ! ProblemInstance.TourFeasible(replacedTargetTour, individual))83 if (!allowInfeasible && !instance.TourFeasible(replacedTargetTour, individual)) 83 84 return null; 84 85 … … 93 94 if (tourIdx != routeToAvoid) { 94 95 Tour tour = individual.Tours[tourIdx]; 95 VRPEvaluation eval = ProblemInstance.EvaluateTour(tour, individual);96 individual.InsertPair(tour, replacedSource, replacedTarget, ProblemInstance);97 VRPEvaluation evalNew = ProblemInstance.EvaluateTour(tour, individual);96 VRPEvaluation eval = instance.EvaluateTour(tour, individual); 97 individual.InsertPair(tour, replacedSource, replacedTarget, instance); 98 VRPEvaluation evalNew = instance.EvaluateTour(tour, individual); 98 99 99 100 double delta = evalNew.Quality - eval.Quality; 100 101 101 102 if (delta < bestQuality && 102 ( ProblemInstance.Feasible(evalNew) || allowInfeasible)) {103 (instance.Feasible(evalNew) || allowInfeasible)) { 103 104 bestQuality = delta; 104 105 bestTour = tourIdx; … … 127 128 } 128 129 130 public static PotvinEncoding ApplyManipulation(IRandom random, PotvinEncoding individual, IPickupAndDeliveryProblemInstance pdp, bool allowInfeasible) { 131 PotvinEncoding result = null; 132 133 int selectedIndex = SelectRandomTourBiasedByLength(random, individual, pdp); 134 if (selectedIndex >= 0) { 135 bool performed = false; 136 Tour route1 = individual.Tours[selectedIndex]; 137 138 if (route1.Stops.Count > 0) { 139 //randomize customer selection 140 Permutation perm = new Permutation(PermutationTypes.Absolute, route1.Stops.Count, random); 141 int customer1Position = 0; 142 143 while (customer1Position < route1.Stops.Count) { 144 performed = false; 145 146 int customer1 = route1.Stops[perm[customer1Position]]; 147 int customer2 = -1; 148 149 for (int i = 0; i < individual.Tours.Count; i++) { 150 if (i != selectedIndex) { 151 Tour tour = individual.Tours[i]; 152 for (int customer2Position = 0; customer2Position < tour.Stops.Count; customer2Position++) { 153 customer2 = tour.Stops[customer2Position]; 154 155 if (pdp.GetPickupDeliveryLocation(customer1) != customer2) { 156 result = ReplacePair(individual, pdp, customer2, customer1, allowInfeasible); 157 if (result != null) { 158 individual = result; 159 160 route1 = individual.Tours[selectedIndex]; 161 performed = true; 162 break; 163 } 164 } 165 } 166 } 167 168 if (performed) { 169 break; 170 } 171 } 172 173 if (!performed) 174 customer1Position++; 175 else 176 break; 177 } 178 } 179 } 180 181 return result; 182 } 183 129 184 protected override void Manipulate(IRandom random, PotvinEncoding individual) { 130 185 bool allowInfeasible = AllowInfeasibleSolutions.Value.Value; … … 132 187 133 188 if (pdp != null) { 134 int selectedIndex = SelectRandomTourBiasedByLength(random, individual); 135 if (selectedIndex >= 0) { 136 bool performed = false; 137 Tour route1 = individual.Tours[selectedIndex]; 138 139 if (route1.Stops.Count > 0) { 140 //randomize customer selection 141 Permutation perm = new Permutation(PermutationTypes.Absolute, route1.Stops.Count, random); 142 int customer1Position = 0; 143 144 while (customer1Position < route1.Stops.Count) { 145 performed = false; 146 147 int customer1 = route1.Stops[perm[customer1Position]]; 148 int customer2 = -1; 149 150 for (int i = 0; i < individual.Tours.Count; i++) { 151 if (i != selectedIndex) { 152 Tour tour = individual.Tours[i]; 153 for (int customer2Position = 0; customer2Position < tour.Stops.Count; customer2Position++) { 154 customer2 = tour.Stops[customer2Position]; 155 156 if (pdp.GetPickupDeliveryLocation(customer1) != customer2) { 157 PotvinEncoding result = ReplacePair(individual, customer2, customer1, allowInfeasible); 158 if (result != null) { 159 VRPToursParameter.ActualValue = result; 160 individual = result; 161 162 route1 = individual.Tours[selectedIndex]; 163 performed = true; 164 break; 165 } 166 } 167 } 168 } 169 170 if (performed) { 171 break; 172 } 173 } 174 175 if (!performed) 176 customer1Position++; 177 else 178 break; 179 } 180 } 181 } 189 PotvinEncoding result = ApplyManipulation(random, individual, pdp, allowInfeasible); 190 if (result != null) { 191 VRPToursParameter.ActualValue = result; 192 } 182 193 } 183 194 }
Note: See TracChangeset
for help on using the changeset viewer.