Changeset 13339 for branches/ProblemRefactoring/HeuristicLab.Algorithms.ParameterlessPopulationPyramid
- Timestamp:
- 11/23/15 16:14:57 (9 years ago)
- Location:
- branches/ProblemRefactoring/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ProblemRefactoring/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/EvaluationTracker.cs
r12057 r13339 26 26 using HeuristicLab.Data; 27 27 using HeuristicLab.Encodings.BinaryVectorEncoding; 28 using HeuristicLab.Optimization; 28 29 using HeuristicLab.Parameters; 29 30 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 30 using HeuristicLab.Problems.Binary;31 31 32 32 namespace HeuristicLab.Algorithms.ParameterlessPopulationPyramid { … … 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 internal sealed class EvaluationTracker : BinaryProblem{37 private readonly BinaryProblemproblem;36 internal sealed class EvaluationTracker : SingleObjectiveProblem<BinaryVectorEncoding, BinaryVector> { 37 private readonly ISingleObjectiveProblem<BinaryVectorEncoding, BinaryVector> problem; 38 38 39 39 private int maxEvaluations; … … 59 59 private set; 60 60 } 61 62 public new BinaryVectorEncoding Encoding { 63 get { return problem.Encoding; } 64 } 61 65 #endregion 62 66 … … 75 79 return new EvaluationTracker(this, cloner); 76 80 } 77 public EvaluationTracker( BinaryProblemproblem, int maxEvaluations) {81 public EvaluationTracker(ISingleObjectiveProblem<BinaryVectorEncoding, BinaryVector> problem, int maxEvaluations) { 78 82 this.problem = problem; 79 83 this.maxEvaluations = maxEvaluations; 80 BestSolution = new BinaryVector( Length);84 BestSolution = new BinaryVector(problem.Encoding.Length); 81 85 BestQuality = double.NaN; 82 86 Evaluations = 0; … … 99 103 } 100 104 101 public override int Length {102 get { return problem.Length; }103 set { problem.Length = value; }104 }105 106 105 public override bool Maximization { 107 106 get { -
branches/ProblemRefactoring/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/HeuristicLab.Algorithms.ParameterlessPopulationPyramid-3.3.csproj
r11994 r13339 148 148 <Private>False</Private> 149 149 </ProjectReference> 150 <ProjectReference Include="..\..\HeuristicLab.Problems.Binary\3.3\HeuristicLab.Problems.Binary-3.3.csproj">151 <Project>{fc627be5-0f93-47d8-bd2e-530ea2b8aa5f}</Project>152 <Name>HeuristicLab.Problems.Binary-3.3</Name>153 <Private>False</Private>154 </ProjectReference>155 150 <ProjectReference Include="..\..\HeuristicLab.Random\3.3\HeuristicLab.Random-3.3.csproj"> 156 151 <Project>{f4539fb6-4708-40c9-be64-0a1390aea197}</Project> -
branches/ProblemRefactoring/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/HillClimber.cs
r13173 r13339 32 32 using HeuristicLab.Parameters; 33 33 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 34 using HeuristicLab.Problems.Binary;35 34 using HeuristicLab.Random; 36 35 … … 50 49 51 50 public override Type ProblemType { 52 get { return typeof( BinaryProblem); }51 get { return typeof(ISingleObjectiveProblem<BinaryVectorEncoding, BinaryVector>); } 53 52 } 54 public new BinaryProblemProblem {55 get { return ( BinaryProblem)base.Problem; }53 public new ISingleObjectiveProblem<BinaryVectorEncoding, BinaryVector> Problem { 54 get { return (ISingleObjectiveProblem<BinaryVectorEncoding, BinaryVector>)base.Problem; } 56 55 set { base.Problem = value; } 57 56 } … … 84 83 Results.Add(new Result("Best quality", BestQuality)); 85 84 for (int iteration = 0; iteration < Iterations; iteration++) { 86 var solution = new BinaryVector(Problem. Length);85 var solution = new BinaryVector(Problem.Encoding.Length); 87 86 for (int i = 0; i < solution.Length; i++) { 88 87 solution[i] = random.Next(2) == 1; … … 98 97 } 99 98 // In the GECCO paper, Section 2.1 100 public static double ImproveToLocalOptimum( BinaryProblemproblem, BinaryVector solution, double fitness, IRandom rand) {99 public static double ImproveToLocalOptimum(ISingleObjectiveProblem<BinaryVectorEncoding, BinaryVector> problem, BinaryVector solution, double fitness, IRandom rand) { 101 100 var tried = new HashSet<int>(); 102 101 do { -
branches/ProblemRefactoring/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/LinkageCrossover.cs
r12012 r13339 24 24 using HeuristicLab.Core; 25 25 using HeuristicLab.Encodings.BinaryVectorEncoding; 26 using HeuristicLab. Problems.Binary;26 using HeuristicLab.Optimization; 27 27 using HeuristicLab.Random; 28 28 … … 33 33 public static class LinkageCrossover { 34 34 // In the GECCO paper, Figure 3 35 public static double ImproveUsingTree(LinkageTree tree, IList<BinaryVector> donors, BinaryVector solution, double fitness, BinaryProblemproblem, IRandom rand) {35 public static double ImproveUsingTree(LinkageTree tree, IList<BinaryVector> donors, BinaryVector solution, double fitness, ISingleObjectiveProblem<BinaryVectorEncoding, BinaryVector> problem, IRandom rand) { 36 36 var options = Enumerable.Range(0, donors.Count).ToArray(); 37 37 foreach (var cluster in tree.Clusters) { … … 48 48 } 49 49 50 private static double Donate(BinaryVector solution, double fitness, BinaryVector source, IEnumerable<int> cluster, BinaryProblemproblem, IRandom rand, out bool changed) {50 private static double Donate(BinaryVector solution, double fitness, BinaryVector source, IEnumerable<int> cluster, ISingleObjectiveProblem<BinaryVectorEncoding, BinaryVector> problem, IRandom rand, out bool changed) { 51 51 // keep track of which bits flipped to make the donation 52 52 List<int> flipped = new List<int>(); -
branches/ProblemRefactoring/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/ParameterlessPopulationPyramid.cs
r13173 r13339 32 32 using HeuristicLab.Parameters; 33 33 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 34 using HeuristicLab.Problems.Binary;35 34 using HeuristicLab.Random; 36 35 … … 44 43 public class ParameterlessPopulationPyramid : BasicAlgorithm { 45 44 public override Type ProblemType { 46 get { return typeof( BinaryProblem); }47 } 48 public new BinaryProblemProblem {49 get { return ( BinaryProblem)base.Problem; }45 get { return typeof(ISingleObjectiveProblem<BinaryVectorEncoding, BinaryVector>); } 46 } 47 public new ISingleObjectiveProblem<BinaryVectorEncoding, BinaryVector> Problem { 48 get { return (ISingleObjectiveProblem<BinaryVectorEncoding, BinaryVector>)base.Problem; } 50 49 set { base.Problem = value; } 51 50 } … … 183 182 if (seen.Contains(solution)) return; 184 183 if (level == pyramid.Count) { 185 pyramid.Add(new Population(tracker. Length, random));184 pyramid.Add(new Population(tracker.Encoding.Length, random)); 186 185 } 187 186 var copied = (BinaryVector)solution.Clone(); … … 193 192 private double iterate() { 194 193 // Create a random solution 195 BinaryVector solution = new BinaryVector(tracker. Length);194 BinaryVector solution = new BinaryVector(tracker.Encoding.Length); 196 195 for (int i = 0; i < solution.Length; i++) { 197 196 solution[i] = random.Next(2) == 1; … … 249 248 fitness = iterate(); 250 249 cancellationToken.ThrowIfCancellationRequested(); 251 } finally { 250 } 251 finally { 252 252 ResultsEvaluations = tracker.Evaluations; 253 253 ResultsBestSolution = new BinaryVector(tracker.BestSolution);
Note: See TracChangeset
for help on using the changeset viewer.