Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/19/20 16:38:33 (4 years ago)
Author:
mkommend
Message:

#2521: Added first version of problem results.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2521_ProblemRefactoring/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/HillClimber.cs

    r17594 r17612  
    4545  public class HillClimber : BasicAlgorithm {
    4646    [Storable]
    47     private IRandom random;
     47    private readonly IRandom random;
    4848
    4949    [Storable] public IFixedValueParameter<IntValue> MaximumIterationsParameter { get; private set; }
     
    6565      get { return MaximumIterationsParameter.Value.Value; }
    6666      set { MaximumIterationsParameter.Value.Value = value; }
     67    }
     68
     69    private int Iterations {
     70      get => IterationsResult.Value.Value;
     71      set => IterationsResult.Value.Value = value;
     72    }
     73
     74    private double BestQuality {
     75      get => BestQualityResult.Value.Value;
     76      set => BestQualityResult.Value.Value = value;
    6777    }
    6878
     
    8898    }
    8999
     100    protected override void Initialize(CancellationToken cancellationToken) {
     101      base.Initialize(cancellationToken);
     102
     103      IterationsResult.Value = new IntValue();
     104      BestQualityResult.Value = new DoubleValue(double.NaN);
     105    }
     106
    90107
    91108
    92109    protected override void Run(CancellationToken cancellationToken) {
    93       IterationsResult.Value = new IntValue();
    94       BestQualityResult.Value = new DoubleValue(double.NaN);
    95 
    96110      while (IterationsResult.Value.Value < MaximumIterations) {
    97111        cancellationToken.ThrowIfCancellationRequested();
     
    106120
    107121        fitness = ImproveToLocalOptimum(Problem, solution, fitness, random);
    108         var bestSoFar = BestQualityResult.Value.Value;
     122        var bestSoFar = BestQuality;
    109123        if (double.IsNaN(bestSoFar) || Problem.IsBetter(fitness, bestSoFar)) {
    110           BestQualityResult.Value.Value = fitness;
     124          BestQuality = fitness;
    111125        }
    112126
    113         IterationsResult.Value.Value++;
     127        Iterations++;
    114128      }
    115129    }
Note: See TracChangeset for help on using the changeset viewer.