- Timestamp:
- 12/06/16 15:07:45 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/MemPRAlgorithm/HeuristicLab.Algorithms.MemPR/3.3/MemPRAlgorithm.cs
r14454 r14456 231 231 Analyze(token); 232 232 token.ThrowIfCancellationRequested(); 233 if (Terminate()) return; 233 234 } 234 235 Context.HcSteps /= 2; … … 314 315 Results.Add(new Result("Iterations", new IntValue(Context.Iterations))); 315 316 else ((IntValue)res.Value).Value = Context.Iterations; 317 if (!Results.TryGetValue("HcSteps", out res)) 318 Results.Add(new Result("HcSteps", new IntValue(Context.HcSteps))); 319 else ((IntValue)res.Value).Value = Context.HcSteps; 316 320 if (!Results.TryGetValue("ByBreeding", out res)) 317 321 Results.Add(new Result("ByBreeding", new IntValue(Context.ByBreeding))); … … 491 495 Context.HillclimbingStat.Add(Tuple.Create(before, after)); 492 496 Context.IncrementEvaluatedSolutions(lscontext.EvaluatedSolutions); 493 return lscontext. Iterations;497 return lscontext.EvaluatedSolutions; 494 498 } 495 499 … … 501 505 var before = scope.Fitness; 502 506 var newScope = (ISingleObjectiveSolutionScope<TSolution>)scope.Clone(); 503 TabuWalk(newScope, steps, token, subspace);507 var newSteps = TabuWalk(newScope, steps, token, subspace); 504 508 Context.TabuwalkingStat.Add(Tuple.Create(before, newScope.Fitness)); 509 //Context.HcSteps = (int)Math.Ceiling(Context.HcSteps * (1.0 + Context.TabuwalkingStat.Count) / (2.0 + Context.TabuwalkingStat.Count) + newSteps / (2.0 + Context.TabuwalkingStat.Count)); 505 510 if (IsBetter(newScope, scope) || (newScope.Fitness == scope.Fitness && Dist(newScope, scope) > 0)) 506 511 scope.Adopt(newScope); 507 512 } 508 protected abstract void TabuWalk(ISingleObjectiveSolutionScope<TSolution> scope, int steps, CancellationToken token, ISolutionSubspace<TSolution> subspace = null);513 protected abstract int TabuWalk(ISingleObjectiveSolutionScope<TSolution> scope, int maxEvals, CancellationToken token, ISolutionSubspace<TSolution> subspace = null); 509 514 protected virtual void TabuClimb(ISingleObjectiveSolutionScope<TSolution> scope, int steps, CancellationToken token, ISolutionSubspace<TSolution> subspace = null) { 510 515 if (double.IsNaN(scope.Fitness)) { … … 514 519 var before = scope.Fitness; 515 520 var newScope = (ISingleObjectiveSolutionScope<TSolution>)scope.Clone(); 516 TabuWalk(newScope, steps, token, subspace);521 var newSteps = TabuWalk(newScope, steps, token, subspace); 517 522 Context.TabuwalkingStat.Add(Tuple.Create(before, newScope.Fitness)); 523 //Context.HcSteps = (int)Math.Ceiling(Context.HcSteps * (1.0 + Context.TabuwalkingStat.Count) / (2.0 + Context.TabuwalkingStat.Count) + newSteps / (2.0 + Context.TabuwalkingStat.Count)); 518 524 if (IsBetter(newScope, scope) || (newScope.Fitness == scope.Fitness && Dist(newScope, scope) > 0)) 519 525 scope.Adopt(newScope); … … 557 563 || Context.Population.Any(p => IsBetter(offspring, p))) return offspring; 558 564 559 if (IsBetter(offspring.Fitness, Context.BestQuality)) 560 HillClimb(offspring, token); // perform hillclimb in full solution space 561 else if (HillclimbingSuited(offspring)) 565 if (HillclimbingSuited(offspring)) 562 566 HillClimb(offspring, token, subspace); // perform hillclimb in the solution sub-space 563 567 return offspring; … … 589 593 if (dist1 > 0 && dist2 > 0) { 590 594 var subspace = CalculateSubspace(new[] { a.Solution, b.Solution }, inverse: true); 591 if (IsBetter(child.Fitness, Context.BestQuality)) 592 HillClimb(child, token); // perform hillclimb in full solution space 593 else if (HillclimbingSuited(child)) { 595 if (HillclimbingSuited(child)) { 594 596 HillClimb(child, token, subspace); // perform hillclimb in solution sub-space 595 597 }
Note: See TracChangeset
for help on using the changeset viewer.