Changeset 16692 for branches/2521_ProblemRefactoring/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/ParameterlessPopulationPyramid.cs
- Timestamp:
- 03/18/19 17:24:30 (5 years ago)
- Location:
- branches/2521_ProblemRefactoring
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2521_ProblemRefactoring
- Property svn:ignore
-
old new 24 24 protoc.exe 25 25 obj 26 .vs
-
- Property svn:mergeinfo changed
- Property svn:ignore
-
branches/2521_ProblemRefactoring/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/ParameterlessPopulationPyramid.cs
r13364 r16692 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 5Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * and the BEACON Center for the Study of Evolution in Action. 5 5 * … … 23 23 using System; 24 24 using System.Collections.Generic; 25 using System.Linq; 25 26 using System.Threading; 26 27 using HeuristicLab.Analysis; … … 43 44 public class ParameterlessPopulationPyramid : BasicAlgorithm { 44 45 public override Type ProblemType { 45 get { return typeof(ISingleObjectiveProblemDefinition<BinaryVectorEncoding, BinaryVector>); } 46 } 47 public new ISingleObjectiveProblemDefinition<BinaryVectorEncoding, BinaryVector> Problem { 48 get { return (ISingleObjectiveProblemDefinition<BinaryVectorEncoding, BinaryVector>)base.Problem; } 49 set { base.Problem = (IProblem)value; } 50 } 51 46 get { return typeof(SingleObjectiveProblem<BinaryVectorEncoding, BinaryVector>); } 47 } 48 public new SingleObjectiveProblem<BinaryVectorEncoding, BinaryVector> Problem { 49 get { return (SingleObjectiveProblem<BinaryVectorEncoding, BinaryVector>)base.Problem; } 50 set { base.Problem = value; } 51 } 52 53 [Storable] 52 54 private readonly IRandom random = new MersenneTwister(); 53 private List<Population> pyramid; 55 [Storable] 56 private List<Population> pyramid = new List<Population>(); 57 [Storable] 54 58 private EvaluationTracker tracker; 55 59 56 60 // Tracks all solutions in Pyramid for quick membership checks 61 57 62 private HashSet<BinaryVector> seen = new HashSet<BinaryVector>(new EnumerableBoolEqualityComparer()); 63 [Storable] 64 private IEnumerable<BinaryVector> StorableSeen { 65 get { return seen; } 66 set { seen = new HashSet<BinaryVector>(value, new EnumerableBoolEqualityComparer()); } 67 } 58 68 59 69 #region ParameterNames … … 152 162 #endregion 153 163 164 public override bool SupportsPause { get { return true; } } 165 154 166 [StorableConstructor] 155 167 protected ParameterlessPopulationPyramid(bool deserializing) : base(deserializing) { } … … 157 169 protected ParameterlessPopulationPyramid(ParameterlessPopulationPyramid original, Cloner cloner) 158 170 : base(original, cloner) { 171 random = cloner.Clone(original.random); 172 pyramid = original.pyramid.Select(cloner.Clone).ToList(); 173 tracker = cloner.Clone(original.tracker); 174 seen = new HashSet<BinaryVector>(original.seen.Select(cloner.Clone), new EnumerableBoolEqualityComparer()); 159 175 } 160 176 … … 163 179 } 164 180 165 public ParameterlessPopulationPyramid() {181 public ParameterlessPopulationPyramid() : base() { 166 182 Parameters.Add(new FixedValueParameter<IntValue>(MaximumIterationsParameterName, "", new IntValue(Int32.MaxValue))); 167 183 Parameters.Add(new FixedValueParameter<IntValue>(MaximumEvaluationsParameterName, "", new IntValue(Int32.MaxValue))); … … 212 228 } 213 229 214 protected override void Run(CancellationToken cancellationToken) {230 protected override void Initialize(CancellationToken cancellationToken) { 215 231 // Set up the algorithm 216 232 if (SetSeedRandomly) Seed = new System.Random().Next(); … … 241 257 Results.Add(new Result("Stored Solutions", table)); 242 258 259 base.Initialize(cancellationToken); 260 } 261 262 protected override void Run(CancellationToken cancellationToken) { 243 263 // Loop until iteration limit reached or canceled. 244 for (ResultsIterations = 0; ResultsIterations < MaximumIterations; ResultsIterations++) {264 while (ResultsIterations < MaximumIterations) { 245 265 double fitness = double.NaN; 246 266 247 267 try { 248 268 fitness = iterate(); 269 ResultsIterations++; 249 270 cancellationToken.ThrowIfCancellationRequested(); 250 271 }
Note: See TracChangeset
for help on using the changeset viewer.