Changeset 11987 for trunk/sources/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/EvaluationTracker.cs
- Timestamp:
- 02/12/15 15:39:28 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/EvaluationTracker.cs
r11956 r11987 22 22 23 23 using System; 24 using HeuristicLab.Problems.BinaryVector; 24 using HeuristicLab.Common; 25 using HeuristicLab.Core; 26 using HeuristicLab.Encodings.BinaryVectorEncoding; 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 28 using HeuristicLab.Problems.Binary; 25 29 26 30 namespace HeuristicLab.Algorithms.ParameterlessPopulationPyramid { … … 28 32 // B. W. Goldman and W. F. Punch, "Parameter-less Population Pyramid," GECCO, pp. 785–792, 2014 29 33 // 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; 32 36 33 37 private int maxEvaluations; … … 49 53 } 50 54 51 public bool[]BestSolution {55 public BinaryVector BestSolution { 52 56 get; 53 57 private set; … … 55 59 #endregion 56 60 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) { 58 76 this.problem = problem; 59 77 this.maxEvaluations = maxEvaluations; 60 BestSolution = new bool[0];78 BestSolution = new BinaryVector(Length); 61 79 BestQuality = double.NaN; 62 80 Evaluations = 0; … … 64 82 } 65 83 66 public double Evaluate(bool[] individual) { 84 85 86 public override double Evaluate(BinaryVector vector, IRandom random) { 67 87 if (Evaluations >= maxEvaluations) throw new OperationCanceledException("Maximum Evaluation Limit Reached"); 68 88 Evaluations++; 69 double fitness = problem.Evaluate( individual);89 double fitness = problem.Evaluate(vector, random); 70 90 if (double.IsNaN(BestQuality) || problem.IsBetter(fitness, BestQuality)) { 71 91 BestQuality = fitness; 72 BestSolution = ( bool[])individual.Clone();92 BestSolution = (BinaryVector)vector.Clone(); 73 93 BestFoundOnEvaluation = Evaluations; 74 94 } … … 76 96 } 77 97 78 #region ForwardedInteraface 79 public int Length { 98 public override int Length { 80 99 get { return problem.Length; } 100 set { problem.Length = value; } 81 101 } 82 public bool Maximization { 102 103 public override bool Maximization { 83 104 get { return problem.Maximization; } 84 105 } 106 85 107 public bool IsBetter(double quality, double bestQuality) { 86 108 return problem.IsBetter(quality, bestQuality); 87 109 } 88 #endregion 110 89 111 } 90 112 }
Note: See TracChangeset
for help on using the changeset viewer.