Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/13/15 15:00:15 (9 years ago)
Author:
abeham
Message:

#2174, #2282: merged revisions r11961,r11963,r11967,r11970,r11971,r11982,r11984,r11998,r12001,r12002,r12003,r12004,r11939,r11945,r11956,r11958,r11959,r11960,r11983,r11987,r11988,r11990,r11993,r11994,r11996,r11999,r12000 to stable

Location:
stable
Files:
2 edited
1 copied

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/HillClimber.cs

    r11838 r12005  
    2828using HeuristicLab.Core;
    2929using HeuristicLab.Data;
     30using HeuristicLab.Encodings.BinaryVectorEncoding;
    3031using HeuristicLab.Optimization;
    3132using HeuristicLab.Parameters;
    3233using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     34using HeuristicLab.Problems.Binary;
    3335using HeuristicLab.Random;
    3436
     
    3840  // B. W. Goldman and W. F. Punch, "Parameter-less Population Pyramid," GECCO, pp. 785–792, 2014
    3941  // and the original source code in C++11 available from: https://github.com/brianwgoldman/Parameter-less_Population_Pyramid
    40   [Item("Hill Climber", "Test algorithm.")]
     42  [Item("Hill Climber", "Binary Hill Climber.")]
    4143  [StorableClass]
    42   [Creatable("Parameterless Population Pyramid")]
     44  [Creatable("Algorithms")]
    4345  public class HillClimber : BasicAlgorithm {
    4446    [Storable]
     
    4850
    4951    public override Type ProblemType {
    50       get { return typeof(BinaryVectorProblem); }
     52      get { return typeof(BinaryProblem); }
    5153    }
    52     public new BinaryVectorProblem Problem {
    53       get { return (BinaryVectorProblem)base.Problem; }
     54    public new BinaryProblem Problem {
     55      get { return (BinaryProblem)base.Problem; }
    5456      set { base.Problem = value; }
    5557    }
     
    8284      Results.Add(new Result("Best quality", BestQuality));
    8385      for (int iteration = 0; iteration < Iterations; iteration++) {
    84         bool[] solution = new bool[Problem.Length];
     86        var solution = new BinaryVector(Problem.Length);
    8587        for (int i = 0; i < solution.Length; i++) {
    8688          solution[i] = random.Next(2) == 1;
    8789        }
    8890
    89         var fitness = Problem.Evaluate(solution);
     91        var fitness = Problem.Evaluate(solution, random);
    9092
    9193        fitness = ImproveToLocalOptimum(Problem, solution, fitness, random);
     
    9698    }
    9799    // In the GECCO paper, Section 2.1
    98     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) {
    99101      var tried = new HashSet<int>();
    100102      do {
     
    103105          if (tried.Contains(option)) continue;
    104106          solution[option] = !solution[option];
    105           double newFitness = problem.Evaluate(solution);
     107          double newFitness = problem.Evaluate(solution, rand);
    106108          if (problem.IsBetter(newFitness, fitness)) {
    107109            fitness = newFitness;
Note: See TracChangeset for help on using the changeset viewer.