Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/10/20 12:15:23 (4 years ago)
Author:
mkommend
Message:

#2521: Added first version of new results. The first algorithm that has been adapted for testing purposes is the hill climber.

File:
1 edited

Legend:

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

    r17517 r17594  
    3131using HeuristicLab.Encodings.BinaryVectorEncoding;
    3232using HeuristicLab.Optimization;
     33
    3334using HeuristicLab.Parameters;
    3435using HeuristicLab.Random;
     
    4748
    4849    [Storable] public IFixedValueParameter<IntValue> MaximumIterationsParameter { get; private set; }
    49     [Storable] public IResultParameter<DoubleValue> BestQualityResultParameter { get; private set; }
    50     [Storable] public IResultParameter<IntValue> IterationsResultParameter { get; private set; }
     50
     51    [Storable] public IResult<DoubleValue> BestQualityResult { get; private set; }
     52    [Storable] public IResult<IntValue> IterationsResult { get; private set; }
    5153
    5254    public override Type ProblemType {
     
    7072      : base(original, cloner) {
    7173      MaximumIterationsParameter = cloner.Clone(original.MaximumIterationsParameter);
    72       BestQualityResultParameter = cloner.Clone(original.BestQualityResultParameter);
    73       IterationsResultParameter = cloner.Clone(original.IterationsResultParameter);
     74      BestQualityResult = cloner.Clone(original.BestQualityResult);
     75      IterationsResult = cloner.Clone(original.IterationsResult);
    7476    }
    7577    public override IDeepCloneable Clone(Cloner cloner) {
     
    8183      random = new MersenneTwister();
    8284      Parameters.Add(MaximumIterationsParameter = new FixedValueParameter<IntValue>("Maximum Iterations", "", new IntValue(100)));
    83       Parameters.Add(BestQualityResultParameter = new ResultParameter<DoubleValue>("Best Quality", "", "Results", new DoubleValue(double.NaN)));
    84       Parameters.Add(IterationsResultParameter = new ResultParameter<IntValue>("Iterations", "", "Results", new IntValue(0)));
     85
     86      Results.Add(BestQualityResult = new Result<DoubleValue>("Best Quality"));
     87      Results.Add(IterationsResult = new Result<IntValue>("Iterations"));
    8588    }
    8689
     90
     91
    8792    protected override void Run(CancellationToken cancellationToken) {
    88       while (IterationsResultParameter.ActualValue.Value < MaximumIterations) {
     93      IterationsResult.Value = new IntValue();
     94      BestQualityResult.Value = new DoubleValue(double.NaN);
     95
     96      while (IterationsResult.Value.Value < MaximumIterations) {
    8997        cancellationToken.ThrowIfCancellationRequested();
    9098
     
    98106
    99107        fitness = ImproveToLocalOptimum(Problem, solution, fitness, random);
    100         var bestSoFar = BestQualityResultParameter.ActualValue.Value;
     108        var bestSoFar = BestQualityResult.Value.Value;
    101109        if (double.IsNaN(bestSoFar) || Problem.IsBetter(fitness, bestSoFar)) {
    102           BestQualityResultParameter.ActualValue.Value = fitness;
     110          BestQualityResult.Value.Value = fitness;
    103111        }
    104112
    105         IterationsResultParameter.ActualValue.Value++;
     113        IterationsResult.Value.Value++;
    106114      }
    107115    }
Note: See TracChangeset for help on using the changeset viewer.