Changeset 15324
- Timestamp:
- 08/11/17 11:45:16 (7 years ago)
- Location:
- stable
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
stable
- Property svn:mergeinfo changed
/trunk/sources merged: 15301
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/EvaluationTracker.cs
r14186 r15324 27 27 using HeuristicLab.Encodings.BinaryVectorEncoding; 28 28 using HeuristicLab.Parameters; 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 29 30 using HeuristicLab.Problems.Binary; 30 31 … … 33 34 // B. W. Goldman and W. F. Punch, "Parameter-less Population Pyramid," GECCO, pp. 785–792, 2014 34 35 // and the original source code in C++11 available from: https://github.com/brianwgoldman/Parameter-less_Population_Pyramid 36 [StorableClass] 35 37 internal sealed class EvaluationTracker : BinaryProblem { 38 [Storable] 36 39 private readonly BinaryProblem problem; 37 40 [Storable] 38 41 private int maxEvaluations; 39 42 40 43 #region Properties 44 [Storable] 41 45 public double BestQuality { 42 46 get; 43 47 private set; 44 48 } 45 49 [Storable] 46 50 public int Evaluations { 47 51 get; 48 52 private set; 49 53 } 50 54 [Storable] 51 55 public int BestFoundOnEvaluation { 52 56 get; 53 57 private set; 54 58 } 55 59 [Storable] 56 60 public BinaryVector BestSolution { 57 61 get; … … 59 63 } 60 64 #endregion 65 66 67 [StorableConstructor] 68 private EvaluationTracker(bool deserializing) : base(deserializing) { } 61 69 62 70 private EvaluationTracker(EvaluationTracker original, Cloner cloner) … … 67 75 Evaluations = original.Evaluations; 68 76 BestFoundOnEvaluation = original.BestFoundOnEvaluation; 69 BestSolution = cloner.Clone( BestSolution);77 BestSolution = cloner.Clone(original.BestSolution); 70 78 } 71 79 public override IDeepCloneable Clone(Cloner cloner) { 72 80 return new EvaluationTracker(this, cloner); 73 81 } 82 74 83 public EvaluationTracker(BinaryProblem problem, int maxEvaluations) { 75 84 this.problem = problem; -
stable/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/LinkageTree.cs
r14186 r15324 27 27 using HeuristicLab.Core; 28 28 using HeuristicLab.Encodings.BinaryVectorEncoding; 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 29 30 using HeuristicLab.Random; 30 31 … … 33 34 // B. W. Goldman and W. F. Punch, "Parameter-less Population Pyramid," GECCO, pp. 785–792, 2014 34 35 // and the original source code in C++11 available from: https://github.com/brianwgoldman/Parameter-less_Population_Pyramid 35 public class LinkageTree { 36 [StorableClass] 37 public class LinkageTree : DeepCloneable { 38 [Storable] 36 39 private readonly int[][][] occurances; 40 [Storable] 37 41 private readonly List<int>[] clusters; 42 [Storable] 38 43 private List<int> clusterOrdering; 44 [Storable] 39 45 private readonly int length; 46 [Storable] 40 47 private readonly IRandom rand; 48 [Storable] 41 49 private bool rebuildRequired = false; 50 51 52 [StorableConstructor] 53 protected LinkageTree(bool deserializing) : base() { } 54 55 56 protected LinkageTree(LinkageTree original, Cloner cloner) : base(original, cloner) { 57 occurances = new int[original.occurances.Length][][]; 58 //mkommend: first entry is not used, cf. ctor line 83 59 for (int i = 1; i < original.occurances.Length; i++) { 60 occurances[i] = new int[original.occurances[i].Length][]; 61 for (int j = 0; j < original.occurances[i].Length; j++) 62 occurances[i][j] = original.occurances[i][j].ToArray(); 63 } 64 65 clusters = original.clusters.Select(c => c.ToList()).ToArray(); 66 clusterOrdering = new List<int>(original.clusterOrdering); 67 length = original.length; 68 rand = cloner.Clone(original.rand); 69 rebuildRequired = original.rebuildRequired; 70 } 71 72 73 public override IDeepCloneable Clone(Cloner cloner) { 74 return new LinkageTree(this, cloner); 75 } 42 76 43 77 public LinkageTree(int length, IRandom rand) { … … 93 127 // Uses the frequency table to calcuate the entropy distance between two indices. 94 128 // In the GECCO paper, calculates Equation 1 95 private int[] bits = new int[4];96 129 private double EntropyDistance(int i, int j) { 130 int[] bits = new int[4]; 97 131 // This ensures you are using the lower triangular part of "occurances" 98 132 if (i < j) { … … 125 159 // by I. Gronau and S. Moran 126 160 // In the GECCO paper, Figure 2 is a simplified version of this algorithm. 127 private double[][] distances;128 161 private void Rebuild() { 162 double[][] distances = null; 129 163 if (distances == null) { 130 164 distances = new double[clusters.Length * 2 - 1][]; -
stable/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/ParameterlessPopulationPyramid.cs
r15061 r15324 23 23 using System; 24 24 using System.Collections.Generic; 25 using System.Linq; 25 26 using System.Threading; 26 27 using HeuristicLab.Analysis; … … 51 52 } 52 53 54 [Storable] 53 55 private readonly IRandom random = new MersenneTwister(); 54 private List<Population> pyramid; 56 [Storable] 57 private List<Population> pyramid = new List<Population>(); 58 [Storable] 55 59 private EvaluationTracker tracker; 56 60 57 61 // Tracks all solutions in Pyramid for quick membership checks 58 private readonly HashSet<BinaryVector> seen = new HashSet<BinaryVector>(new EnumerableBoolEqualityComparer()); 62 63 private HashSet<BinaryVector> seen = new HashSet<BinaryVector>(new EnumerableBoolEqualityComparer()); 64 [Storable] 65 private IEnumerable<BinaryVector> StorableSeen { 66 get { return seen; } 67 set { seen = new HashSet<BinaryVector>(value, new EnumerableBoolEqualityComparer()); } 68 } 59 69 60 70 #region ParameterNames … … 160 170 protected ParameterlessPopulationPyramid(ParameterlessPopulationPyramid original, Cloner cloner) 161 171 : base(original, cloner) { 172 random = cloner.Clone(original.random); 173 pyramid = original.pyramid.Select(cloner.Clone).ToList(); 174 tracker = cloner.Clone(original.tracker); 175 seen = new HashSet<BinaryVector>(original.seen.Select(cloner.Clone), new EnumerableBoolEqualityComparer()); 162 176 } 163 177 … … 166 180 } 167 181 168 public ParameterlessPopulationPyramid() {182 public ParameterlessPopulationPyramid() : base() { 169 183 Parameters.Add(new FixedValueParameter<IntValue>(MaximumIterationsParameterName, "", new IntValue(Int32.MaxValue))); 170 184 Parameters.Add(new FixedValueParameter<IntValue>(MaximumEvaluationsParameterName, "", new IntValue(Int32.MaxValue))); … … 256 270 ResultsIterations++; 257 271 cancellationToken.ThrowIfCancellationRequested(); 258 } finally { 272 } 273 finally { 259 274 ResultsEvaluations = tracker.Evaluations; 260 275 ResultsBestSolution = new BinaryVector(tracker.BestSolution); -
stable/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/Population.cs
r14186 r15324 22 22 23 23 using System.Collections.Generic; 24 using System.Linq; 25 using HeuristicLab.Common; 24 26 using HeuristicLab.Core; 25 27 using HeuristicLab.Encodings.BinaryVectorEncoding; 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 26 29 27 30 namespace HeuristicLab.Algorithms.ParameterlessPopulationPyramid { … … 29 32 // B. W. Goldman and W. F. Punch, "Parameter-less Population Pyramid," GECCO, pp. 785–792, 2014 30 33 // and the original source code in C++11 available from: https://github.com/brianwgoldman/Parameter-less_Population_Pyramid 31 public class Population { 34 [StorableClass] 35 public class Population : DeepCloneable { 36 [Storable] 32 37 public List<BinaryVector> Solutions { 33 38 get; 34 39 private set; 35 40 } 36 41 [Storable] 37 42 public LinkageTree Tree { 38 43 get; 39 44 private set; 45 } 46 47 48 [StorableConstructor] 49 protected Population(bool deserializing) : base() { } 50 51 52 protected Population(Population original, Cloner cloner) : base(original, cloner) { 53 Solutions = original.Solutions.Select(cloner.Clone).ToList(); 54 Tree = cloner.Clone(original.Tree); 55 } 56 57 public override IDeepCloneable Clone(Cloner cloner) { 58 return new Population(this, cloner); 40 59 } 41 60
Note: See TracChangeset
for help on using the changeset viewer.