Changeset 7822 for branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.VehicleRouting/3.3/Encodings
- Timestamp:
- 05/15/12 12:14:47 (13 years ago)
- Location:
- branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Potvin/Crossovers
- Files:
-
- 3 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 }
Note: See TracChangeset
for help on using the changeset viewer.