Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/24/15 16:01:02 (8 years ago)
Author:
mkommend
Message:

#2521: Adapted real vector encoding, test function problems, P3, CMA-ES and optimization.

Location:
branches/ProblemRefactoring/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/ProblemRefactoring/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/EvaluationTracker.cs

    r13339 r13361  
    2222
    2323using System;
    24 using HeuristicLab.Common;
     24using System.Collections.Generic;
    2525using HeuristicLab.Core;
    26 using HeuristicLab.Data;
    2726using HeuristicLab.Encodings.BinaryVectorEncoding;
    2827using HeuristicLab.Optimization;
    29 using HeuristicLab.Parameters;
    30 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    3128
    3229namespace HeuristicLab.Algorithms.ParameterlessPopulationPyramid {
     
    3431  // B. W. Goldman and W. F. Punch, "Parameter-less Population Pyramid," GECCO, pp. 785–792, 2014
    3532  // and the original source code in C++11 available from: https://github.com/brianwgoldman/Parameter-less_Population_Pyramid
    36   internal sealed class EvaluationTracker : SingleObjectiveProblem<BinaryVectorEncoding, BinaryVector> {
    37     private readonly ISingleObjectiveProblem<BinaryVectorEncoding, BinaryVector> problem;
     33  internal sealed class EvaluationTracker : ISingleObjectiveProblemDefinition<BinaryVectorEncoding, BinaryVector> {
     34    private readonly ISingleObjectiveProblemDefinition<BinaryVectorEncoding, BinaryVector> problem;
    3835
    3936    private int maxEvaluations;
     
    6057    }
    6158
    62     public new BinaryVectorEncoding Encoding {
     59    public BinaryVectorEncoding Encoding {
    6360      get { return problem.Encoding; }
    6461    }
    6562    #endregion
    6663
    67     [StorableConstructor]
    68     private EvaluationTracker(bool deserializing) : base(deserializing) { }
    69     private EvaluationTracker(EvaluationTracker original, Cloner cloner)
    70       : base(original, cloner) {
    71       problem = cloner.Clone(original.problem);
    72       maxEvaluations = original.maxEvaluations;
    73       BestQuality = original.BestQuality;
    74       Evaluations = original.Evaluations;
    75       BestFoundOnEvaluation = original.BestFoundOnEvaluation;
    76       BestSolution = cloner.Clone(BestSolution);
    77     }
    78     public override IDeepCloneable Clone(Cloner cloner) {
    79       return new EvaluationTracker(this, cloner);
    80     }
    81     public EvaluationTracker(ISingleObjectiveProblem<BinaryVectorEncoding, BinaryVector> problem, int maxEvaluations) {
     64    public EvaluationTracker(ISingleObjectiveProblemDefinition<BinaryVectorEncoding, BinaryVector> problem, int maxEvaluations) {
    8265      this.problem = problem;
    8366      this.maxEvaluations = maxEvaluations;
     
    8669      Evaluations = 0;
    8770      BestFoundOnEvaluation = 0;
    88 
    89       if (Parameters.ContainsKey("Maximization")) Parameters.Remove("Maximization");
    90       Parameters.Add(new FixedValueParameter<BoolValue>("Maximization", "Set to false if the problem should be minimized.", (BoolValue)new BoolValue(Maximization).AsReadOnly()) { Hidden = true });
    9171    }
    9272
    93     public override double Evaluate(BinaryVector vector, IRandom random) {
     73
     74
     75    public double Evaluate(BinaryVector vector, IRandom random) {
    9476      if (Evaluations >= maxEvaluations) throw new OperationCanceledException("Maximum Evaluation Limit Reached");
    9577      Evaluations++;
     
    10385    }
    10486
    105     public override bool Maximization {
     87    public bool Maximization {
    10688      get {
    10789        if (problem == null) return false;
     
    11092    }
    11193
    112     public override bool IsBetter(double quality, double bestQuality) {
     94    public bool IsBetter(double quality, double bestQuality) {
    11395      return problem.IsBetter(quality, bestQuality);
    11496    }
    11597
     98    public void Analyze(BinaryVector[] individuals, double[] qualities, ResultCollection results, IRandom random) {
     99      problem.Analyze(individuals, qualities, results, random);
     100    }
     101
     102    public IEnumerable<BinaryVector> GetNeighbors(BinaryVector individual, IRandom random) {
     103      return problem.GetNeighbors(individual, random);
     104    }
    116105  }
    117106}
  • branches/ProblemRefactoring/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/HillClimber.cs

    r13339 r13361  
    4949
    5050    public override Type ProblemType {
    51       get { return typeof(ISingleObjectiveProblem<BinaryVectorEncoding, BinaryVector>); }
     51      get { return typeof(ISingleObjectiveProblemDefinition<BinaryVectorEncoding, BinaryVector>); }
    5252    }
    53     public new ISingleObjectiveProblem<BinaryVectorEncoding, BinaryVector> Problem {
    54       get { return (ISingleObjectiveProblem<BinaryVectorEncoding, BinaryVector>)base.Problem; }
    55       set { base.Problem = value; }
     53    public new ISingleObjectiveProblemDefinition<BinaryVectorEncoding, BinaryVector> Problem {
     54      get { return (ISingleObjectiveProblemDefinition<BinaryVectorEncoding, BinaryVector>)base.Problem; }
     55      set { base.Problem = (IProblem)value; }
    5656    }
    5757
     
    9797    }
    9898    // In the GECCO paper, Section 2.1
    99     public static double ImproveToLocalOptimum(ISingleObjectiveProblem<BinaryVectorEncoding, BinaryVector> problem, BinaryVector solution, double fitness, IRandom rand) {
     99    public static double ImproveToLocalOptimum(ISingleObjectiveProblemDefinition<BinaryVectorEncoding, BinaryVector> problem, BinaryVector solution, double fitness, IRandom rand) {
    100100      var tried = new HashSet<int>();
    101101      do {
  • branches/ProblemRefactoring/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/LinkageCrossover.cs

    r13339 r13361  
    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, ISingleObjectiveProblem<BinaryVectorEncoding, BinaryVector> problem, IRandom rand) {
     35    public static double ImproveUsingTree(LinkageTree tree, IList<BinaryVector> donors, BinaryVector solution, double fitness, ISingleObjectiveProblemDefinition<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, ISingleObjectiveProblem<BinaryVectorEncoding, BinaryVector> problem, IRandom rand, out bool changed) {
     50    private static double Donate(BinaryVector solution, double fitness, BinaryVector source, IEnumerable<int> cluster, ISingleObjectiveProblemDefinition<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

    r13339 r13361  
    4545      get { return typeof(ISingleObjectiveProblem<BinaryVectorEncoding, BinaryVector>); }
    4646    }
    47     public new ISingleObjectiveProblem<BinaryVectorEncoding, BinaryVector> Problem {
    48       get { return (ISingleObjectiveProblem<BinaryVectorEncoding, BinaryVector>)base.Problem; }
    49       set { base.Problem = value; }
     47    public new ISingleObjectiveProblemDefinition<BinaryVectorEncoding, BinaryVector> Problem {
     48      get { return (ISingleObjectiveProblemDefinition<BinaryVectorEncoding, BinaryVector>)base.Problem; }
     49      set { base.Problem = (IProblem)value; }
    5050    }
    5151
     
    182182      if (seen.Contains(solution)) return;
    183183      if (level == pyramid.Count) {
    184         pyramid.Add(new Population(tracker.Encoding.Length, random));
     184        pyramid.Add(new Population(Problem.Encoding.Length, random));
    185185      }
    186186      var copied = (BinaryVector)solution.Clone();
     
    192192    private double iterate() {
    193193      // Create a random solution
    194       BinaryVector solution = new BinaryVector(tracker.Encoding.Length);
     194      BinaryVector solution = new BinaryVector(Problem.Encoding.Length);
    195195      for (int i = 0; i < solution.Length; i++) {
    196196        solution[i] = random.Next(2) == 1;
Note: See TracChangeset for help on using the changeset viewer.