Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/23/15 16:14:57 (8 years ago)
Author:
mkommend
Message:

#2521: Rectored problems and encodings.

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  
    2626using HeuristicLab.Data;
    2727using HeuristicLab.Encodings.BinaryVectorEncoding;
     28using HeuristicLab.Optimization;
    2829using HeuristicLab.Parameters;
    2930using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    30 using HeuristicLab.Problems.Binary;
    3131
    3232namespace HeuristicLab.Algorithms.ParameterlessPopulationPyramid {
     
    3434  // B. W. Goldman and W. F. Punch, "Parameter-less Population Pyramid," GECCO, pp. 785–792, 2014
    3535  // 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 BinaryProblem problem;
     36  internal sealed class EvaluationTracker : SingleObjectiveProblem<BinaryVectorEncoding, BinaryVector> {
     37    private readonly ISingleObjectiveProblem<BinaryVectorEncoding, BinaryVector> problem;
    3838
    3939    private int maxEvaluations;
     
    5959      private set;
    6060    }
     61
     62    public new BinaryVectorEncoding Encoding {
     63      get { return problem.Encoding; }
     64    }
    6165    #endregion
    6266
     
    7579      return new EvaluationTracker(this, cloner);
    7680    }
    77     public EvaluationTracker(BinaryProblem problem, int maxEvaluations) {
     81    public EvaluationTracker(ISingleObjectiveProblem<BinaryVectorEncoding, BinaryVector> problem, int maxEvaluations) {
    7882      this.problem = problem;
    7983      this.maxEvaluations = maxEvaluations;
    80       BestSolution = new BinaryVector(Length);
     84      BestSolution = new BinaryVector(problem.Encoding.Length);
    8185      BestQuality = double.NaN;
    8286      Evaluations = 0;
     
    99103    }
    100104
    101     public override int Length {
    102       get { return problem.Length; }
    103       set { problem.Length = value; }
    104     }
    105 
    106105    public override bool Maximization {
    107106      get {
  • branches/ProblemRefactoring/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/HeuristicLab.Algorithms.ParameterlessPopulationPyramid-3.3.csproj

    r11994 r13339  
    148148      <Private>False</Private>
    149149    </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>
    155150    <ProjectReference Include="..\..\HeuristicLab.Random\3.3\HeuristicLab.Random-3.3.csproj">
    156151      <Project>{f4539fb6-4708-40c9-be64-0a1390aea197}</Project>
  • branches/ProblemRefactoring/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/HillClimber.cs

    r13173 r13339  
    3232using HeuristicLab.Parameters;
    3333using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    34 using HeuristicLab.Problems.Binary;
    3534using HeuristicLab.Random;
    3635
     
    5049
    5150    public override Type ProblemType {
    52       get { return typeof(BinaryProblem); }
     51      get { return typeof(ISingleObjectiveProblem<BinaryVectorEncoding, BinaryVector>); }
    5352    }
    54     public new BinaryProblem Problem {
    55       get { return (BinaryProblem)base.Problem; }
     53    public new ISingleObjectiveProblem<BinaryVectorEncoding, BinaryVector> Problem {
     54      get { return (ISingleObjectiveProblem<BinaryVectorEncoding, BinaryVector>)base.Problem; }
    5655      set { base.Problem = value; }
    5756    }
     
    8483      Results.Add(new Result("Best quality", BestQuality));
    8584      for (int iteration = 0; iteration < Iterations; iteration++) {
    86         var solution = new BinaryVector(Problem.Length);
     85        var solution = new BinaryVector(Problem.Encoding.Length);
    8786        for (int i = 0; i < solution.Length; i++) {
    8887          solution[i] = random.Next(2) == 1;
     
    9897    }
    9998    // In the GECCO paper, Section 2.1
    100     public static double ImproveToLocalOptimum(BinaryProblem problem, BinaryVector solution, double fitness, IRandom rand) {
     99    public static double ImproveToLocalOptimum(ISingleObjectiveProblem<BinaryVectorEncoding, BinaryVector> problem, BinaryVector solution, double fitness, IRandom rand) {
    101100      var tried = new HashSet<int>();
    102101      do {
  • branches/ProblemRefactoring/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/LinkageCrossover.cs

    r12012 r13339  
    2424using HeuristicLab.Core;
    2525using HeuristicLab.Encodings.BinaryVectorEncoding;
    26 using HeuristicLab.Problems.Binary;
     26using HeuristicLab.Optimization;
    2727using HeuristicLab.Random;
    2828
     
    3333  public static class LinkageCrossover {
    3434    // In the GECCO paper, Figure 3
    35     public static double ImproveUsingTree(LinkageTree tree, IList<BinaryVector> donors, BinaryVector solution, double fitness, BinaryProblem problem, IRandom rand) {
     35    public static double ImproveUsingTree(LinkageTree tree, IList<BinaryVector> donors, BinaryVector solution, double fitness, ISingleObjectiveProblem<BinaryVectorEncoding, BinaryVector> problem, IRandom rand) {
    3636      var options = Enumerable.Range(0, donors.Count).ToArray();
    3737      foreach (var cluster in tree.Clusters) {
     
    4848    }
    4949
    50     private static double Donate(BinaryVector solution, double fitness, BinaryVector source, IEnumerable<int> cluster, BinaryProblem problem, 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) {
    5151      // keep track of which bits flipped to make the donation
    5252      List<int> flipped = new List<int>();
  • branches/ProblemRefactoring/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/ParameterlessPopulationPyramid.cs

    r13173 r13339  
    3232using HeuristicLab.Parameters;
    3333using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    34 using HeuristicLab.Problems.Binary;
    3534using HeuristicLab.Random;
    3635
     
    4443  public class ParameterlessPopulationPyramid : BasicAlgorithm {
    4544    public override Type ProblemType {
    46       get { return typeof(BinaryProblem); }
    47     }
    48     public new BinaryProblem Problem {
    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; }
    5049      set { base.Problem = value; }
    5150    }
     
    183182      if (seen.Contains(solution)) return;
    184183      if (level == pyramid.Count) {
    185         pyramid.Add(new Population(tracker.Length, random));
     184        pyramid.Add(new Population(tracker.Encoding.Length, random));
    186185      }
    187186      var copied = (BinaryVector)solution.Clone();
     
    193192    private double iterate() {
    194193      // Create a random solution
    195       BinaryVector solution = new BinaryVector(tracker.Length);
     194      BinaryVector solution = new BinaryVector(tracker.Encoding.Length);
    196195      for (int i = 0; i < solution.Length; i++) {
    197196        solution[i] = random.Next(2) == 1;
     
    249248          fitness = iterate();
    250249          cancellationToken.ThrowIfCancellationRequested();
    251         } finally {
     250        }
     251        finally {
    252252          ResultsEvaluations = tracker.Evaluations;
    253253          ResultsBestSolution = new BinaryVector(tracker.BestSolution);
Note: See TracChangeset for help on using the changeset viewer.