- Timestamp:
- 01/08/17 22:16:19 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/MemPRAlgorithm/HeuristicLab.Algorithms.MemPR/3.3/Permutation/PermutationMemPR.cs
r14550 r14551 395 395 private ISingleObjectiveSolutionScope<Encodings.PermutationEncoding.Permutation> CrossAbsolute(ISingleObjectiveSolutionScope<Encodings.PermutationEncoding.Permutation> p1, ISingleObjectiveSolutionScope<Encodings.PermutationEncoding.Permutation> p2, CancellationToken token) { 396 396 var cache = new HashSet<Encodings.PermutationEncoding.Permutation>(new PermutationEqualityComparer()); 397 cache.Add(p1.Solution); 398 cache.Add(p2.Solution); 399 397 400 var cacheHits = 0; 398 var evaluations = 1;401 var evaluations = 0; 399 402 ISingleObjectiveSolutionScope<Encodings.PermutationEncoding.Permutation> offspring = null; 400 for (; evaluations <= p1.Solution.Length; evaluations++) {403 while (evaluations < p1.Solution.Length) { 401 404 Encodings.PermutationEncoding.Permutation c = null; 402 405 var xochoice = Context.Random.Next(3); … … 413 416 var probe = ToScope(c); 414 417 Evaluate(probe, token); 418 evaluations++; 415 419 cache.Add(c); 416 420 if (offspring == null || Context.IsBetter(probe, offspring)) { … … 420 424 } 421 425 } 422 Context.IncrementEvaluatedSolutions(evaluations -1);426 Context.IncrementEvaluatedSolutions(evaluations); 423 427 return offspring; 424 428 } … … 426 430 private ISingleObjectiveSolutionScope<Encodings.PermutationEncoding.Permutation> CrossRelativeDirected(ISingleObjectiveSolutionScope<Encodings.PermutationEncoding.Permutation> p1, ISingleObjectiveSolutionScope<Encodings.PermutationEncoding.Permutation> p2, CancellationToken token) { 427 431 var cache = new HashSet<Encodings.PermutationEncoding.Permutation>(new PermutationEqualityComparer()); 432 cache.Add(p1.Solution); 433 cache.Add(p2.Solution); 434 428 435 var cacheHits = 0; 429 var evaluations = 1;436 var evaluations = 0; 430 437 ISingleObjectiveSolutionScope<Encodings.PermutationEncoding.Permutation> offspring = null; 431 for (; evaluations <= p1.Solution.Length; evaluations++) {438 while(evaluations < p1.Solution.Length) { 432 439 Encodings.PermutationEncoding.Permutation c = null; 433 440 var xochoice = Context.Random.Next(3); … … 444 451 var probe = ToScope(c); 445 452 Evaluate(probe, token); 453 evaluations++; 446 454 cache.Add(c); 447 455 if (offspring == null || Context.IsBetter(probe, offspring)) { … … 451 459 } 452 460 } 453 Context.IncrementEvaluatedSolutions(evaluations -1);461 Context.IncrementEvaluatedSolutions(evaluations); 454 462 return offspring; 455 463 } … … 457 465 private ISingleObjectiveSolutionScope<Encodings.PermutationEncoding.Permutation> CrossRelativeUndirected(ISingleObjectiveSolutionScope<Encodings.PermutationEncoding.Permutation> p1, ISingleObjectiveSolutionScope<Encodings.PermutationEncoding.Permutation> p2, CancellationToken token) { 458 466 var cache = new HashSet<Encodings.PermutationEncoding.Permutation>(new PermutationEqualityComparer()); 467 cache.Add(p1.Solution); 468 cache.Add(p2.Solution); 469 459 470 var cacheHits = 0; 460 var evaluations = 1;471 var evaluations = 0; 461 472 ISingleObjectiveSolutionScope<Encodings.PermutationEncoding.Permutation> offspring = null; 462 for (; evaluations <= p1.Solution.Length; evaluations++) {473 while(evaluations <= p1.Solution.Length) { 463 474 Encodings.PermutationEncoding.Permutation c = null; 464 475 var xochoice = Context.Random.Next(3); … … 475 486 var probe = ToScope(c); 476 487 Evaluate(probe, token); 488 evaluations++; 477 489 cache.Add(c); 478 490 if (offspring == null || Context.IsBetter(probe, offspring)) { … … 482 494 } 483 495 } 484 Context.IncrementEvaluatedSolutions(evaluations -1);496 Context.IncrementEvaluatedSolutions(evaluations); 485 497 return offspring; 486 498 } 487 499 488 500 protected override ISingleObjectiveSolutionScope<Encodings.PermutationEncoding.Permutation> Link(ISingleObjectiveSolutionScope<Encodings.PermutationEncoding.Permutation> a, ISingleObjectiveSolutionScope<Encodings.PermutationEncoding.Permutation> b, CancellationToken token, bool delink = false) { 489 if (double.IsNaN(a.Fitness)) {490 Evaluate(a, token);491 Context.IncrementEvaluatedSolutions(1);492 }493 if (double.IsNaN(b.Fitness)) {494 Evaluate(b, token);495 Context.IncrementEvaluatedSolutions(1);496 }497 498 501 var wrapper = new EvaluationWrapper<Encodings.PermutationEncoding.Permutation>(Problem, ToScope(null)); 499 502 double quality; … … 626 629 Context.IncrementEvaluatedSolutions(evaluations); 627 630 628 if (VALIDATE && bestChild != null && !bestChild.Validate()) throw new ArgumentException("Relinking produced invalid child"); 629 if (VALIDATE && Dist(child, p2) > 0) throw new InvalidOperationException("Child is not equal to p2 after relinking"); 631 if (VALIDATE && bestChild != null && !bestChild.Validate()) throw new ArgumentException("Delinking produced invalid child"); 630 632 631 633 return bestChild ?? child;
Note: See TracChangeset
for help on using the changeset viewer.