Changeset 7821 for branches/ScatterSearch (trunk integration)
- Timestamp:
- 05/15/12 10:42:00 (13 years ago)
- Location:
- branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.VehicleRouting/3.3
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Alba/LocalImprovement/AlbaLambdaInterchangeLocalImprovementOperator.cs
r7259 r7821 101 101 } 102 102 103 public static void Apply(AlbaEncoding solution, int maxIterations, 103 public static void Apply(AlbaEncoding solution, int maxIterations, bool firstImprovement, 104 104 int lambda, int samples, IRandom random, ref double quality, out int evaluatedSolutions, 105 105 DoubleMatrix distanceMatrix, IntValue vehicles, DoubleArray dueTime, DoubleArray serviceTime, DoubleArray readyTime, … … 110 110 111 111 evaluatedSolutions = 0; 112 113 if (quality == -1) { 114 quality = VRPEvaluator.Evaluate(solution, vehicles, dueTime, serviceTime, readyTime, 115 demand, capacity, fleetUsageFactor, timeFactor, distanceFactor, 116 overloadPenalty, tardinessPenalty, coordinates, 117 distanceMatrixParameter, useDistanceMatrix).Quality; 118 evaluatedSolutions++; 119 } 112 120 113 121 for (int i = 0; i < maxIterations; i++) { … … 126 134 127 135 evaluatedSolutions++; 128 if (moveQuality < quality || quality == -1) {136 if (moveQuality < quality) { 129 137 quality = moveQuality; 130 138 bestMove = move; 139 140 if (firstImprovement) 141 break; 131 142 } 132 143 } … … 155 166 int evaluatedSolutions; 156 167 157 Apply(solution, maxIterations, lambda, samples, random, ref quality, out evaluatedSolutions,168 Apply(solution, maxIterations, false, lambda, samples, random, ref quality, out evaluatedSolutions, 158 169 problem.DistanceMatrix, problem.Vehicles, problem.DueTime, problem.ServiceTime, 159 170 problem.ReadyTime, problem.Demand, problem.Capacity, problem.Coordinates, -
branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.VehicleRouting/3.3/Improvers/VRPImprovementOperator.cs
r7793 r7821 146 146 int evaluatedSolutions; 147 147 148 AlbaLambdaInterchangeLocalImprovementOperator.Apply(solution, ImprovementAttemptsParameter.Value.Value, LambdaParameter.Value.Value,148 AlbaLambdaInterchangeLocalImprovementOperator.Apply(solution, ImprovementAttemptsParameter.Value.Value, true, LambdaParameter.Value.Value, 149 149 SampleSizeParameter.Value.Value, RandomParameter.ActualValue, ref quality, out evaluatedSolutions, DistanceMatrixParameter.ActualValue, 150 150 VehiclesParameter.ActualValue, DueTimeParameter.ActualValue, ServiceTimeParameter.ActualValue, ReadyTimeParameter.ActualValue, -
branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.VehicleRouting/3.3/PathRelinkers/VRPPathRelinker.cs
r7815 r7821 159 159 Parameters.Add(new LookupParameter<DoubleValue>("EvalTardinessPenalty", "The tardiness penalty considered in the evaluation.")); 160 160 Parameters.Add(new LookupParameter<IRandom>("Random", "The pseudo random number generator which should be used for stochastic manipulation operators.")); 161 Parameters.Add(new ValueParameter<IntValue>("SampleSize", new IntValue( 250)));161 Parameters.Add(new ValueParameter<IntValue>("SampleSize", new IntValue(10))); 162 162 Parameters.Add(new ValueParameter<IntValue>("Iterations", new IntValue(50))); 163 163 } … … 208 208 209 209 #region moves 210 public static void GuidedRelocateMove(PotvinEncoding initiator, PotvinEncoding guide, IRandom random) { 211 List<int> cities = new List<int>(); 212 foreach (Tour tour in initiator.Tours) { 213 foreach (int city in tour.Cities) { 214 Tour guideTour = guide.Tours.First(t => t.Cities.Contains(city)); 215 if (guide.Tours.IndexOf(guideTour) != initiator.Tours.IndexOf(tour)) { 216 cities.Add(city); 217 } 218 } 219 } 220 221 if (cities.Count == 0) { 222 RelocateMove(initiator, random); 223 } else { 224 int city = cities[random.Next(cities.Count)]; 225 Tour tour = initiator.Tours.First(t => t.Cities.Contains(city)); 226 tour.Cities.Remove(city); 227 228 Tour guideTour = guide.Tours.First(t => t.Cities.Contains(city)); 229 int guideTourIndex = guide.Tours.IndexOf(guideTour); 230 231 if (guideTourIndex < initiator.Tours.Count) { 232 Tour tour2 = initiator.Tours[guideTourIndex]; 233 234 int guideIndex = guideTour.Cities.IndexOf(city); 235 if (guideIndex == 0) { 236 tour2.Cities.Insert(0, city); 237 } else { 238 int predecessor = guideTour.Cities[guideIndex - 1]; 239 int initIndex = tour2.Cities.IndexOf(predecessor); 240 if (initIndex != -1) { 241 tour2.Cities.Insert(initIndex + 1, city); 242 } else { 243 if (guideIndex == guideTour.Cities.Count - 1) { 244 tour2.Cities.Insert(tour2.Cities.Count, city); 245 } else { 246 int sucessor = guideTour.Cities[guideIndex + 1]; 247 initIndex = tour2.Cities.IndexOf(sucessor); 248 if (initIndex != -1) { 249 tour2.Cities.Insert(initIndex, city); 250 } else { 251 tour2.Cities.Insert(random.Next(tour2.Cities.Count + 1), city); 252 } 253 } 254 } 255 } 256 } else { 257 Tour tour2 = new Tour(); 258 tour2.Cities.Add(city); 259 initiator.Tours.Add(tour2); 260 } 261 262 if (tour.Cities.Count == 0) 263 initiator.Tours.Remove(tour); 264 } 265 } 266 210 267 public static void RelocateMove(PotvinEncoding individual, IRandom random) { 211 268 int cities = individual.Cities; … … 305 362 } 306 363 307 public static void TwoOptStar tMove(PotvinEncoding individual, IRandom random) {364 public static void TwoOptStarMove(PotvinEncoding individual, IRandom random) { 308 365 //consider creating new tour 309 366 individual.Tours.Add(new Tour()); … … 411 468 PotvinEncoding next = current.Clone() as PotvinEncoding; 412 469 413 int neighborhood = rand.Next( 5);470 int neighborhood = rand.Next(2); 414 471 switch (neighborhood) { 415 case 0: RelocateMove(next, rand);472 case 0: GuidedRelocateMove(next, guide, rand); 416 473 break; 417 case 1: ExchangeMove(next, rand);474 case 1: TwoOptMove(next, rand); 418 475 break; 419 case 2: TwoOpt Move(next, rand);476 case 2: TwoOptStarMove(next, rand); 420 477 break; 421 case 3: TwoOptStartMove(next, rand);478 case 3: OrOptMove(next, rand); 422 479 break; 423 case 4: OrOptMove(next, rand);480 case 4: ExchangeMove(next, rand); 424 481 break; 425 482 } 483 484 next = MatchTours(next, guide); 426 485 427 486 TourEvaluation nextEval = VRPEvaluator.Evaluate(next,
Note: See TracChangeset
for help on using the changeset viewer.