Changeset 12005 for stable/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/EvaluationTracker.cs
- Timestamp:
- 02/13/15 15:00:15 (9 years ago)
- Location:
- stable
- Files:
-
- 1 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
stable
- Property svn:mergeinfo changed
/trunk/sources merged: 11939,11945,11956,11958-11961,11963,11967,11970-11971,11982-11984,11987-11988,11990,11993-11994,11996,11998-12004
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/EvaluationTracker.cs
r11956 r12005 22 22 23 23 using System; 24 using HeuristicLab.Problems.BinaryVector; 24 using HeuristicLab.Common; 25 using HeuristicLab.Core; 26 using HeuristicLab.Data; 27 using HeuristicLab.Encodings.BinaryVectorEncoding; 28 using HeuristicLab.Parameters; 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 30 using HeuristicLab.Problems.Binary; 25 31 26 32 namespace HeuristicLab.Algorithms.ParameterlessPopulationPyramid { … … 28 34 // B. W. Goldman and W. F. Punch, "Parameter-less Population Pyramid," GECCO, pp. 785–792, 2014 29 35 // 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;36 internal sealed class EvaluationTracker : BinaryProblem { 37 private readonly BinaryProblem problem; 32 38 33 39 private int maxEvaluations; … … 49 55 } 50 56 51 public bool[]BestSolution {57 public BinaryVector BestSolution { 52 58 get; 53 59 private set; … … 55 61 #endregion 56 62 57 public EvaluationTracker(IBinaryVectorProblem problem, int maxEvaluations) { 63 [StorableConstructor] 64 private EvaluationTracker(bool deserializing) : base(deserializing) { } 65 private EvaluationTracker(EvaluationTracker original, Cloner cloner) 66 : base(original, cloner) { 67 problem = cloner.Clone(original.problem); 68 maxEvaluations = original.maxEvaluations; 69 BestQuality = original.BestQuality; 70 Evaluations = original.Evaluations; 71 BestFoundOnEvaluation = original.BestFoundOnEvaluation; 72 BestSolution = cloner.Clone(BestSolution); 73 } 74 public override IDeepCloneable Clone(Cloner cloner) { 75 return new EvaluationTracker(this, cloner); 76 } 77 public EvaluationTracker(BinaryProblem problem, int maxEvaluations) { 58 78 this.problem = problem; 59 79 this.maxEvaluations = maxEvaluations; 60 BestSolution = new bool[0];80 BestSolution = new BinaryVector(Length); 61 81 BestQuality = double.NaN; 62 82 Evaluations = 0; 63 83 BestFoundOnEvaluation = 0; 84 85 if (Parameters.ContainsKey("Maximization")) Parameters.Remove("Maximization"); 86 Parameters.Add(new FixedValueParameter<BoolValue>("Maximization", "Set to false if the problem should be minimized.", (BoolValue)new BoolValue(Maximization).AsReadOnly()) { Hidden = true }); 64 87 } 65 88 66 public double Evaluate(bool[] individual) {89 public override double Evaluate(BinaryVector vector, IRandom random) { 67 90 if (Evaluations >= maxEvaluations) throw new OperationCanceledException("Maximum Evaluation Limit Reached"); 68 91 Evaluations++; 69 double fitness = problem.Evaluate( individual);92 double fitness = problem.Evaluate(vector, random); 70 93 if (double.IsNaN(BestQuality) || problem.IsBetter(fitness, BestQuality)) { 71 94 BestQuality = fitness; 72 BestSolution = ( bool[])individual.Clone();95 BestSolution = (BinaryVector)vector.Clone(); 73 96 BestFoundOnEvaluation = Evaluations; 74 97 } … … 76 99 } 77 100 78 #region ForwardedInteraface 79 public int Length { 101 public override int Length { 80 102 get { return problem.Length; } 103 set { problem.Length = value; } 81 104 } 82 public bool Maximization { 83 get { return problem.Maximization; } 105 106 public override bool Maximization { 107 get { 108 if (problem == null) return false; 109 return problem.Maximization; 110 } 84 111 } 112 85 113 public bool IsBetter(double quality, double bestQuality) { 86 114 return problem.IsBetter(quality, bestQuality); 87 115 } 88 #endregion 116 89 117 } 90 118 }
Note: See TracChangeset
for help on using the changeset viewer.