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

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

File:
1 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}
Note: See TracChangeset for help on using the changeset viewer.