Changeset 17577 for branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Operators/SingleObjectiveImprover.cs
- Timestamp:
- 05/29/20 15:18:44 (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Operators/SingleObjectiveImprover.cs
r17366 r17577 90 90 var maxAttempts = ImprovementAttemptsParameter.ActualValue.Value; 91 91 var sampleSize = SampleSizeParameter.ActualValue.Value; 92 var solution = ScopeUtil.GetEncodedSolution(ExecutionContext.Scope, encoding); 93 var solutionContext = new SingleObjectiveSolutionContextScope<TEncodedSolution>(ExecutionContext.Scope, solution); 92 var solutionContext = ScopeUtil.CreateSolutionContext(ExecutionContext.Scope, encoding); 94 93 95 94 double quality; … … 102 101 var count = 0; 103 102 for (var i = 0; i < maxAttempts; i++) { 104 TEncodedSolution best = default(TEncodedSolution);103 ISingleObjectiveSolutionContext<TEncodedSolution> best = default; 105 104 var bestQuality = quality; 106 105 foreach (var neighbor in GetNeighbors(solutionContext, random).Take(sampleSize)) { 107 Evaluate(neighbor, random, CancellationToken); 106 if (!neighbor.IsEvaluated) 107 Evaluate(neighbor, random, CancellationToken); 108 108 var q = neighbor.EvaluationResult.Quality; 109 109 count++; 110 110 if (maximize && bestQuality > q || !maximize && bestQuality < q) continue; 111 best = neighbor .EncodedSolution;111 best = neighbor; 112 112 bestQuality = q; 113 113 } 114 114 if (best == null) break; 115 solution = best;115 solutionContext = best; 116 116 quality = bestQuality; 117 117 } … … 119 119 LocalEvaluatedSolutionsParameter.ActualValue = new IntValue(count); 120 120 QualityParameter.ActualValue = new DoubleValue(quality); 121 122 ScopeUtil.Copy EncodedSolutionToScope(ExecutionContext.Scope, encoding, solution);121 ScopeUtil.CopyEncodedSolutionToScope(ExecutionContext.Scope, encoding, solutionContext.EncodedSolution); 122 ScopeUtil.CopyToScope(ExecutionContext.Scope, solutionContext); 123 123 return base.Apply(); 124 124 }
Note: See TracChangeset
for help on using the changeset viewer.