Free cookie consent management tool by TermsFeed Policy Generator

Changeset 13339 for branches


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

#2521: Rectored problems and encodings.

Location:
branches/ProblemRefactoring
Files:
15 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);
  • branches/ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Interfaces/IMultiObjectiveProblemDefinition.cs

    r13336 r13339  
    2323
    2424namespace HeuristicLab.Optimization {
    25   public interface IMultiObjectiveProblemDefinition<TSolution> : IProblemDefinition
    26   where TSolution : class, ISolution {
     25  public interface IMultiObjectiveProblemDefinition<TEncoding, TSolution> : IProblemDefinition<TEncoding, TSolution>
     26    where TEncoding : class, IEncoding<TSolution>
     27    where TSolution : class, ISolution {
    2728    bool[] Maximization { get; }
    2829    double[] Evaluate(TSolution individual, IRandom random);
  • branches/ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Interfaces/IProblemDefinition.cs

    r13336 r13339  
    2121
    2222namespace HeuristicLab.Optimization {
    23   public interface IProblemDefinition {
    24     //IEncoding Encoding { get; }
     23  public interface IProblemDefinition<TEncoding, TSolution>
     24    where TEncoding : class, IEncoding<TSolution>
     25    where TSolution : class, ISolution {
     26    TEncoding Encoding { get; }
    2527  }
    2628}
  • branches/ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Interfaces/ISingleObjectiveProblem.cs

    r13337 r13339  
    2424
    2525namespace HeuristicLab.Optimization {
    26   public interface ISingleObjectiveProblem<TSolution> : IProblem<TSolution>, ISingleObjectiveProblemDefinition<TSolution>, ISingleObjectiveHeuristicOptimizationProblem
     26  public interface ISingleObjectiveProblem<TEncoding, TSolution> : IProblem<TEncoding, TSolution>, ISingleObjectiveProblemDefinition<TEncoding, TSolution>, ISingleObjectiveHeuristicOptimizationProblem
     27    where TEncoding : class, IEncoding<TSolution>
    2728    where TSolution : class, ISolution {
    2829    bool IsBetter(double quality, double bestQuality);
  • branches/ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Interfaces/ISingleObjectiveProblemDefinition.cs

    r13336 r13339  
    2424
    2525namespace HeuristicLab.Optimization {
    26   public interface ISingleObjectiveProblemDefinition<TSolution> : IProblemDefinition
    27   where TSolution : class, ISolution {
     26  public interface ISingleObjectiveProblemDefinition<TEncoding, TSolution> : IProblemDefinition<TEncoding, TSolution>
     27    where TEncoding : class, IEncoding<TSolution>
     28    where TSolution : class, ISolution {
    2829    bool Maximization { get; }
    2930    double Evaluate(TSolution individual, IRandom random);
  • branches/ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/MultiObjectiveProblem.cs

    r13336 r13339  
    2929namespace HeuristicLab.Optimization {
    3030  [StorableClass]
    31   public abstract class MultiObjectiveProblem<TSolution> : Problem<TSolution, MultiObjectiveEvaluator<TSolution>>, IMultiObjectiveHeuristicOptimizationProblem, IMultiObjectiveProblemDefinition<TSolution>
    32   where TSolution : class, ISolution {
     31  public abstract class MultiObjectiveProblem<TEncoding, TSolution> : Problem<TEncoding, TSolution, MultiObjectiveEvaluator<TSolution>>, IMultiObjectiveHeuristicOptimizationProblem, IMultiObjectiveProblemDefinition<TEncoding, TSolution>
     32    where TEncoding : class, IEncoding<TSolution>
     33    where TSolution : class, ISolution {
    3334    [StorableConstructor]
    3435    protected MultiObjectiveProblem(bool deserializing) : base(deserializing) { }
    3536
    36     protected MultiObjectiveProblem(MultiObjectiveProblem<TSolution> original, Cloner cloner)
     37    protected MultiObjectiveProblem(MultiObjectiveProblem<TEncoding, TSolution> original, Cloner cloner)
    3738      : base(original, cloner) {
    3839      ParameterizeOperators();
  • branches/ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Problem.cs

    r13336 r13339  
    3030namespace HeuristicLab.Optimization {
    3131  [StorableClass]
    32   public abstract class Problem<TSolution, TEvaluator> : HeuristicOptimizationProblem<TEvaluator, ISolutionCreator<TSolution>>, IProblemDefinition, IStorableContent
     32  public abstract class Problem<TEncoding, TSolution, TEvaluator> : HeuristicOptimizationProblem<TEvaluator, ISolutionCreator<TSolution>>, IProblemDefinition<TEncoding, TSolution>, IStorableContent
     33    where TEncoding : class, IEncoding<TSolution>
    3334    where TSolution : class, ISolution
    3435    where TEvaluator : class, IEvaluator {
     
    3637    public string Filename { get; set; }
    3738
    38     protected IValueParameter<IEncoding<TSolution>> EncodingParameter {
    39       get { return (IValueParameter<IEncoding<TSolution>>)Parameters["Encoding"]; }
     39    protected IValueParameter<TEncoding> EncodingParameter {
     40      get { return (IValueParameter<TEncoding>)Parameters["Encoding"]; }
    4041    }
    4142
    42     public IEncoding<TSolution> Encoding {
     43    public TEncoding Encoding {
    4344      get { return EncodingParameter.Value; }
    4445      protected set {
     
    6162    protected Problem()
    6263      : base() {
    63       Parameters.Add(new ValueParameter<IEncoding<TSolution>>("Encoding", "Describes the configuration of the encoding, what the variables are called, what type they are and their bounds if any."));
    64       if (Encoding != null) Parameterize();
     64      Parameters.Add(new ValueParameter<TEncoding>("Encoding", "Describes the configuration of the encoding, what the variables are called, what type they are and their bounds if any."));
     65      if (Encoding != null) {
     66        SolutionCreator = Encoding.SolutionCreator;
     67        Parameterize();
     68      }
    6569      RegisterEvents();
    6670    }
    6771
    68     protected Problem(Problem<TSolution, TEvaluator> original, Cloner cloner)
     72    protected Problem(Problem<TEncoding, TSolution, TEvaluator> original, Cloner cloner)
    6973      : base(original, cloner) {
    7074      RegisterEvents();
  • branches/ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/SingleObjectiveProblem.cs

    r13336 r13339  
    3030namespace HeuristicLab.Optimization {
    3131  [StorableClass]
    32   public abstract class SingleObjectiveProblem<TSolution> : Problem<TSolution, SingleObjectiveEvaluator<TSolution>>,
    33     ISingleObjectiveProblemDefinition<TSolution>, ISingleObjectiveHeuristicOptimizationProblem
    34   where TSolution : class, ISolution {
     32  public abstract class SingleObjectiveProblem<TEncoding, TSolution> : Problem<TEncoding, TSolution, SingleObjectiveEvaluator<TSolution>>, ISingleObjectiveProblem<TEncoding, TSolution>
     33    where TEncoding : class, IEncoding<TSolution>
     34    where TSolution : class, ISolution {
    3535
    3636    protected IValueParameter<DoubleValue> BestKnownQualityParameter {
     
    5252    protected SingleObjectiveProblem(bool deserializing) : base(deserializing) { }
    5353
    54     protected SingleObjectiveProblem(SingleObjectiveProblem<TSolution> original, Cloner cloner)
     54    protected SingleObjectiveProblem(SingleObjectiveProblem<TEncoding, TSolution> original, Cloner cloner)
    5555      : base(original, cloner) {
    5656      ParameterizeOperators();
  • branches/ProblemRefactoring/HeuristicLab.Optimization/3.3/Interfaces/IProblem.cs

    r13336 r13339  
    3636  }
    3737
    38   public interface IProblem<TSolution> : IHeuristicOptimizationProblem where TSolution : class, ISolution {
    39     IEncoding<TSolution> Encoding { get; }
     38  public interface IProblem<TEncoding, TSolution> : IHeuristicOptimizationProblem, IProblemDefinition<TEncoding, TSolution>
     39    where TEncoding : class, IEncoding<TSolution>
     40    where TSolution : class, ISolution {
    4041  }
    4142}
  • branches/ProblemRefactoring/HeuristicLab.Optimization/3.3/Problems/HeuristicOptimizationProblem.cs

    r12012 r13339  
    9999    }
    100100
    101     protected virtual void SolutionCreatorParameter_ValueChanged(object sender, EventArgs e) {
     101    private void SolutionCreatorParameter_ValueChanged(object sender, EventArgs e) {
    102102      OnSolutionCreatorChanged();
    103103    }
  • branches/ProblemRefactoring/HeuristicLab.Problems.Binary/3.3/BinaryProblem.cs

    r13336 r13339  
    3434namespace HeuristicLab.Problems.Binary {
    3535  [StorableClass]
    36   public abstract class BinaryProblem : SingleObjectiveProblem<BinaryVector> {
     36  public abstract class BinaryProblem : SingleObjectiveProblem<BinaryVectorEncoding, BinaryVector> {
    3737    public virtual int Length {
    3838      get { return Encoding.Length; }
    3939      set { Encoding.Length = value; }
    40     }
    41 
    42     public new BinaryVectorEncoding Encoding {
    43       get { return (BinaryVectorEncoding)base.Encoding; }
    44       set { base.Encoding = value; }
    4540    }
    4641
     
    6560      var lengthParameter = new FixedValueParameter<IntValue>("Length", "The length of the BinaryVector.", new IntValue(10));
    6661      Parameters.Add(lengthParameter);
    67       Encoding = new BinaryVectorEncoding();
    6862      Encoding.LengthParameter = lengthParameter;
    6963      RegisterEventHandlers();
Note: See TracChangeset for help on using the changeset viewer.