Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/04/17 16:33:37 (7 years ago)
Author:
gkronber
Message:

#2650: merged r14504:14533 from trunk to branch

Location:
branches/symbreg-factors-2650
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/symbreg-factors-2650

  • branches/symbreg-factors-2650/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/HillClimber.cs

    r14185 r14542  
    4848
    4949    private const string IterationsParameterName = "Iterations";
     50    private const string BestQualityResultName = "Best quality";
     51    private const string IterationsResultName = "Iterations";
    5052
    5153    public override Type ProblemType {
    5254      get { return typeof(BinaryProblem); }
    5355    }
     56
     57    public override bool SupportsPause { get { return false; } }
     58
    5459    public new BinaryProblem Problem {
    5560      get { return (BinaryProblem)base.Problem; }
     
    6570      set { IterationsParameter.Value.Value = value; }
    6671    }
     72
     73    #region ResultsProperties
     74    private double ResultsBestQuality {
     75      get { return ((DoubleValue)Results[BestQualityResultName].Value).Value; }
     76      set { ((DoubleValue)Results[BestQualityResultName].Value).Value = value; }
     77    }
     78    private int ResultsIterations {
     79      get { return ((IntValue)Results[IterationsResultName].Value).Value; }
     80      set { ((IntValue)Results[IterationsResultName].Value).Value = value; }
     81    }
     82    #endregion
    6783
    6884    [StorableConstructor]
     
    8096      Parameters.Add(new FixedValueParameter<IntValue>(IterationsParameterName, "", new IntValue(100)));
    8197    }
     98
     99
     100    protected override void Initialize(CancellationToken cancellationToken) {
     101      Results.Add(new Result(BestQualityResultName, new DoubleValue(double.NaN)));
     102      Results.Add(new Result(IterationsResultName, new IntValue(0)));
     103      base.Initialize(cancellationToken);
     104    }
    82105    protected override void Run(CancellationToken cancellationToken) {
    83       var BestQuality = new DoubleValue(double.NaN);
    84       Results.Add(new Result("Best quality", BestQuality));
    85       for (int iteration = 0; iteration < Iterations; iteration++) {
     106      while (ResultsIterations < Iterations) {
     107        cancellationToken.ThrowIfCancellationRequested();
     108
    86109        var solution = new BinaryVector(Problem.Length);
    87110        for (int i = 0; i < solution.Length; i++) {
     
    92115
    93116        fitness = ImproveToLocalOptimum(Problem, solution, fitness, random);
    94         if (double.IsNaN(BestQuality.Value) || Problem.IsBetter(fitness, BestQuality.Value)) {
    95           BestQuality.Value = fitness;
     117        if (double.IsNaN(ResultsBestQuality) || Problem.IsBetter(fitness, ResultsBestQuality)) {
     118          ResultsBestQuality = fitness;
    96119        }
     120
     121        ResultsIterations++;
    97122      }
    98123    }
Note: See TracChangeset for help on using the changeset viewer.