Changeset 6459 for trunk/sources/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Potvin/Crossovers
- Timestamp:
- 06/21/11 10:27:03 (13 years ago)
- Location:
- trunk/sources/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Potvin/Crossovers
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Potvin/Crossovers/PotvinCrossover.cs
r6455 r6459 36 36 } 37 37 38 public IValueParameter<BoolValue> AllowInfeasibleSolutions { 39 get { return (IValueParameter<BoolValue>)Parameters["AllowInfeasibleSolutions"]; } 40 } 41 42 [StorableHook(HookType.AfterDeserialization)] 43 private void AfterDeserialization() { 44 // BackwardsCompatibility3.3 45 #region Backwards compatible code (remove with 3.4) 46 if (!Parameters.ContainsKey("AllowInfeasibleSolutions")) { 47 Parameters.Add(new ValueParameter<BoolValue>("AllowInfeasibleSolutions", "Indicates if infeasible solutions should be allowed.", new BoolValue(false))); 48 } 49 #endregion 50 } 51 38 52 [StorableConstructor] 39 53 protected PotvinCrossover(bool deserializing) : base(deserializing) { } … … 44 58 public PotvinCrossover() { 45 59 Parameters.Add(new LookupParameter<IRandom>("Random", "The pseudo random number generator which should be used for stochastic manipulation operators.")); 60 Parameters.Add(new ValueParameter<BoolValue>("AllowInfeasibleSolutions", "Indicates if infeasible solutions should be allowed.", new BoolValue(false))); 46 61 } 47 62 … … 50 65 protected static bool FindInsertionPlace(PotvinEncoding individual, int city, 51 66 DoubleArray dueTime, DoubleArray serviceTime, DoubleArray readyTime, DoubleArray demand, 52 DoubleValue capacity, DistanceMatrix distMatrix, 67 DoubleValue capacity, DistanceMatrix distMatrix, bool allowInfeasible, 53 68 out int route, out int place) { 54 69 return individual.FindInsertionPlace( 55 70 dueTime, serviceTime, readyTime, 56 71 demand, capacity, distMatrix, 57 city, -1, out route, out place); 72 city, -1, allowInfeasible, 73 out route, out place); 58 74 } 59 75 … … 72 88 73 89 protected static bool RouteUnrouted(PotvinEncoding solution, DistanceMatrix distMatrix, 74 DoubleArray dueTime, DoubleArray readyTime, DoubleArray serviceTime, DoubleArray demand, DoubleValue capacity ) {90 DoubleArray dueTime, DoubleArray readyTime, DoubleArray serviceTime, DoubleArray demand, DoubleValue capacity, bool allowInfeasible) { 75 91 bool success = true; 76 92 int index = 0; … … 81 97 if (FindInsertionPlace(solution, unrouted, 82 98 dueTime, serviceTime, readyTime, demand, capacity, 83 distMatrix, 99 distMatrix, allowInfeasible, 84 100 out route, out place)) { 85 101 solution.Tours[route].Cities.Insert(place, unrouted); … … 98 114 99 115 protected static bool Repair(IRandom random, PotvinEncoding solution, Tour newTour, DistanceMatrix distmatrix, 100 DoubleArray dueTime, DoubleArray readyTime, DoubleArray serviceTime, DoubleArray demand, DoubleValue capacity) { 116 DoubleArray dueTime, DoubleArray readyTime, DoubleArray serviceTime, DoubleArray demand, DoubleValue capacity, 117 bool allowInfeasible) { 101 118 bool success = true; 102 119 … … 134 151 } 135 152 136 if (! newTour.Feasible(153 if (!allowInfeasible && !newTour.Feasible( 137 154 dueTime, serviceTime, readyTime, demand, capacity, distmatrix)) 138 155 return false; 139 156 140 157 //route unrouted vehicles 141 success = RouteUnrouted(solution, distmatrix, dueTime, readyTime, serviceTime, demand, capacity );158 success = RouteUnrouted(solution, distmatrix, dueTime, readyTime, serviceTime, demand, capacity, allowInfeasible); 142 159 143 160 return success; -
trunk/sources/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Potvin/Crossovers/PotvinInsertionBasedCrossover.cs
r6455 r6459 157 157 DoubleArray dueTimeArray, 158 158 DoubleArray serviceTimeArray, DoubleArray readyTimeArray, DoubleArray demandArray, DoubleValue capacity, 159 DistanceMatrix distMatrix, 160 int city, out int place) { 159 DistanceMatrix distMatrix, int city, bool allowInfeasible, out int place) { 161 160 place = -1; 162 161 bool bestFeasible = false; … … 171 170 capacity, distMatrix); 172 171 173 if ( !bestFeasible || feasible) {172 if ((!allowInfeasible && feasible) || (allowInfeasible && (!bestFeasible || feasible))) { 174 173 double newLength = tour.GetLength(distMatrix); 175 174 double detour = newLength - length; 176 175 177 if (place <= 0 || (!(bestFeasible && !feasible)) && detour < minDetour || (feasible && !bestFeasible)) { 176 if (place <= 0 || detour < minDetour || 177 (allowInfeasible && ((!(bestFeasible && !feasible)) && detour < minDetour || (feasible && !bestFeasible)))) { 178 178 place = i; 179 179 minDetour = detour; … … 203 203 DoubleValue capacity = CapacityParameter.ActualValue; 204 204 205 bool allowInfeasible = AllowInfeasibleSolutions.Value.Value; 206 205 207 List<Tour> R1 = new List<Tour>(); 206 208 PotvinEncoding p1Clone = parent1.Clone() as PotvinEncoding; … … 247 249 248 250 int place = -1; 249 if(FindRouteInsertionPlace(childTour, dueTime, serviceTime, readyTime, 250 demand, capacity, distMatrix, city, out place)) {251 if(FindRouteInsertionPlace(childTour, dueTime, serviceTime, readyTime, 252 demand, capacity, distMatrix, city, allowInfeasible, out place)) { 251 253 childTour.Cities.Insert(place, city); 252 254 253 if (!Repair(random, child, childTour, distMatrix, dueTime, readyTime, serviceTime, demand, capacity )) {255 if (!Repair(random, child, childTour, distMatrix, dueTime, readyTime, serviceTime, demand, capacity, allowInfeasible)) { 254 256 childTour.Cities.RemoveAt(place); 255 257 insertSuccess = false; … … 261 263 262 264 child.Tours.Add(childTour); 263 if (!Repair(random, child, childTour, distMatrix, dueTime, readyTime, serviceTime, demand, capacity )) {265 if (!Repair(random, child, childTour, distMatrix, dueTime, readyTime, serviceTime, demand, capacity, allowInfeasible)) { 264 266 /*success = false; 265 267 break;*/ … … 271 273 Tour childTour = p1Clone.Tours[i].Clone() as Tour; 272 274 child.Tours.Add(childTour); 273 if (!Repair(random, child, childTour, distMatrix, dueTime, readyTime, serviceTime, demand, capacity )) {275 if (!Repair(random, child, childTour, distMatrix, dueTime, readyTime, serviceTime, demand, capacity, allowInfeasible)) { 274 276 /*success = false; 275 277 break;*/ … … 285 287 } 286 288 287 if (!RouteUnrouted(child, distMatrix, dueTime, readyTime, serviceTime, demand, capacity )) {289 if (!RouteUnrouted(child, distMatrix, dueTime, readyTime, serviceTime, demand, capacity, allowInfeasible)) { 288 290 success = false; 289 291 } 290 292 } 291 293 292 if (success )294 if (success || allowInfeasible) 293 295 return child; 294 296 else { -
trunk/sources/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Potvin/Crossovers/PotvinRouteBasedCrossover.cs
r6449 r6459 50 50 DoubleValue capacity = CapacityParameter.ActualValue; 51 51 52 bool allowInfeasible = AllowInfeasibleSolutions.Value.Value; 53 52 54 PotvinEncoding child = parent2.Clone() as PotvinEncoding; 53 55 … … 65 67 child.Unrouted.Add(city); 66 68 67 if (Repair(random, child, replacing, distMatrix, dueTime, readyTime, serviceTime, demand, capacity ))69 if (Repair(random, child, replacing, distMatrix, dueTime, readyTime, serviceTime, demand, capacity, allowInfeasible) || allowInfeasible) 68 70 return child; 69 71 else { -
trunk/sources/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Potvin/Crossovers/PotvinSequenceBasedCrossover.cs
r6449 r6459 51 51 DoubleValue capacity = CapacityParameter.ActualValue; 52 52 53 bool allowInfeasible = AllowInfeasibleSolutions.Value.Value; 54 53 55 PotvinEncoding child = parent1.Clone() as PotvinEncoding; 54 56 Tour newTour = new Tour(); … … 79 81 child.Unrouted.Add(city); 80 82 81 if (Repair(random, child, newTour, distMatrix, dueTime, readyTime, serviceTime, demand, capacity )) {83 if (Repair(random, child, newTour, distMatrix, dueTime, readyTime, serviceTime, demand, capacity, allowInfeasible) || allowInfeasible) { 82 84 return child; 83 85 } else {
Note: See TracChangeset
for help on using the changeset viewer.