Ignore:
Timestamp:
05/29/20 15:18:44 (2 years ago)
Author:
abeham
Message:

#2521: remove scope-based contexts, add helper methods to ScopeUtil, adapt operators

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Operators/SingleObjectiveImprover.cs

    r17366 r17577  
    9090      var maxAttempts = ImprovementAttemptsParameter.ActualValue.Value;
    9191      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);
    9493
    9594      double quality;
     
    102101      var count = 0;
    103102      for (var i = 0; i < maxAttempts; i++) {
    104         TEncodedSolution best = default(TEncodedSolution);
     103        ISingleObjectiveSolutionContext<TEncodedSolution> best = default;
    105104        var bestQuality = quality;
    106105        foreach (var neighbor in GetNeighbors(solutionContext, random).Take(sampleSize)) {
    107           Evaluate(neighbor, random, CancellationToken);
     106          if (!neighbor.IsEvaluated)
     107            Evaluate(neighbor, random, CancellationToken);
    108108          var q = neighbor.EvaluationResult.Quality;
    109109          count++;
    110110          if (maximize && bestQuality > q || !maximize && bestQuality < q) continue;
    111           best = neighbor.EncodedSolution;
     111          best = neighbor;
    112112          bestQuality = q;
    113113        }
    114114        if (best == null) break;
    115         solution = best;
     115        solutionContext = best;
    116116        quality = bestQuality;
    117117      }
     
    119119      LocalEvaluatedSolutionsParameter.ActualValue = new IntValue(count);
    120120      QualityParameter.ActualValue = new DoubleValue(quality);
    121 
    122       ScopeUtil.CopyEncodedSolutionToScope(ExecutionContext.Scope, encoding, solution);
     121      ScopeUtil.CopyEncodedSolutionToScope(ExecutionContext.Scope, encoding, solutionContext.EncodedSolution);
     122      ScopeUtil.CopyToScope(ExecutionContext.Scope, solutionContext);
    123123      return base.Apply();
    124124    }
Note: See TracChangeset for help on using the changeset viewer.