Changeset 7822 for branches/ScatterSearch (trunk integration)
- Timestamp:
- 05/15/12 12:14:47 (13 years ago)
- Location:
- branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.VehicleRouting/3.3
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Potvin/Crossovers/PotvinCrossover.cs
r7259 r7822 74 74 } 75 75 76 protected Tour FindRoute(PotvinEncoding solution, int city) {76 protected static Tour FindRoute(PotvinEncoding solution, int city) { 77 77 Tour found = null; 78 78 -
branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Potvin/Crossovers/PotvinRouteBasedCrossover.cs
r7259 r7822 40 40 : base() { } 41 41 42 protected override PotvinEncoding Crossover(IRandom random, PotvinEncoding parent1, PotvinEncoding parent2) { 43 BoolValue useDistanceMatrix = UseDistanceMatrixParameter.ActualValue; 44 DoubleMatrix coordinates = CoordinatesParameter.ActualValue; 45 DistanceMatrix distMatrix = VRPUtilities.GetDistanceMatrix(coordinates, DistanceMatrixParameter, useDistanceMatrix); 46 DoubleArray dueTime = DueTimeParameter.ActualValue; 47 DoubleArray readyTime = ReadyTimeParameter.ActualValue; 48 DoubleArray serviceTime = ServiceTimeParameter.ActualValue; 49 DoubleArray demand = DemandParameter.ActualValue; 50 DoubleValue capacity = CapacityParameter.ActualValue; 42 public static PotvinEncoding Apply(IRandom random, PotvinEncoding parent1, PotvinEncoding parent2, bool allowInfeasible, 43 DoubleArray dueTimeArray, DoubleArray serviceTimeArray, DoubleArray readyTimeArray, DoubleArray demandArray, DoubleValue capacity, 44 DoubleMatrix coordinates, IParameter distanceMatrix, BoolValue useDistanceMatrix) { 45 PotvinEncoding child = parent2.Clone() as PotvinEncoding; 51 46 52 bool allowInfeasible = AllowInfeasibleSolutions.Value.Value; 53 54 PotvinEncoding child = parent2.Clone() as PotvinEncoding; 47 DistanceMatrix distMatrix = VRPUtilities.GetDistanceMatrix(coordinates, distanceMatrix, useDistanceMatrix); 55 48 56 49 int tourParent1 = random.Next(parent1.Tours.Count); … … 67 60 child.Unrouted.Add(city); 68 61 69 if (Repair(random, child, replacing, distMatrix, dueTime, readyTime, serviceTime, demand, capacity, allowInfeasible) || allowInfeasible) 62 if (Repair(random, child, replacing, distMatrix, dueTimeArray, readyTimeArray, serviceTimeArray, 63 demandArray, capacity, allowInfeasible) || allowInfeasible) 70 64 return child; 71 65 else { … … 73 67 return parent1.Clone() as PotvinEncoding; 74 68 else 75 return parent2.Clone() as PotvinEncoding; 69 return parent2.Clone() as PotvinEncoding; 76 70 } 71 } 72 73 protected override PotvinEncoding Crossover(IRandom random, PotvinEncoding parent1, PotvinEncoding parent2) { 74 BoolValue useDistanceMatrix = UseDistanceMatrixParameter.ActualValue; 75 DoubleMatrix coordinates = CoordinatesParameter.ActualValue; 76 DoubleArray dueTime = DueTimeParameter.ActualValue; 77 DoubleArray readyTime = ReadyTimeParameter.ActualValue; 78 DoubleArray serviceTime = ServiceTimeParameter.ActualValue; 79 DoubleArray demand = DemandParameter.ActualValue; 80 DoubleValue capacity = CapacityParameter.ActualValue; 81 82 bool allowInfeasible = AllowInfeasibleSolutions.Value.Value; 83 84 return Apply(random, parent1, parent2, 85 allowInfeasible, dueTime, serviceTime, readyTime, 86 demand, capacity, coordinates, DistanceMatrixParameter, useDistanceMatrix); 77 87 } 78 88 } -
branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Potvin/Crossovers/PotvinSequenceBasedCrossover.cs
r7259 r7822 41 41 : base() { } 42 42 43 protected override PotvinEncoding Crossover(IRandom random, PotvinEncoding parent1, PotvinEncoding parent2) { 44 BoolValue useDistanceMatrix = UseDistanceMatrixParameter.ActualValue; 45 DoubleMatrix coordinates = CoordinatesParameter.ActualValue; 46 DistanceMatrix distMatrix = VRPUtilities.GetDistanceMatrix(coordinates, DistanceMatrixParameter, useDistanceMatrix); 47 DoubleArray dueTime = DueTimeParameter.ActualValue; 48 DoubleArray readyTime = ReadyTimeParameter.ActualValue; 49 DoubleArray serviceTime = ServiceTimeParameter.ActualValue; 50 DoubleArray demand = DemandParameter.ActualValue; 51 DoubleValue capacity = CapacityParameter.ActualValue; 43 public static PotvinEncoding Apply(IRandom random, PotvinEncoding parent1, PotvinEncoding parent2, bool allowInfeasible, 44 DoubleArray dueTimeArray, DoubleArray serviceTimeArray, DoubleArray readyTimeArray, DoubleArray demandArray, DoubleValue capacity, 45 DoubleMatrix coordinates, IParameter distanceMatrix, BoolValue useDistanceMatrix) { 46 PotvinEncoding child = parent1.Clone() as PotvinEncoding; 52 47 53 bool allowInfeasible = AllowInfeasibleSolutions.Value.Value; 48 DistanceMatrix distMatrix = VRPUtilities.GetDistanceMatrix(coordinates, distanceMatrix, useDistanceMatrix); 49 int cities = coordinates.Rows - 1; 54 50 55 PotvinEncoding child = parent1.Clone() as PotvinEncoding;56 51 Tour newTour = new Tour(); 57 52 58 int breakPoint1 = random.Next(1, Cities + 1);53 int breakPoint1 = random.Next(1, cities + 1); 59 54 Tour tour1 = FindRoute(child, breakPoint1); 60 55 breakPoint1 = tour1.Cities.IndexOf(breakPoint1); … … 63 58 newTour.Cities.Add(tour1.Cities[i]); 64 59 65 int breakPoint2 = random.Next(1, Cities + 1);60 int breakPoint2 = random.Next(1, cities + 1); 66 61 Tour tour2 = FindRoute(parent2, breakPoint2); 67 62 breakPoint2 = tour2.Cities.IndexOf(breakPoint2); … … 81 76 child.Unrouted.Add(city); 82 77 83 if (Repair(random, child, newTour, distMatrix, dueTime, readyTime, serviceTime, demand, capacity, allowInfeasible) || allowInfeasible) { 78 if (Repair(random, child, newTour, distMatrix, dueTimeArray, readyTimeArray, serviceTimeArray, 79 demandArray, capacity, allowInfeasible) || allowInfeasible) { 84 80 return child; 85 81 } else { 86 82 if (random.NextDouble() < 0.5) 87 83 return parent1.Clone() as PotvinEncoding; 88 84 else 89 return parent2.Clone() as PotvinEncoding; 90 } 85 return parent2.Clone() as PotvinEncoding; 86 } 87 } 88 89 protected override PotvinEncoding Crossover(IRandom random, PotvinEncoding parent1, PotvinEncoding parent2) { 90 BoolValue useDistanceMatrix = UseDistanceMatrixParameter.ActualValue; 91 DoubleMatrix coordinates = CoordinatesParameter.ActualValue; 92 DistanceMatrix distMatrix = VRPUtilities.GetDistanceMatrix(coordinates, DistanceMatrixParameter, useDistanceMatrix); 93 DoubleArray dueTime = DueTimeParameter.ActualValue; 94 DoubleArray readyTime = ReadyTimeParameter.ActualValue; 95 DoubleArray serviceTime = ServiceTimeParameter.ActualValue; 96 DoubleArray demand = DemandParameter.ActualValue; 97 DoubleValue capacity = CapacityParameter.ActualValue; 98 99 bool allowInfeasible = AllowInfeasibleSolutions.Value.Value; 100 101 return Apply(random, parent1, parent2, 102 allowInfeasible, dueTime, serviceTime, readyTime, 103 demand, capacity, coordinates, DistanceMatrixParameter, useDistanceMatrix); 91 104 } 92 105 } -
branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.VehicleRouting/3.3/PathRelinkers/VRPPathRelinker.cs
r7821 r7822 208 208 209 209 #region moves 210 public static PotvinEncoding RouteBasedXOver(PotvinEncoding initiator, PotvinEncoding guide, IRandom random, 211 IntValue vehicles, DoubleArray dueTimeArray, 212 DoubleArray serviceTimeArray, DoubleArray readyTimeArray, DoubleArray demandArray, DoubleValue capacity, 213 DoubleMatrix coordinates, IParameter distanceMatrix, BoolValue useDistanceMatrix) { 214 return PotvinRouteBasedCrossover.Apply(random, initiator, guide, false, 215 dueTimeArray, serviceTimeArray, readyTimeArray, demandArray, 216 capacity, coordinates, distanceMatrix, useDistanceMatrix); 217 } 218 219 public static PotvinEncoding SequenceBasedXOver(PotvinEncoding initiator, PotvinEncoding guide, IRandom random, 220 IntValue vehicles, DoubleArray dueTimeArray, 221 DoubleArray serviceTimeArray, DoubleArray readyTimeArray, DoubleArray demandArray, DoubleValue capacity, 222 DoubleMatrix coordinates, IParameter distanceMatrix, BoolValue useDistanceMatrix) { 223 return PotvinSequenceBasedCrossover.Apply(random, initiator, guide, false, 224 dueTimeArray, serviceTimeArray, readyTimeArray, demandArray, 225 capacity, coordinates, distanceMatrix, useDistanceMatrix); 226 } 227 228 210 229 public static void GuidedRelocateMove(PotvinEncoding initiator, PotvinEncoding guide, IRandom random) { 211 230 List<int> cities = new List<int>(); … … 468 487 PotvinEncoding next = current.Clone() as PotvinEncoding; 469 488 470 int neighborhood = rand.Next( 2);489 int neighborhood = rand.Next(4); 471 490 switch (neighborhood) { 472 case 0: GuidedRelocateMove(next, guide, rand); 491 case 0: next = RouteBasedXOver(next, guide, rand, 492 vehicles, dueTimeArray, serviceTimeArray, readyTimeArray, demandArray, 493 capacity, coordinates, distanceMatrix, useDistanceMatrix); 473 494 break; 474 case 1: TwoOptMove(next, rand); 495 case 1: next = SequenceBasedXOver(next, guide, rand, 496 vehicles, dueTimeArray, serviceTimeArray, readyTimeArray, demandArray, 497 capacity, coordinates, distanceMatrix, useDistanceMatrix); 498 break; 499 case 2: TwoOptMove(next, rand); 475 500 break; 476 case 2: TwoOptStarMove(next, rand); 477 break; 478 case 3: OrOptMove(next, rand); 479 break; 480 case 4: ExchangeMove(next, rand); 501 case 3: GuidedRelocateMove(next, guide, rand); 481 502 break; 482 503 }
Note: See TracChangeset
for help on using the changeset viewer.