Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/18/19 16:11:21 (5 years ago)
Author:
mkommend
Message:

#2521: Refactored single-objective problems to use EvaluationResult instead of double as return type from Evaluate.

Location:
branches/2521_ProblemRefactoring/HeuristicLab.Problems.GeneticProgramming/3.3/Boolean
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.GeneticProgramming/3.3/Boolean/EvenParityProblem.cs

    r17320 r17382  
    2929using HeuristicLab.Data;
    3030using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     31using HeuristicLab.Optimization;
    3132using HeuristicLab.Parameters;
    3233
     
    104105
    105106
    106     public override double Evaluate(ISymbolicExpressionTree tree, IRandom random, CancellationToken cancellationToken) {
     107    public override ISingleObjectiveEvaluationResult Evaluate(ISymbolicExpressionTree tree, IRandom random, CancellationToken cancellationToken) {
    107108      if (NumberOfBits <= 0) throw new NotSupportedException("Number of bits must be larger than zero.");
    108109      if (NumberOfBits > 10) throw new NotSupportedException("Even parity does not support problems with number of bits > 10.");
     
    110111      var targets = bs.Select(b => CalcTarget(b, NumberOfBits));
    111112      var pred = Interpret(tree, bs);
    112       return targets.Zip(pred, (t, p) => t == p ? 1 : 0).Sum(); // count number of correct predictions
     113      var quality = targets.Zip(pred, (t, p) => t == p ? 1 : 0).Sum(); // count number of correct predictions
     114
     115      return new SingleObjectiveEvaluationResult(quality);
    113116    }
    114117
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.GeneticProgramming/3.3/Boolean/MultiplexerProblem.cs

    r17320 r17382  
    3030using HeuristicLab.Data;
    3131using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     32using HeuristicLab.Optimization;
    3233using HeuristicLab.Parameters;
    3334
     
    118119
    119120
    120     public override double Evaluate(ISymbolicExpressionTree tree, IRandom random, CancellationToken cancellationToken) {
     121    public override ISingleObjectiveEvaluationResult Evaluate(ISymbolicExpressionTree tree, IRandom random, CancellationToken cancellationToken) {
    121122      if (NumberOfBits <= 0) throw new NotSupportedException("Number of bits must be larger than zero.");
    122123      if (NumberOfBits > 37) throw new NotSupportedException("Multiplexer does not support problems with number of bits > 37.");
     
    126127      var targets = bs.Select(b => CalcTarget(b, addrBits, inputBits));
    127128      var pred = Interpret(tree, bs, (byte)addrBits);
    128       return targets.Zip(pred, (t, p) => t == p ? 1 : 0).Sum(); // count number of correct predictions
     129      var quality = targets.Zip(pred, (t, p) => t == p ? 1 : 0).Sum(); // count number of correct predictions
     130
     131      return new SingleObjectiveEvaluationResult(quality);
    129132    }
    130133
Note: See TracChangeset for help on using the changeset viewer.