Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/12/15 15:39:28 (9 years ago)
Author:
abeham
Message:

#2282:

  • Renamed BinaryVectorProblem to BinaryProblem
  • Removed IBinaryVectorProblem interface
  • Derived BinaryProblem from SingleObjectiveBasicProblem
  • Changed bool[] datatype to BinaryVector
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/EvaluationTracker.cs

    r11956 r11987  
    2222
    2323using System;
    24 using HeuristicLab.Problems.BinaryVector;
     24using HeuristicLab.Common;
     25using HeuristicLab.Core;
     26using HeuristicLab.Encodings.BinaryVectorEncoding;
     27using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     28using HeuristicLab.Problems.Binary;
    2529
    2630namespace HeuristicLab.Algorithms.ParameterlessPopulationPyramid {
     
    2832  // B. W. Goldman and W. F. Punch, "Parameter-less Population Pyramid," GECCO, pp. 785–792, 2014
    2933  // and the original source code in C++11 available from: https://github.com/brianwgoldman/Parameter-less_Population_Pyramid
    30   public class EvaluationTracker : IBinaryVectorProblem {
    31     private readonly IBinaryVectorProblem problem;
     34  internal sealed class EvaluationTracker : BinaryProblem {
     35    private readonly BinaryProblem problem;
    3236
    3337    private int maxEvaluations;
     
    4953    }
    5054
    51     public bool[] BestSolution {
     55    public BinaryVector BestSolution {
    5256      get;
    5357      private set;
     
    5559    #endregion
    5660
    57     public EvaluationTracker(IBinaryVectorProblem problem, int maxEvaluations) {
     61    [StorableConstructor]
     62    private EvaluationTracker(bool deserializing) : base(deserializing) { }
     63    private EvaluationTracker(EvaluationTracker original, Cloner cloner)
     64      : base(original, cloner) {
     65      problem = cloner.Clone(original.problem);
     66      maxEvaluations = original.maxEvaluations;
     67      BestQuality = original.BestQuality;
     68      Evaluations = original.Evaluations;
     69      BestFoundOnEvaluation = original.BestFoundOnEvaluation;
     70      BestSolution = cloner.Clone(BestSolution);
     71    }
     72    public override IDeepCloneable Clone(Cloner cloner) {
     73      return new EvaluationTracker(this, cloner);
     74    }
     75    public EvaluationTracker(BinaryProblem problem, int maxEvaluations) {
    5876      this.problem = problem;
    5977      this.maxEvaluations = maxEvaluations;
    60       BestSolution = new bool[0];
     78      BestSolution = new BinaryVector(Length);
    6179      BestQuality = double.NaN;
    6280      Evaluations = 0;
     
    6482    }
    6583
    66     public double Evaluate(bool[] individual) {
     84
     85
     86    public override double Evaluate(BinaryVector vector, IRandom random) {
    6787      if (Evaluations >= maxEvaluations) throw new OperationCanceledException("Maximum Evaluation Limit Reached");
    6888      Evaluations++;
    69       double fitness = problem.Evaluate(individual);
     89      double fitness = problem.Evaluate(vector, random);
    7090      if (double.IsNaN(BestQuality) || problem.IsBetter(fitness, BestQuality)) {
    7191        BestQuality = fitness;
    72         BestSolution = (bool[])individual.Clone();
     92        BestSolution = (BinaryVector)vector.Clone();
    7393        BestFoundOnEvaluation = Evaluations;
    7494      }
     
    7696    }
    7797
    78     #region ForwardedInteraface
    79     public int Length {
     98    public override int Length {
    8099      get { return problem.Length; }
     100      set { problem.Length = value; }
    81101    }
    82     public bool Maximization {
     102
     103    public override bool Maximization {
    83104      get { return problem.Maximization; }
    84105    }
     106
    85107    public bool IsBetter(double quality, double bestQuality) {
    86108      return problem.IsBetter(quality, bestQuality);
    87109    }
    88     #endregion
     110
    89111  }
    90112}
Note: See TracChangeset for help on using the changeset viewer.