Changeset 15973 for branches/2522_RefactorPluginInfrastructure/HeuristicLab.Algorithms.ParameterlessPopulationPyramid
- Timestamp:
- 06/28/18 11:13:37 (6 years ago)
- Location:
- branches/2522_RefactorPluginInfrastructure
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2522_RefactorPluginInfrastructure
- Property svn:ignore
-
old new 24 24 protoc.exe 25 25 obj 26 .vs
-
- Property svn:mergeinfo changed
- Property svn:ignore
-
branches/2522_RefactorPluginInfrastructure/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/EnumerableBoolEqualityComparer.cs
r12392 r15973 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/2522_RefactorPluginInfrastructure/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/EvaluationTracker.cs
r12057 r15973 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 * … … 34 34 // B. W. Goldman and W. F. Punch, "Parameter-less Population Pyramid," GECCO, pp. 785–792, 2014 35 35 // and the original source code in C++11 available from: https://github.com/brianwgoldman/Parameter-less_Population_Pyramid 36 [StorableClass] 36 37 internal sealed class EvaluationTracker : BinaryProblem { 38 [Storable] 37 39 private readonly BinaryProblem problem; 38 40 [Storable] 39 41 private int maxEvaluations; 40 42 41 43 #region Properties 44 [Storable] 42 45 public double BestQuality { 43 46 get; 44 47 private set; 45 48 } 46 49 [Storable] 47 50 public int Evaluations { 48 51 get; 49 52 private set; 50 53 } 51 54 [Storable] 52 55 public int BestFoundOnEvaluation { 53 56 get; 54 57 private set; 55 58 } 56 59 [Storable] 57 60 public BinaryVector BestSolution { 58 61 get; … … 61 64 #endregion 62 65 66 63 67 [StorableConstructor] 64 68 private EvaluationTracker(bool deserializing) : base(deserializing) { } 69 65 70 private EvaluationTracker(EvaluationTracker original, Cloner cloner) 66 71 : base(original, cloner) { … … 70 75 Evaluations = original.Evaluations; 71 76 BestFoundOnEvaluation = original.BestFoundOnEvaluation; 72 BestSolution = cloner.Clone( BestSolution);77 BestSolution = cloner.Clone(original.BestSolution); 73 78 } 74 79 public override IDeepCloneable Clone(Cloner cloner) { 75 80 return new EvaluationTracker(this, cloner); 76 81 } 82 77 83 public EvaluationTracker(BinaryProblem problem, int maxEvaluations) { 78 84 this.problem = problem; -
branches/2522_RefactorPluginInfrastructure/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/HillClimber.cs
r13173 r15973 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 * … … 48 48 49 49 private const string IterationsParameterName = "Iterations"; 50 private const string BestQualityResultName = "Best quality"; 51 private const string IterationsResultName = "Iterations"; 50 52 51 53 public override Type ProblemType { 52 54 get { return typeof(BinaryProblem); } 53 55 } 56 57 public override bool SupportsPause { get { return false; } } 58 54 59 public new BinaryProblem Problem { 55 60 get { return (BinaryProblem)base.Problem; } … … 65 70 set { IterationsParameter.Value.Value = value; } 66 71 } 72 73 #region ResultsProperties 74 private double ResultsBestQuality { 75 get { return ((DoubleValue)Results[BestQualityResultName].Value).Value; } 76 set { ((DoubleValue)Results[BestQualityResultName].Value).Value = value; } 77 } 78 private int ResultsIterations { 79 get { return ((IntValue)Results[IterationsResultName].Value).Value; } 80 set { ((IntValue)Results[IterationsResultName].Value).Value = value; } 81 } 82 #endregion 67 83 68 84 [StorableConstructor] … … 80 96 Parameters.Add(new FixedValueParameter<IntValue>(IterationsParameterName, "", new IntValue(100))); 81 97 } 98 99 100 protected override void Initialize(CancellationToken cancellationToken) { 101 Results.Add(new Result(BestQualityResultName, new DoubleValue(double.NaN))); 102 Results.Add(new Result(IterationsResultName, new IntValue(0))); 103 base.Initialize(cancellationToken); 104 } 82 105 protected override void Run(CancellationToken cancellationToken) { 83 var BestQuality = new DoubleValue(double.NaN);84 Results.Add(new Result("Best quality", BestQuality));85 for (int iteration = 0; iteration < Iterations; iteration++) { 106 while (ResultsIterations < Iterations) { 107 cancellationToken.ThrowIfCancellationRequested(); 108 86 109 var solution = new BinaryVector(Problem.Length); 87 110 for (int i = 0; i < solution.Length; i++) { … … 92 115 93 116 fitness = ImproveToLocalOptimum(Problem, solution, fitness, random); 94 if (double.IsNaN( BestQuality.Value) || Problem.IsBetter(fitness, BestQuality.Value)) {95 BestQuality.Value= fitness;117 if (double.IsNaN(ResultsBestQuality) || Problem.IsBetter(fitness, ResultsBestQuality)) { 118 ResultsBestQuality = fitness; 96 119 } 120 121 ResultsIterations++; 97 122 } 98 123 } -
branches/2522_RefactorPluginInfrastructure/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/LinkageCrossover.cs
r12012 r15973 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/2522_RefactorPluginInfrastructure/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/LinkageTree.cs
r12012 r15973 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/2522_RefactorPluginInfrastructure/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/ParameterlessPopulationPyramid.cs
r13173 r15973 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; … … 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 62 58 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 … … 153 163 #endregion 154 164 165 public override bool SupportsPause { get { return true; } } 166 155 167 [StorableConstructor] 156 168 protected ParameterlessPopulationPyramid(bool deserializing) : base(deserializing) { } … … 158 170 protected ParameterlessPopulationPyramid(ParameterlessPopulationPyramid original, Cloner cloner) 159 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()); 160 176 } 161 177 … … 164 180 } 165 181 166 public ParameterlessPopulationPyramid() {182 public ParameterlessPopulationPyramid() : base() { 167 183 Parameters.Add(new FixedValueParameter<IntValue>(MaximumIterationsParameterName, "", new IntValue(Int32.MaxValue))); 168 184 Parameters.Add(new FixedValueParameter<IntValue>(MaximumEvaluationsParameterName, "", new IntValue(Int32.MaxValue))); … … 213 229 } 214 230 215 protected override void Run(CancellationToken cancellationToken) {231 protected override void Initialize(CancellationToken cancellationToken) { 216 232 // Set up the algorithm 217 233 if (SetSeedRandomly) Seed = new System.Random().Next(); … … 242 258 Results.Add(new Result("Stored Solutions", table)); 243 259 260 base.Initialize(cancellationToken); 261 } 262 263 protected override void Run(CancellationToken cancellationToken) { 244 264 // Loop until iteration limit reached or canceled. 245 for (ResultsIterations = 0; ResultsIterations < MaximumIterations; ResultsIterations++) {265 while (ResultsIterations < MaximumIterations) { 246 266 double fitness = double.NaN; 247 267 248 268 try { 249 269 fitness = iterate(); 270 ResultsIterations++; 250 271 cancellationToken.ThrowIfCancellationRequested(); 251 } finally { 272 } 273 finally { 252 274 ResultsEvaluations = tracker.Evaluations; 253 275 ResultsBestSolution = new BinaryVector(tracker.BestSolution); -
branches/2522_RefactorPluginInfrastructure/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/Plugin.cs.frame
r13321 r15973 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/2522_RefactorPluginInfrastructure/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/Population.cs
r12012 r15973 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/2522_RefactorPluginInfrastructure/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/Properties/AssemblyInfo.cs.frame
r13321 r15973 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.