Changeset 12018 for branches/ALPS/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/ParameterlessPopulationPyramid.cs
- Timestamp:
- 02/16/15 20:14:52 (10 years ago)
- Location:
- branches/ALPS
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ALPS
- Property svn:mergeinfo changed
/stable merged: 12008-12010 /trunk/sources merged: 11978,11982-11984,11987-11994,11996,11998-12004,12012,12015-12016
- Property svn:mergeinfo changed
-
branches/ALPS/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/ParameterlessPopulationPyramid.cs
r11960 r12018 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 4Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * and the BEACON Center for the Study of Evolution in Action. 5 5 * … … 32 32 using HeuristicLab.Parameters; 33 33 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 34 using HeuristicLab.Problems.Binary Vector;34 using HeuristicLab.Problems.Binary; 35 35 using HeuristicLab.Random; 36 36 … … 44 44 public class ParameterlessPopulationPyramid : BasicAlgorithm { 45 45 public override Type ProblemType { 46 get { return typeof(Binary VectorProblem); }47 } 48 public new Binary VectorProblem Problem {49 get { return (Binary VectorProblem)base.Problem; }46 get { return typeof(BinaryProblem); } 47 } 48 public new BinaryProblem Problem { 49 get { return (BinaryProblem)base.Problem; } 50 50 set { base.Problem = value; } 51 51 } … … 56 56 57 57 // Tracks all solutions in Pyramid for quick membership checks 58 private HashSet< bool[]> seen = new HashSet<bool[]>(new EnumerableBoolEqualityComparer());58 private HashSet<BinaryVector> seen = new HashSet<BinaryVector>(new EnumerableBoolEqualityComparer()); 59 59 60 60 #region ParameterNames … … 179 179 } 180 180 181 private void AddIfUnique( bool[]solution, int level) {181 private void AddIfUnique(BinaryVector solution, int level) { 182 182 // Don't add things you have seen 183 183 if (seen.Contains(solution)) return; … … 185 185 pyramid.Add(new Population(tracker.Length, random)); 186 186 } 187 var copied = ( bool[])solution.Clone();187 var copied = (BinaryVector)solution.Clone(); 188 188 pyramid[level].Add(copied); 189 189 seen.Add(copied); … … 193 193 private double iterate() { 194 194 // Create a random solution 195 bool[] solution = new bool[tracker.Length];195 BinaryVector solution = new BinaryVector(tracker.Length); 196 196 for (int i = 0; i < solution.Length; i++) { 197 197 solution[i] = random.Next(2) == 1; 198 198 } 199 double fitness = tracker.Evaluate(solution );199 double fitness = tracker.Evaluate(solution, random); 200 200 fitness = HillClimber.ImproveToLocalOptimum(tracker, solution, fitness, random); 201 201 AddIfUnique(solution, 0); … … 249 249 fitness = iterate(); 250 250 cancellationToken.ThrowIfCancellationRequested(); 251 } 252 finally { 251 } finally { 253 252 ResultsEvaluations = tracker.Evaluations; 254 253 ResultsBestSolution = new BinaryVector(tracker.BestSolution);
Note: See TracChangeset
for help on using the changeset viewer.