Changeset 11987 for trunk/sources/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/HillClimber.cs
- Timestamp:
- 02/12/15 15:39:28 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/HillClimber.cs
r11960 r11987 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.