Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/07/14 17:25:50 (10 years ago)
Author:
bgoldman
Message:

#2282 Code cleanup, added Deceptive Step Trap problem.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/Parameter-less Population Pyramid/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/Problems/EvaluationTracker.cs

    r11666 r11669  
    2222using System;
    2323using System.Collections.Generic;
    24 using System.Linq;
    25 using System.Text;
    26 using System.Threading.Tasks;
    2724
    2825namespace HeuristicLab.Algorithms.ParameterlessPopulationPyramid {
    2926  public class EvaluationTracker : IBinaryVectorProblem {
    3027    private readonly IBinaryVectorProblem problem;
     28
    3129    private int maxEvaluations;
    3230
    33     private double bestQuality = double.NaN;
     31    #region Properties
    3432    public double BestQuality {
    35       get { return bestQuality; }
     33      get;
     34      private set;
    3635    }
    3736
    38     private int evaluations = 0;
    3937    public int Evaluations {
    40       get { return evaluations; }
     38      get;
     39      private set;
    4140    }
    4241
    43     private int bestFoundOnEvaluation = 0;
    4442    public int BestFoundOnEvaluation {
    45       get { return bestFoundOnEvaluation; }
     43      get;
     44      private set;
    4645    }
    4746
    4847    public bool[] BestSolution {
    49       get; private set;
     48      get;
     49      private set;
    5050    }
     51    #endregion
    5152
    5253    public EvaluationTracker(IBinaryVectorProblem problem, int maxEvaluations) {
     
    5455      this.maxEvaluations = maxEvaluations;
    5556      BestSolution = new bool[0];
     57      BestQuality = double.NaN;
     58      Evaluations = 0;
     59      BestFoundOnEvaluation = 0;
    5660    }
    5761
    5862    public double Evaluate(bool[] individual) {
    59       if (evaluations >= maxEvaluations) throw new OperationCanceledException("Maximum Evaluation Limit Reached");
    60       evaluations++;
     63      if (Evaluations >= maxEvaluations) throw new OperationCanceledException("Maximum Evaluation Limit Reached");
     64      Evaluations++;
    6165      double fitness = problem.Evaluate(individual);
    62       if (double.IsNaN(bestQuality) || problem.IsBetter(fitness, bestQuality)) {
    63         bestQuality = fitness;
     66      if (double.IsNaN(BestQuality) || problem.IsBetter(fitness, BestQuality)) {
     67        BestQuality = fitness;
    6468        BestSolution = (bool[])individual.Clone();
    65         bestFoundOnEvaluation = evaluations;
     69        BestFoundOnEvaluation = Evaluations;
    6670      }
    6771      return fitness;
    6872    }
    6973
    70 
     74    #region ForwardedInteraface
    7175    public int Length {
    7276      get { return problem.Length; }
     
    7781    public bool IsBetter(double quality, double bestQuality) {
    7882      return problem.IsBetter(quality, bestQuality);
    79     }   
     83    }
     84    #endregion
    8085  }
    8186}
Note: See TracChangeset for help on using the changeset viewer.