Changeset 12018 for branches/ALPS/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/HillClimber.cs
- Timestamp:
- 02/16/15 20:14:52 (9 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/HillClimber.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 * … … 28 28 using HeuristicLab.Core; 29 29 using HeuristicLab.Data; 30 using HeuristicLab.Encodings.BinaryVectorEncoding; 30 31 using HeuristicLab.Optimization; 31 32 using HeuristicLab.Parameters; 32 33 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 33 using HeuristicLab.Problems.Binary Vector;34 using HeuristicLab.Problems.Binary; 34 35 using HeuristicLab.Random; 35 36 … … 49 50 50 51 public override Type ProblemType { 51 get { return typeof(Binary VectorProblem); }52 get { return typeof(BinaryProblem); } 52 53 } 53 public new Binary VectorProblem Problem {54 get { return (Binary VectorProblem)base.Problem; }54 public new BinaryProblem Problem { 55 get { return (BinaryProblem)base.Problem; } 55 56 set { base.Problem = value; } 56 57 } … … 83 84 Results.Add(new Result("Best quality", BestQuality)); 84 85 for (int iteration = 0; iteration < Iterations; iteration++) { 85 bool[] solution = new bool[Problem.Length];86 var solution = new BinaryVector(Problem.Length); 86 87 for (int i = 0; i < solution.Length; i++) { 87 88 solution[i] = random.Next(2) == 1; 88 89 } 89 90 90 var fitness = Problem.Evaluate(solution );91 var fitness = Problem.Evaluate(solution, random); 91 92 92 93 fitness = ImproveToLocalOptimum(Problem, solution, fitness, random); … … 97 98 } 98 99 // In the GECCO paper, Section 2.1 99 public static double ImproveToLocalOptimum( IBinaryVectorProblem problem, bool[]solution, double fitness, IRandom rand) {100 public static double ImproveToLocalOptimum(BinaryProblem problem, BinaryVector solution, double fitness, IRandom rand) { 100 101 var tried = new HashSet<int>(); 101 102 do { … … 104 105 if (tried.Contains(option)) continue; 105 106 solution[option] = !solution[option]; 106 double newFitness = problem.Evaluate(solution );107 double newFitness = problem.Evaluate(solution, rand); 107 108 if (problem.IsBetter(newFitness, fitness)) { 108 109 fitness = newFitness;
Note: See TracChangeset
for help on using the changeset viewer.