Changeset 17698 for branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Prins
- Timestamp:
- 07/24/20 00:58:42 (4 years ago)
- Location:
- branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Prins
- Files:
-
- 1 added
- 1 deleted
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Prins/Crossovers/PrinsCrossover.cs
r17226 r17698 49 49 } 50 50 51 protected abstract PrinsEncod ing Crossover(IRandom random, PrinsEncoding parent1, PrinsEncodingparent2);51 protected abstract PrinsEncodedSolution Crossover(IRandom random, PrinsEncodedSolution parent1, PrinsEncodedSolution parent2); 52 52 53 53 public override IOperation InstrumentedApply() { 54 ItemArray<IVRPEncod ing> parents = new ItemArray<IVRPEncoding>(ParentsParameter.ActualValue.Length);54 ItemArray<IVRPEncodedSolution> parents = new ItemArray<IVRPEncodedSolution>(ParentsParameter.ActualValue.Length); 55 55 for (int i = 0; i < ParentsParameter.ActualValue.Length; i++) { 56 IVRPEncod ingsolution = ParentsParameter.ActualValue[i];56 IVRPEncodedSolution solution = ParentsParameter.ActualValue[i]; 57 57 58 if (!(solution is PrinsEncod ing)) {59 parents[i] = PrinsEncod ing.ConvertFrom(solution, ProblemInstance);58 if (!(solution is PrinsEncodedSolution)) { 59 parents[i] = PrinsEncodedSolution.ConvertFrom(solution, ProblemInstance); 60 60 } else { 61 61 parents[i] = solution; … … 65 65 66 66 ChildParameter.ActualValue = 67 Crossover(RandomParameter.ActualValue, parents[0] as PrinsEncod ing, parents[1] as PrinsEncoding);67 Crossover(RandomParameter.ActualValue, parents[0] as PrinsEncodedSolution, parents[1] as PrinsEncodedSolution); 68 68 69 69 return base.InstrumentedApply(); -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Prins/Crossovers/PrinsPermutationCrossover.cs
r17226 r17698 50 50 } 51 51 52 protected override PrinsEncod ing Crossover(IRandom random, PrinsEncoding parent1, PrinsEncodingparent2) {52 protected override PrinsEncodedSolution Crossover(IRandom random, PrinsEncodedSolution parent1, PrinsEncodedSolution parent2) { 53 53 if (parent1.Length != parent2.Length) 54 return parent1.Clone() as PrinsEncod ing;54 return parent1.Clone() as PrinsEncodedSolution; 55 55 56 56 //note - the inner crossover is called here and the result is converted to a prins representation … … 67 67 ExecutionContext.Scope.Variables.Remove(childName); 68 68 69 return new PrinsEncod ing(permutation, ProblemInstance);69 return new PrinsEncodedSolution(permutation, ProblemInstance); 70 70 } else 71 71 return null; -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Prins/Manipulators/PrinsExhaustiveLSManipulator.cs
r17226 r17698 44 44 } 45 45 46 protected override void Manipulate(IRandom random, PrinsEncod ingindividual) {46 protected override void Manipulate(IRandom random, PrinsEncodedSolution individual) { 47 47 List<Tour> tours = individual.GetTours(); 48 48 bool improvement = false; … … 53 53 improvement = false; 54 54 double originalQuality = GetQuality(individual); 55 PrinsEncod ingchild = null;55 PrinsEncodedSolution child = null; 56 56 57 57 while (!improvement && u < ProblemInstance.Cities.Value) { -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Prins/Manipulators/PrinsLSManipulator.cs
r17226 r17698 48 48 } 49 49 50 protected double GetQuality(PrinsEncod ingindividual) {50 protected double GetQuality(PrinsEncodedSolution individual) { 51 51 return ProblemInstance.Evaluate(individual).Quality; 52 52 } 53 53 54 private int FindCity(PrinsEncod ingindividual, int city) {54 private int FindCity(PrinsEncodedSolution individual, int city) { 55 55 int index = -1; 56 56 … … 68 68 protected const int depot = -1; 69 69 70 private Tour FindTour(PrinsEncod ingindividual, int city) {70 private Tour FindTour(PrinsEncodedSolution individual, int city) { 71 71 Tour found = null; 72 72 … … 85 85 86 86 //inserts u after v in the child 87 private void InsertAfter(int u, int v, PrinsEncod ing parent, PrinsEncodingchild) {87 private void InsertAfter(int u, int v, PrinsEncodedSolution parent, PrinsEncodedSolution child) { 88 88 int pi = 0; 89 89 int ci = 0; … … 104 104 105 105 //inserts (u, x) after v in the child 106 private void InsertAfter(int u, int x, int v, PrinsEncod ing parent, PrinsEncodingchild) {106 private void InsertAfter(int u, int x, int v, PrinsEncodedSolution parent, PrinsEncodedSolution child) { 107 107 int pi = 0; 108 108 int ci = 0; … … 126 126 127 127 //inserts u before v in the child 128 private void InsertBefore(int u, int v, PrinsEncod ing parent, PrinsEncodingchild) {128 private void InsertBefore(int u, int v, PrinsEncodedSolution parent, PrinsEncodedSolution child) { 129 129 int pi = 0; 130 130 int ci = 0; … … 145 145 146 146 //inserts (u, x) before v in the child 147 private void InsertBefore(int u, int x, int v, PrinsEncod ing parent, PrinsEncodingchild) {147 private void InsertBefore(int u, int x, int v, PrinsEncodedSolution parent, PrinsEncodedSolution child) { 148 148 int pi = 0; 149 149 int ci = 0; … … 167 167 168 168 //swaps u and v 169 private void Swap(int u, int v, PrinsEncod ing parent, PrinsEncodingchild) {169 private void Swap(int u, int v, PrinsEncodedSolution parent, PrinsEncodedSolution child) { 170 170 for (int i = 0; i < child.Length; i++) { 171 171 if (parent[i] == u) … … 179 179 180 180 //swaps (u, x) and v 181 private void Swap(int u, int x, int v, PrinsEncod ing parent, PrinsEncodingchild) {181 private void Swap(int u, int x, int v, PrinsEncodedSolution parent, PrinsEncodedSolution child) { 182 182 int childIndex = 0; 183 183 int parentIndex = 0; … … 201 201 202 202 //swaps (u, x) and (v, y) 203 private void Swap(int u, int x, int v, int y, PrinsEncod ing parent, PrinsEncodingchild) {203 private void Swap(int u, int x, int v, int y, PrinsEncodedSolution parent, PrinsEncodedSolution child) { 204 204 int i = 0; 205 205 … … 222 222 223 223 //swaps (u, x) and (v, y) by (u, y) and (x, v) 224 private void Swap2(int u, int x, int v, int y, PrinsEncod ing parent, PrinsEncodingchild) {224 private void Swap2(int u, int x, int v, int y, PrinsEncodedSolution parent, PrinsEncodedSolution child) { 225 225 int i = 0; 226 226 … … 240 240 } 241 241 242 private void M1(PrinsEncod ing parent, PrinsEncodingchild, int u, int v) {242 private void M1(PrinsEncodedSolution parent, PrinsEncodedSolution child, int u, int v) { 243 243 if (u != depot) { 244 244 if (v == depot) { … … 252 252 } 253 253 254 private void M2(PrinsEncod ing parent, PrinsEncodingchild, int u, int v) {254 private void M2(PrinsEncodedSolution parent, PrinsEncodedSolution child, int u, int v) { 255 255 if (u != depot) { 256 256 Tour tour = FindTour(child, u + 1); … … 270 270 } 271 271 272 private void M3(PrinsEncod ing parent, PrinsEncodingchild, int u, int v) {272 private void M3(PrinsEncodedSolution parent, PrinsEncodedSolution child, int u, int v) { 273 273 if (u != depot) { 274 274 Tour tour = FindTour(child, u + 1); … … 288 288 } 289 289 290 private void M4(PrinsEncod ing parent, PrinsEncodingchild, int u, int v) {290 private void M4(PrinsEncodedSolution parent, PrinsEncodedSolution child, int u, int v) { 291 291 if (u != depot && v != depot) { 292 292 Swap(u, v, parent, child); … … 294 294 } 295 295 296 private void M5(PrinsEncod ing parent, PrinsEncodingchild, int u, int v) {296 private void M5(PrinsEncodedSolution parent, PrinsEncodedSolution child, int u, int v) { 297 297 if (u != depot && v != depot) { 298 298 Tour tour = FindTour(child, u + 1); … … 307 307 } 308 308 309 private void M6(PrinsEncod ing parent, PrinsEncodingchild, int u, int v) {309 private void M6(PrinsEncodedSolution parent, PrinsEncodedSolution child, int u, int v) { 310 310 if (u != depot && v != depot) { 311 311 Tour tour = FindTour(child, u + 1); … … 326 326 } 327 327 328 private void M7(PrinsEncod ing parent, PrinsEncodingchild, int u, int v) {328 private void M7(PrinsEncodedSolution parent, PrinsEncodedSolution child, int u, int v) { 329 329 if (u != depot && v != depot) { 330 330 Tour tu = FindTour(child, u + 1); … … 348 348 } 349 349 350 private void M8(PrinsEncod ing parent, PrinsEncodingchild, int u, int v) {350 private void M8(PrinsEncodedSolution parent, PrinsEncodedSolution child, int u, int v) { 351 351 if (u != depot && v != depot) { 352 352 Tour tu = FindTour(child, u + 1); … … 370 370 } 371 371 372 private void M9(PrinsEncod ing parent, PrinsEncodingchild, int u, int v) {372 private void M9(PrinsEncodedSolution parent, PrinsEncodedSolution child, int u, int v) { 373 373 if (u != depot && v != depot) { 374 374 Tour tu = FindTour(child, u + 1); … … 392 392 } 393 393 394 protected PrinsEncod ing Manipulate(PrinsEncodingindividual,394 protected PrinsEncodedSolution Manipulate(PrinsEncodedSolution individual, 395 395 double originalQuality, int u, int v) { 396 PrinsEncod ingchild = null;396 PrinsEncodedSolution child = null; 397 397 bool improvement = false; 398 398 399 399 if (u != v) { 400 child = individual.Clone() as PrinsEncod ing;400 child = individual.Clone() as PrinsEncodedSolution; 401 401 M1(individual, child, u, v); 402 402 improvement = GetQuality(child) < originalQuality; 403 403 404 404 if (!improvement) { 405 child = individual.Clone() as PrinsEncod ing;405 child = individual.Clone() as PrinsEncodedSolution; 406 406 M2(individual, child, u, v); 407 407 improvement = GetQuality(child) < originalQuality; … … 409 409 410 410 if (!improvement) { 411 child = individual.Clone() as PrinsEncod ing;411 child = individual.Clone() as PrinsEncodedSolution; 412 412 M3(individual, child, u, v); 413 413 improvement = GetQuality(child) < originalQuality; … … 415 415 416 416 if (!improvement) { 417 child = individual.Clone() as PrinsEncod ing;417 child = individual.Clone() as PrinsEncodedSolution; 418 418 M4(individual, child, u, v); 419 419 improvement = GetQuality(child) < originalQuality; … … 421 421 422 422 if (!improvement) { 423 child = individual.Clone() as PrinsEncod ing;423 child = individual.Clone() as PrinsEncodedSolution; 424 424 M5(individual, child, u, v); 425 425 improvement = GetQuality(child) < originalQuality; … … 427 427 428 428 if (!improvement) { 429 child = individual.Clone() as PrinsEncod ing;429 child = individual.Clone() as PrinsEncodedSolution; 430 430 M6(individual, child, u, v); 431 431 improvement = GetQuality(child) < originalQuality; … … 433 433 434 434 if (!improvement) { 435 child = individual.Clone() as PrinsEncod ing;435 child = individual.Clone() as PrinsEncodedSolution; 436 436 M7(individual, child, u, v); 437 437 improvement = GetQuality(child) < originalQuality; … … 439 439 440 440 if (!improvement) { 441 child = individual.Clone() as PrinsEncod ing;441 child = individual.Clone() as PrinsEncodedSolution; 442 442 M8(individual, child, u, v); 443 443 improvement = GetQuality(child) < originalQuality; … … 445 445 446 446 if (!improvement) { 447 child = individual.Clone() as PrinsEncod ing;447 child = individual.Clone() as PrinsEncodedSolution; 448 448 M9(individual, child, u, v); 449 449 improvement = GetQuality(child) < originalQuality; -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Prins/Manipulators/PrinsManipulator.cs
r17226 r17698 48 48 } 49 49 50 protected abstract void Manipulate(IRandom random, PrinsEncod ingindividual);50 protected abstract void Manipulate(IRandom random, PrinsEncodedSolution individual); 51 51 52 52 public override IOperation InstrumentedApply() { 53 IVRPEncod ingsolution = VRPToursParameter.ActualValue;54 if (!(solution is PrinsEncod ing)) {55 VRPToursParameter.ActualValue = PrinsEncod ing.ConvertFrom(solution, ProblemInstance);53 IVRPEncodedSolution solution = VRPToursParameter.ActualValue; 54 if (!(solution is PrinsEncodedSolution)) { 55 VRPToursParameter.ActualValue = PrinsEncodedSolution.ConvertFrom(solution, ProblemInstance); 56 56 } 57 57 58 Manipulate(RandomParameter.ActualValue, VRPToursParameter.ActualValue as PrinsEncod ing);58 Manipulate(RandomParameter.ActualValue, VRPToursParameter.ActualValue as PrinsEncodedSolution); 59 59 60 60 return base.InstrumentedApply(); -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Prins/Manipulators/PrinsPermutationManipulator.cs
r17226 r17698 50 50 } 51 51 52 protected override void Manipulate(IRandom random, PrinsEncod ingindividual) {52 protected override void Manipulate(IRandom random, PrinsEncodedSolution individual) { 53 53 InnerManipulatorParameter.ActualValue.PermutationParameter.ActualName = VRPToursParameter.ActualName; 54 54 -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Prins/Manipulators/PrinsStochasticLSManipulator.cs
r17226 r17698 51 51 } 52 52 53 protected override void Manipulate(IRandom random, PrinsEncod ingindividual) {53 protected override void Manipulate(IRandom random, PrinsEncodedSolution individual) { 54 54 List<Tour> tours = individual.GetTours(); 55 55 bool improvement = false; … … 59 59 improvement = false; 60 60 double originalQuality = GetQuality(individual); 61 PrinsEncod ingchild = null;61 PrinsEncodedSolution child = null; 62 62 63 63 int samples = 0;
Note: See TracChangeset
for help on using the changeset viewer.