Changeset 16692 for branches/2521_ProblemRefactoring/HeuristicLab.Algorithms.ParameterlessPopulationPyramid
- Timestamp:
- 03/18/19 17:24:30 (6 years ago)
- Location:
- branches/2521_ProblemRefactoring
- Files:
-
- 10 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/EnumerableBoolEqualityComparer.cs
r12392 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 * 5 5 * This file is part of HeuristicLab. -
branches/2521_ProblemRefactoring/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/EvaluationTracker.cs
r13361 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 HeuristicLab.Common; 25 26 using HeuristicLab.Core; 26 27 using HeuristicLab.Encodings.BinaryVectorEncoding; 27 28 using HeuristicLab.Optimization; 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 28 30 29 31 namespace HeuristicLab.Algorithms.ParameterlessPopulationPyramid { … … 31 33 // B. W. Goldman and W. F. Punch, "Parameter-less Population Pyramid," GECCO, pp. 785–792, 2014 32 34 // and the original source code in C++11 available from: https://github.com/brianwgoldman/Parameter-less_Population_Pyramid 33 internal sealed class EvaluationTracker : ISingleObjectiveProblemDefinition<BinaryVectorEncoding, BinaryVector> { 34 private readonly ISingleObjectiveProblemDefinition<BinaryVectorEncoding, BinaryVector> problem; 35 35 [StorableClass] 36 internal sealed class EvaluationTracker : Item, ISingleObjectiveProblemDefinition<BinaryVectorEncoding, BinaryVector> { 37 [Storable] 38 private SingleObjectiveProblem<BinaryVectorEncoding, BinaryVector> problem; 39 [Storable] 36 40 private int maxEvaluations; 37 41 38 42 #region Properties 43 [Storable] 39 44 public double BestQuality { 40 45 get; 41 46 private set; 42 47 } 43 48 [Storable] 44 49 public int Evaluations { 45 50 get; 46 51 private set; 47 52 } 48 53 [Storable] 49 54 public int BestFoundOnEvaluation { 50 55 get; 51 56 private set; 52 57 } 53 58 [Storable] 54 59 public BinaryVector BestSolution { 55 60 get; … … 62 67 #endregion 63 68 64 public EvaluationTracker(ISingleObjectiveProblemDefinition<BinaryVectorEncoding, BinaryVector> problem, int maxEvaluations) { 69 70 [StorableConstructor] 71 private EvaluationTracker(bool deserializing) : base(deserializing) { } 72 73 private EvaluationTracker(EvaluationTracker original, Cloner cloner) 74 : base(original, cloner) { 75 problem = cloner.Clone(original.problem); 76 maxEvaluations = original.maxEvaluations; 77 BestQuality = original.BestQuality; 78 Evaluations = original.Evaluations; 79 BestFoundOnEvaluation = original.BestFoundOnEvaluation; 80 BestSolution = cloner.Clone(original.BestSolution); 81 } 82 public override IDeepCloneable Clone(Cloner cloner) { 83 return new EvaluationTracker(this, cloner); 84 } 85 86 public EvaluationTracker(SingleObjectiveProblem<BinaryVectorEncoding, BinaryVector> problem, int maxEvaluations) { 65 87 this.problem = problem; 66 88 this.maxEvaluations = maxEvaluations; -
branches/2521_ProblemRefactoring/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/HillClimber.cs
r13361 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 * … … 47 47 48 48 private const string IterationsParameterName = "Iterations"; 49 private const string BestQualityResultName = "Best quality"; 50 private const string IterationsResultName = "Iterations"; 49 51 50 52 public override Type ProblemType { … … 56 58 } 57 59 60 public override bool SupportsPause { get { return false; } } 61 58 62 public IFixedValueParameter<IntValue> IterationsParameter { 59 63 get { return (IFixedValueParameter<IntValue>)Parameters[IterationsParameterName]; } … … 64 68 set { IterationsParameter.Value.Value = value; } 65 69 } 70 71 #region ResultsProperties 72 private double ResultsBestQuality { 73 get { return ((DoubleValue)Results[BestQualityResultName].Value).Value; } 74 set { ((DoubleValue)Results[BestQualityResultName].Value).Value = value; } 75 } 76 private int ResultsIterations { 77 get { return ((IntValue)Results[IterationsResultName].Value).Value; } 78 set { ((IntValue)Results[IterationsResultName].Value).Value = value; } 79 } 80 #endregion 66 81 67 82 [StorableConstructor] … … 79 94 Parameters.Add(new FixedValueParameter<IntValue>(IterationsParameterName, "", new IntValue(100))); 80 95 } 96 97 98 protected override void Initialize(CancellationToken cancellationToken) { 99 Results.Add(new Result(BestQualityResultName, new DoubleValue(double.NaN))); 100 Results.Add(new Result(IterationsResultName, new IntValue(0))); 101 base.Initialize(cancellationToken); 102 } 81 103 protected override void Run(CancellationToken cancellationToken) { 82 var BestQuality = new DoubleValue(double.NaN);83 Results.Add(new Result("Best quality", BestQuality));84 for (int iteration = 0; iteration < Iterations; iteration++) { 104 while (ResultsIterations < Iterations) { 105 cancellationToken.ThrowIfCancellationRequested(); 106 85 107 var solution = new BinaryVector(Problem.Encoding.Length); 86 108 for (int i = 0; i < solution.Length; i++) { … … 91 113 92 114 fitness = ImproveToLocalOptimum(Problem, solution, fitness, random); 93 if (double.IsNaN( BestQuality.Value) || Problem.IsBetter(fitness, BestQuality.Value)) {94 BestQuality.Value= fitness;115 if (double.IsNaN(ResultsBestQuality) || Problem.IsBetter(fitness, ResultsBestQuality)) { 116 ResultsBestQuality = fitness; 95 117 } 118 119 ResultsIterations++; 96 120 } 97 121 } -
branches/2521_ProblemRefactoring/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/LinkageCrossover.cs
r13361 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 * -
branches/2521_ProblemRefactoring/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/LinkageTree.cs
r12012 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 * … … 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][]; -
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 } -
branches/2521_ProblemRefactoring/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/Plugin.cs.frame
r13385 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 * 5 5 * This file is part of HeuristicLab. … … 29 29 /// Plugin class for HeuristicLab.Algorithms.ParameterlessPopulationPyramid plugin. 30 30 /// </summary> 31 [Plugin("HeuristicLab.Algorithms.ParameterlessPopulationPyramid", "3.3.1 3.$WCREV$")]31 [Plugin("HeuristicLab.Algorithms.ParameterlessPopulationPyramid", "3.3.15.$WCREV$")] 32 32 [PluginFile("HeuristicLab.Algorithms.ParameterlessPopulationPyramid-3.3.dll", PluginFileType.Assembly)] 33 33 [PluginDependency("HeuristicLab.Analysis", "3.3")] -
branches/2521_ProblemRefactoring/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/Population.cs
r12012 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 * … … 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 -
branches/2521_ProblemRefactoring/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/Properties/AssemblyInfo.cs.frame
r13321 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 * 5 5 * This file is part of HeuristicLab. … … 32 32 [assembly: AssemblyCompany("HEAL")] 33 33 [assembly: AssemblyProduct("HeuristicLab")] 34 [assembly: AssemblyCopyright("(c) 2002-201 5HEAL and BEACON Center for the Study of Evolution in Action")]34 [assembly: AssemblyCopyright("(c) 2002-2018 HEAL and BEACON Center for the Study of Evolution in Action")] 35 35 [assembly: AssemblyTrademark("")] 36 36 [assembly: AssemblyCulture("")] … … 54 54 // by using the '*' as shown below: 55 55 [assembly: AssemblyVersion("3.3.0.0")] 56 [assembly: AssemblyFileVersion("3.3.1 3.$WCREV$")]56 [assembly: AssemblyFileVersion("3.3.15.$WCREV$")]
Note: See TracChangeset
for help on using the changeset viewer.