Changeset 6491
- Timestamp:
- 06/28/11 09:25:10 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Potvin/Crossovers/PotvinInsertionBasedCrossover.cs
r6459 r6491 34 34 public IValueParameter<IntValue> Length { 35 35 get { return (IValueParameter<IntValue>)Parameters["Length"]; } 36 } 36 } 37 37 38 38 [StorableConstructor] … … 46 46 public PotvinInsertionBasedCrossover() 47 47 : base() { 48 49 } 50 51 pr otectedstatic int SelectRandomTourBiasedByLength(IRandom random, PotvinEncoding individual) {48 Parameters.Add(new ValueParameter<IntValue>("Length", "The maximum length of the replaced route.", new IntValue(1))); 49 } 50 51 private static int SelectRandomTourBiasedByLength(IRandom random, PotvinEncoding individual) { 52 52 int tourIndex = -1; 53 53 … … 119 119 if (next >= tour.Cities.Count) 120 120 next = 0; 121 else 121 else 122 122 next = tour.Cities[next]; 123 123 double distance = VRPUtilities.GetDistance( … … 192 192 protected override PotvinEncoding Crossover(IRandom random, PotvinEncoding parent1, PotvinEncoding parent2) { 193 193 PotvinEncoding child = new PotvinEncoding(); 194 bool success = true;195 194 196 195 BoolValue useDistanceMatrix = UseDistanceMatrixParameter.ActualValue; … … 236 235 237 236 //REPAIR - add cities from R2 238 bool insertSuccess = true;239 237 int maxCount = random.Next(1, Math.Min(5, R2.Count)); 240 238 int count = 0; … … 249 247 250 248 int place = -1; 251 if (FindRouteInsertionPlace(childTour, dueTime, serviceTime, readyTime,249 if (FindRouteInsertionPlace(childTour, dueTime, serviceTime, readyTime, 252 250 demand, capacity, distMatrix, city, allowInfeasible, out place)) { 253 251 childTour.Cities.Insert(place, city); … … 255 253 if (!Repair(random, child, childTour, distMatrix, dueTime, readyTime, serviceTime, demand, capacity, allowInfeasible)) { 256 254 childTour.Cities.RemoveAt(place); 257 insertSuccess = false;258 255 } else { 259 256 count++; 260 } 261 } 257 } 258 } 262 259 } 263 260 264 261 child.Tours.Add(childTour); 265 if (!Repair(random, child, childTour, distMatrix, dueTime, readyTime, serviceTime, demand, capacity, allowInfeasible)) { 266 /*success = false; 267 break;*/ 268 } 269 } 270 271 if (success) { 272 for (int i = 0; i < p1Clone.Tours.Count; i++) { 273 Tour childTour = p1Clone.Tours[i].Clone() as Tour; 274 child.Tours.Add(childTour); 275 if (!Repair(random, child, childTour, distMatrix, dueTime, readyTime, serviceTime, demand, capacity, allowInfeasible)) { 276 /*success = false; 277 break;*/ 278 } 279 } 280 } 281 282 if (success) { 283 //route unrouted customers 284 for (int i = 1; i <= parent1.Cities; i++) { 285 if (FindRoute(child, i) == null) 286 child.Unrouted.Add(i); 287 } 288 289 if (!RouteUnrouted(child, distMatrix, dueTime, readyTime, serviceTime, demand, capacity, allowInfeasible)) { 290 success = false; 291 } 262 Repair(random, child, childTour, distMatrix, dueTime, readyTime, serviceTime, demand, capacity, allowInfeasible); 263 } 264 265 for (int i = 0; i < p1Clone.Tours.Count; i++) { 266 Tour childTour = p1Clone.Tours[i].Clone() as Tour; 267 child.Tours.Add(childTour); 268 Repair(random, child, childTour, distMatrix, dueTime, readyTime, serviceTime, demand, capacity, allowInfeasible); 269 } 270 271 //route unrouted customers 272 for (int i = 1; i <= parent1.Cities; i++) { 273 if (FindRoute(child, i) == null) 274 child.Unrouted.Add(i); 275 } 276 277 bool success = true; 278 if (!RouteUnrouted(child, distMatrix, dueTime, readyTime, serviceTime, demand, capacity, allowInfeasible)) { 279 success = false; 292 280 } 293 281 … … 298 286 return parent1.Clone() as PotvinEncoding; 299 287 else 300 return parent2.Clone() as PotvinEncoding; 288 return parent2.Clone() as PotvinEncoding; 301 289 } 302 290 }
Note: See TracChangeset
for help on using the changeset viewer.