Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/23/15 15:15:27 (9 years ago)
Author:
mkommend
Message:

#2521: Refactored encodings and problems.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/ProblemRefactoring/HeuristicLab.Problems.Binary/3.3/BinaryProblem.cs

    r12000 r13336  
    3434namespace HeuristicLab.Problems.Binary {
    3535  [StorableClass]
    36   public abstract class BinaryProblem : SingleObjectiveBasicProblem<BinaryVectorEncoding> {
     36  public abstract class BinaryProblem : SingleObjectiveProblem<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; }
    4045    }
    4146
     
    6065      var lengthParameter = new FixedValueParameter<IntValue>("Length", "The length of the BinaryVector.", new IntValue(10));
    6166      Parameters.Add(lengthParameter);
     67      Encoding = new BinaryVectorEncoding();
    6268      Encoding.LengthParameter = lengthParameter;
    6369      RegisterEventHandlers();
    6470    }
    6571
    66     public virtual bool IsBetter(double quality, double bestQuality) {
    67       return (Maximization && quality > bestQuality || !Maximization && quality < bestQuality);
    68     }
    69 
    70     public abstract double Evaluate(BinaryVector vector, IRandom random);
    71     public sealed override double Evaluate(Individual individual, IRandom random) {
    72       return Evaluate(individual.BinaryVector(), random);
    73     }
    74 
    75     public override void Analyze(Individual[] individuals, double[] qualities, ResultCollection results, IRandom random) {
     72    public override void Analyze(BinaryVector[] individuals, double[] qualities, ResultCollection results, IRandom random) {
    7673      base.Analyze(individuals, qualities, results, random);
    7774      var orderedIndividuals = individuals.Zip(qualities, (i, q) => new { Individual = i, Quality = q }).OrderBy(z => z.Quality);
     
    8178        results.Add(new Result("Best Solution", typeof(BinaryVector)));
    8279      }
    83       results["Best Solution"].Value = (IItem)best.BinaryVector().Clone();
     80      results["Best Solution"].Value = (IItem)best.Clone();
    8481    }
    8582
Note: See TracChangeset for help on using the changeset viewer.