Free cookie consent management tool by TermsFeed Policy Generator

Changeset 17382


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
Files:
33 edited

Legend:

Unmodified
Added
Removed
  • branches/2521_ProblemRefactoring/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/GaussianProcessCovarianceOptimizationProblem.cs

    r17320 r17382  
    198198    private readonly object syncRoot = new object();
    199199    // Does not produce the same result for the same seed when using parallel engine (see below)!
    200     public override double Evaluate(ISymbolicExpressionTree tree, IRandom random, CancellationToken cancellationToken) {
     200    public override ISingleObjectiveEvaluationResult Evaluate(ISymbolicExpressionTree tree, IRandom random, CancellationToken cancellationToken) {
    201201      var meanFunction = new MeanConst();
    202202      var problemData = ProblemData;
     
    260260      UpdateBestSoFar(bestObjValue[0], bestHyperParameters, meanFunction, covarianceFunction);
    261261
    262       return bestObjValue[0];
     262      var quality = bestObjValue[0];
     263      return new SingleObjectiveEvaluationResult(quality);
    263264    }
    264265
  • branches/2521_ProblemRefactoring/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/EvaluationTracker.cs

    r17363 r17382  
    9595    }
    9696
    97     public double Evaluate(BinaryVector vector, IRandom random) {
     97    public ISingleObjectiveEvaluationResult Evaluate(BinaryVector vector, IRandom random) {
    9898      return Evaluate(vector, random, CancellationToken.None);
    9999    }
    100100
    101     public double Evaluate(BinaryVector vector, IRandom random, CancellationToken cancellationToken) {
     101    public ISingleObjectiveEvaluationResult Evaluate(BinaryVector vector, IRandom random, CancellationToken cancellationToken) {
    102102      if (Evaluations >= maxEvaluations) throw new OperationCanceledException("Maximum Evaluation Limit Reached");
    103103      Evaluations++;
    104       double fitness = problem.Evaluate(vector, random);
     104
     105      var evaluationResult = problem.Evaluate(vector, random);
     106      double fitness = evaluationResult.Quality;
    105107      if (double.IsNaN(BestQuality) || problem.IsBetter(fitness, BestQuality)) {
    106108        BestQuality = fitness;
     
    108110        BestFoundOnEvaluation = Evaluations;
    109111      }
    110       return fitness;
     112      return evaluationResult;
    111113    }
    112114
     
    115117    }
    116118    public void Evaluate(ISingleObjectiveSolutionContext<BinaryVector> solutionContext, IRandom random, CancellationToken cancellationToken) {
    117       double quality = Evaluate(solutionContext.EncodedSolution, random, cancellationToken);
    118       solutionContext.EvaluationResult = new SingleObjectiveEvaluationResult(quality);
     119      var evaluationResult = Evaluate(solutionContext.EncodedSolution, random, cancellationToken);
     120      solutionContext.EvaluationResult = evaluationResult;
    119121    }
    120122
  • branches/2521_ProblemRefactoring/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/HillClimber.cs

    r17226 r17382  
    2525using System.Linq;
    2626using System.Threading;
     27using HEAL.Attic;
    2728using HeuristicLab.Common;
    2829using HeuristicLab.Core;
     
    3132using HeuristicLab.Optimization;
    3233using HeuristicLab.Parameters;
    33 using HEAL.Attic;
    3434using HeuristicLab.Random;
    3535
     
    110110        }
    111111
    112         var fitness = Problem.Evaluate(solution, random);
     112        var evaluationResult = Problem.Evaluate(solution, random);
     113        var fitness = evaluationResult.Quality;
    113114
    114115        fitness = ImproveToLocalOptimum(Problem, solution, fitness, random);
     
    128129          if (tried.Contains(option)) continue;
    129130          solution[option] = !solution[option];
    130           double newFitness = problem.Evaluate(solution, rand);
     131          var newEvaluationResult = problem.Evaluate(solution, rand);
     132          double newFitness = newEvaluationResult.Quality;
    131133          if (problem.IsBetter(newFitness, fitness)) {
    132134            fitness = newFitness;
  • branches/2521_ProblemRefactoring/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/LinkageCrossover.cs

    r17226 r17382  
    5959      changed = flipped.Count > 0;
    6060      if (changed) {
    61         double newFitness = problem.Evaluate(solution, rand);
     61        double newFitness = problem.Evaluate(solution, rand).Quality;
    6262        // if the original is strictly better, revert the change
    6363        if (problem.IsBetter(fitness, newFitness)) {
  • branches/2521_ProblemRefactoring/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/ParameterlessPopulationPyramid.cs

    r17226 r17382  
    214214        solution[i] = random.Next(2) == 1;
    215215      }
    216       double fitness = tracker.Evaluate(solution, random);
     216      double fitness = tracker.Evaluate(solution, random).Quality;
    217217      fitness = HillClimber.ImproveToLocalOptimum(tracker, solution, fitness, random);
    218218      AddIfUnique(solution, 0);
     
    271271          ResultsIterations++;
    272272          cancellationToken.ThrowIfCancellationRequested();
    273         }
    274         finally {
     273        } finally {
    275274          ResultsEvaluations = tracker.Evaluations;
    276275          ResultsBestSolution = new BinaryVector(tracker.BestSolution);
  • branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Interfaces/IEvaluationResult.cs

    r17357 r17382  
    2626  [StorableType("406EB24F-A59C-440C-8B83-49FC05F48855")]
    2727  public interface IEvaluationResult : IItem {
     28
     29    //TODO: make methods generic for get/set additional data
    2830    void SetAdditionalData(string identifier, object o);
    2931    object GetAdditionalData(string identifier);
  • branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Interfaces/ISingleObjectiveProblemDefinition.cs

    r17363 r17382  
    3737    where TEncodedSolution : class, IEncodedSolution {
    3838
    39     double Evaluate(TEncodedSolution solution, IRandom random);
    40     double Evaluate(TEncodedSolution solution, IRandom random, CancellationToken cancellationToken);
     39    ISingleObjectiveEvaluationResult Evaluate(TEncodedSolution solution, IRandom random);
     40    ISingleObjectiveEvaluationResult Evaluate(TEncodedSolution solution, IRandom random, CancellationToken cancellationToken);
     41
    4142    void Evaluate(ISingleObjectiveSolutionContext<TEncodedSolution> solutionContext, IRandom random);
    4243    void Evaluate(ISingleObjectiveSolutionContext<TEncodedSolution> solutionContext, IRandom random, CancellationToken cancellationToken);
  • branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Interfaces/ISolutionContext.cs

    r17363 r17382  
    3333    IEvaluationResult EvaluationResult { get; }
    3434
     35
     36    //TODO: make methods generic for get/set additional data
    3537    void SetAdditionalData(string identifier, object o);
    3638    object GetAdditionalData(string identifier);
  • branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/SingleObjectiveProblem.cs

    r17366 r17382  
    113113    }
    114114
    115     public double Evaluate(TEncodedSolution solution, IRandom random) {
     115    public ISingleObjectiveEvaluationResult Evaluate(TEncodedSolution solution, IRandom random) {
    116116      return Evaluate(solution, random, CancellationToken.None);
    117117    }
    118     public abstract double Evaluate(TEncodedSolution solution, IRandom random, CancellationToken cancellationToken);
     118    public abstract ISingleObjectiveEvaluationResult Evaluate(TEncodedSolution solution, IRandom random, CancellationToken cancellationToken);
    119119
    120120    public void Evaluate(ISingleObjectiveSolutionContext<TEncodedSolution> solutionContext, IRandom random) {
     
    122122    }
    123123    public virtual void Evaluate(ISingleObjectiveSolutionContext<TEncodedSolution> solutionContext, IRandom random, CancellationToken cancellationToken) {
    124       double quality = Evaluate(solutionContext.EncodedSolution, random, cancellationToken);
    125       solutionContext.EvaluationResult = new SingleObjectiveEvaluationResult(quality);
     124      var evaluationResult = Evaluate(solutionContext.EncodedSolution, random, cancellationToken);
     125      solutionContext.EvaluationResult = evaluationResult;
    126126    }
    127127
     
    139139      return GetNeighbors(solutionContext.EncodedSolution, random).Select(n => new SingleObjectiveSolutionContext<TEncodedSolution>(n));
    140140    }
    141 
    142 
    143141
    144142    public static bool IsBetter(bool maximization, double quality, double bestQuality) {
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.Binary/3.3/DeceptiveTrapProblem.cs

    r17320 r17382  
    2929using HeuristicLab.Data;
    3030using HeuristicLab.Encodings.BinaryVectorEncoding;
     31using HeuristicLab.Optimization;
    3132using HeuristicLab.Parameters;
    3233
     
    8182    }
    8283
    83     public override double Evaluate(BinaryVector individual, IRandom random, CancellationToken cancellationToken) {
     84    public override ISingleObjectiveEvaluationResult Evaluate(BinaryVector individual, IRandom random, CancellationToken cancellationToken) {
    8485      if (individual.Length != Length) throw new ArgumentException("The individual has not the correct length.");
    8586      int total = 0;
     
    8889        total += Score(individual, i, trapSize);
    8990      }
    90       return (double)(total * trapSize) / (TrapMaximum * individual.Length);
     91      var quality =  (double)(total * trapSize) / (TrapMaximum * individual.Length);
     92      return new SingleObjectiveEvaluationResult(quality);
    9193    }
    9294  }
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.Binary/3.3/HIFFProblem.cs

    r17320 r17382  
    2828using HeuristicLab.Core;
    2929using HeuristicLab.Encodings.BinaryVectorEncoding;
     30using HeuristicLab.Optimization;
    3031
    3132namespace HeuristicLab.Problems.Binary {
     
    4849    }
    4950    // In the GECCO paper, Section 4.1
    50     public override double Evaluate(BinaryVector individual, IRandom random, CancellationToken cancellationToken) {
     51    public override ISingleObjectiveEvaluationResult Evaluate(BinaryVector individual, IRandom random, CancellationToken cancellationToken) {
    5152      int[] level = new int[individual.Length];
    5253      int levelLength = individual.Length;
     
    8384
    8485      // Convert to percentage of total
    85       return (double)total / maximum;
     86      var quality = (double)total / maximum;
     87      return new SingleObjectiveEvaluationResult(quality);
    8688    }
    8789  }
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.Binary/3.3/OneMaxProblem.cs

    r17320 r17382  
    2727using HeuristicLab.Core;
    2828using HeuristicLab.Encodings.BinaryVectorEncoding;
     29using HeuristicLab.Optimization;
    2930
    3031namespace HeuristicLab.Problems.Binary {
     
    4849    }
    4950
    50     public override double Evaluate(BinaryVector vector, IRandom random, CancellationToken cancellationToken) {
    51       return vector.Count(b => b);
     51    public override ISingleObjectiveEvaluationResult Evaluate(BinaryVector vector, IRandom random, CancellationToken cancellationToken) {
     52      var quality = vector.Count(b => b);
     53      return new SingleObjectiveEvaluationResult(quality);
    5254    }
    5355
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.ExternalEvaluation/3.4/SingleObjectiveExternalEvaluationProblem.cs

    r17363 r17382  
    105105
    106106    #region Single Objective Problem Overrides
    107     public override double Evaluate(TEncodedSolution solution, IRandom random, CancellationToken cancellationToken) {
     107    public override ISingleObjectiveEvaluationResult Evaluate(TEncodedSolution solution, IRandom random, CancellationToken cancellationToken) {
    108108      var qualityMessage = Evaluate(BuildSolutionMessage(solution), cancellationToken);
    109109      if (!qualityMessage.HasExtension(SingleObjectiveQualityMessage.QualityMessage_))
    110110        throw new InvalidOperationException("The received message is not a SingleObjectiveQualityMessage.");
    111       return qualityMessage.GetExtension(SingleObjectiveQualityMessage.QualityMessage_).Quality;
     111      var quality = qualityMessage.GetExtension(SingleObjectiveQualityMessage.QualityMessage_).Quality;
     112      return new SingleObjectiveEvaluationResult(quality);
     113
    112114    }
    113115    public virtual QualityMessage Evaluate(SolutionMessage solutionMessage, CancellationToken cancellationToken) {
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.GeneticProgramming/3.3/ArtificialAnt/Problem.cs

    r17320 r17382  
    135135
    136136
    137     public override double Evaluate(ISymbolicExpressionTree tree, IRandom random, CancellationToken cancellationToken) {
     137    public override ISingleObjectiveEvaluationResult Evaluate(ISymbolicExpressionTree tree, IRandom random, CancellationToken cancellationToken) {
    138138      var interpreter = new Interpreter(tree, World, MaxTimeSteps);
    139139      interpreter.Run();
    140       return interpreter.FoodEaten;
     140      var quality = interpreter.FoodEaten;
     141      return new SingleObjectiveEvaluationResult(quality);
    141142    }
    142143
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.GeneticProgramming/3.3/BasicSymbolicRegression/Problem.cs

    r17320 r17382  
    2828using HeuristicLab.Core;
    2929using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     30using HeuristicLab.Optimization;
    3031using HeuristicLab.Parameters;
    3132using HeuristicLab.Problems.DataAnalysis;
     
    9091
    9192
    92     public override double Evaluate(ISymbolicExpressionTree tree, IRandom random, CancellationToken cancellationToken) {
     93    public override ISingleObjectiveEvaluationResult Evaluate(ISymbolicExpressionTree tree, IRandom random, CancellationToken cancellationToken) {
    9394      // Doesn't use classes from HeuristicLab.Problems.DataAnalysis.Symbolic to make sure that the implementation can be fully understood easily.
    9495      // HeuristicLab.Problems.DataAnalysis.Symbolic would already provide all the necessary functionality (esp. interpreter) but at a much higher complexity.
     
    103104      var r = OnlinePearsonsRCalculator.Calculate(target, predicted, out errorState);
    104105      if (errorState != OnlineCalculatorError.None) r = 0;
    105       return r * r;
     106      var quality = r * r;
     107
     108      return new SingleObjectiveEvaluationResult(quality);
    106109    }
    107110
  • 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
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.GeneticProgramming/3.3/LawnMower/Problem.cs

    r17320 r17382  
    9393    }
    9494
    95     public override double Evaluate(ISymbolicExpressionTree tree, IRandom random, CancellationToken cancellationToken) {
     95    public override ISingleObjectiveEvaluationResult Evaluate(ISymbolicExpressionTree tree, IRandom random, CancellationToken cancellationToken) {
    9696      var length = LawnLengthParameter.Value.Value;
    9797      var width = LawnWidthParameter.Value.Value;
     
    105105            numberOfMowedCells++;
    106106          }
    107       return numberOfMowedCells;
     107      var quality = numberOfMowedCells;
     108      return new SingleObjectiveEvaluationResult(quality);
    108109    }
    109110  }
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.GeneticProgramming/3.3/robocode/Problem.cs

    r17320 r17382  
    9999    private void AfterDeserialization() { RegisterEventHandlers(); }
    100100
    101     public override double Evaluate(ISymbolicExpressionTree tree, IRandom random, CancellationToken cancellationToken) {
    102       return Interpreter.EvaluateTankProgram(tree, RobocodePath, Enemies, null, false, NrOfRounds);
     101    public override ISingleObjectiveEvaluationResult Evaluate(ISymbolicExpressionTree tree, IRandom random, CancellationToken cancellationToken) {
     102      var quality = Interpreter.EvaluateTankProgram(tree, RobocodePath, Enemies, null, false, NrOfRounds);
     103      return new SingleObjectiveEvaluationResult(quality);
    103104    }
    104105
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.GrammaticalEvolution/3.4/ArtificialAnt/GEArtificialAntProblem.cs

    r17320 r17382  
    9696
    9797    private readonly object syncRoot = new object();
    98     public override double Evaluate(IntegerVector solution, IRandom random, CancellationToken cancellationToken) {
     98    public override ISingleObjectiveEvaluationResult Evaluate(IntegerVector solution, IRandom random, CancellationToken cancellationToken) {
    9999      var bounds = Encoding.Bounds;
    100100      var len = Encoding.Length;
     
    113113      interpreter.Run();
    114114
    115       return interpreter.FoodEaten;
     115      var quality = interpreter.FoodEaten;
     116      return new SingleObjectiveEvaluationResult(quality);
    116117    }
    117118
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.GraphColoring/3.3/GraphColoringProblem.cs

    r17320 r17382  
    129129    }
    130130
    131     public override double Evaluate(LinearLinkage lle, IRandom random, CancellationToken cancellationToken) {
     131    public override ISingleObjectiveEvaluationResult Evaluate(LinearLinkage lle, IRandom random, CancellationToken cancellationToken) {
    132132      var adjList = adjacencyListParameter.Value;
    133133      var llee = lle.ToEndLinks(); // LLE-e encoding uses the highest indexed member as group number
     134
     135      double quality = double.NaN;
    134136
    135137      switch (FitnessFunction) {
     
    142144            var mag = Math.Pow(10, -(int)Math.Ceiling(Math.Log10(llee.Length)));
    143145            // the value is e.g. 4.03 for 4 conflicts with 3 colors (and less than 100 nodes)
    144             return conflicts + colors * mag;
     146            quality = conflicts + colors * mag;
     147            break;
    145148          }
    146149        case FitnessFunction.Penalized: {
     
    157160              if (color1 == color2) colors[color1].ConflictCount++;
    158161            }
    159             return 2 * colors.Sum(x => x.Value.ColorCount * x.Value.ConflictCount) - colors.Sum(x => x.Value.ColorCount * x.Value.ColorCount);
     162            quality = 2 * colors.Sum(x => x.Value.ColorCount * x.Value.ConflictCount) - colors.Sum(x => x.Value.ColorCount * x.Value.ColorCount);
     163            break;
    160164          }
    161165        default: throw new InvalidOperationException(string.Format("Unknown fitness function {0}.", FitnessFunction));
    162166      }
     167
     168      return new SingleObjectiveEvaluationResult(quality);
    163169    }
    164170
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.Knapsack/3.3/KnapsackProblem.cs

    r17356 r17382  
    9797    }
    9898
    99     public override double Evaluate(BinaryVector solution, IRandom random, CancellationToken cancellationToken) {
     99    public override ISingleObjectiveEvaluationResult Evaluate(BinaryVector solution, IRandom random, CancellationToken cancellationToken) {
    100100      var totalWeight = 0.0;
    101101      var totalValue = 0.0;
     
    105105        totalValue += Values[i];
    106106      }
    107       return totalWeight > KnapsackCapacity ? KnapsackCapacity - totalWeight : totalValue;
     107      var quality = totalWeight > KnapsackCapacity ? KnapsackCapacity - totalWeight : totalValue;
     108      return new SingleObjectiveEvaluationResult(quality);
    108109    }
    109110
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.NK/3.3/NKLandscape.cs

    r17320 r17382  
    2929using HeuristicLab.Data;
    3030using HeuristicLab.Encodings.BinaryVectorEncoding;
     31using HeuristicLab.Optimization;
    3132using HeuristicLab.Parameters;
    3233using HeuristicLab.PluginInfrastructure;
     
    335336    }
    336337
    337     public override double Evaluate(BinaryVector vector, IRandom random, CancellationToken cancellationToken) {
     338    public override ISingleObjectiveEvaluationResult Evaluate(BinaryVector vector, IRandom random, CancellationToken cancellationToken) {
    338339      double[] f_i; //useful for debugging
    339340      double quality = Evaluate(vector, GeneInteractions, Weights, InteractionSeed.Value, out f_i, Q, P);
    340       return quality;
     341      return new SingleObjectiveEvaluationResult(quality);
    341342    }
    342343    #endregion
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.PTSP/3.3/AnalyticalPTSP.cs

    r17335 r17382  
    2525using HeuristicLab.Core;
    2626using HeuristicLab.Encodings.PermutationEncoding;
     27using HeuristicLab.Optimization;
    2728
    2829namespace HeuristicLab.Problems.PTSP {
     
    6061    }
    6162
    62     public override double Evaluate(Permutation tour, IRandom random, CancellationToken cancellationToken) {
    63       return Evaluate(tour, ProbabilisticTSPData, cancellationToken);
     63    public override ISingleObjectiveEvaluationResult Evaluate(Permutation tour, IRandom random, CancellationToken cancellationToken) {
     64      var quality = Evaluate(tour, ProbabilisticTSPData, cancellationToken);
     65      return new SingleObjectiveEvaluationResult(quality);
    6466    }
    6567
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.PTSP/3.3/EstimatedPTSP.cs

    r17335 r17382  
    2929using HeuristicLab.Data;
    3030using HeuristicLab.Encodings.PermutationEncoding;
     31using HeuristicLab.Optimization;
    3132using HeuristicLab.Parameters;
    3233using HeuristicLab.Problems.Instances;
     
    5657      set { RealizationsParameter.Value.Value = value; }
    5758    }
    58    
     59
    5960    private ReadOnlyItemList<BoolArray> RealizationData {
    6061      get { return RealizationDataParameter.Value; }
     
    102103    }
    103104
    104     public override double Evaluate(Permutation tour, IRandom random, CancellationToken cancellationToken) {
    105       return Evaluate(tour, ProbabilisticTSPData, RealizationData, cancellationToken);
     105    public override ISingleObjectiveEvaluationResult Evaluate(Permutation tour, IRandom random, CancellationToken cancellationToken) {
     106      var quality = Evaluate(tour, ProbabilisticTSPData, RealizationData, cancellationToken);
     107      return new SingleObjectiveEvaluationResult(quality);
    106108    }
    107109
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.PTSP/3.3/ProbabilisticTSP.cs

    r17363 r17382  
    124124        try {
    125125          var tour = new Permutation(PermutationTypes.RelativeUndirected, data.BestKnownTour);
    126           var tourLength = Evaluate(tour, new MersenneTwister(1));
     126          var tourLength = Evaluate(tour, new MersenneTwister(1)).Quality;
    127127          BestKnownSolution = ProbabilisticTSPData.GetSolution(tour, tourLength);
    128128          BestKnownQuality = tourLength;
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.Programmable/3.3/CompiledProblemDefinition.cs

    r17381 r17382  
    6161    public abstract bool Maximization { get; }
    6262
    63     public virtual double Evaluate(TEncodedSolution solution, IRandom random) {
     63    public virtual ISingleObjectiveEvaluationResult Evaluate(TEncodedSolution solution, IRandom random) {
    6464      return Evaluate(solution, random, CancellationToken.None);
    6565    }
    66     public abstract double Evaluate(TEncodedSolution solution, IRandom random, CancellationToken cancellationToken);
     66    public abstract ISingleObjectiveEvaluationResult Evaluate(TEncodedSolution solution, IRandom random, CancellationToken cancellationToken);
    6767
    6868    public virtual void Evaluate(ISingleObjectiveSolutionContext<TEncodedSolution> solutionContext, IRandom random) {
     
    7070    }
    7171    public virtual void Evaluate(ISingleObjectiveSolutionContext<TEncodedSolution> solutionContext, IRandom random, CancellationToken cancellationToken) {
    72       double quality = Evaluate(solutionContext.EncodedSolution, random, cancellationToken);
    73       solutionContext.EvaluationResult = new SingleObjectiveEvaluationResult(quality);
     72      var evaluationResult = Evaluate(solutionContext.EncodedSolution, random, cancellationToken);
     73      solutionContext.EvaluationResult = evaluationResult;
    7474    }
    7575
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.Programmable/3.3/SingleObjectiveProblemDefinitionScript.cs

    r17366 r17382  
    5151    public bool Maximization => CompiledProblemDefinition.Maximization;
    5252
    53     double ISingleObjectiveProblemDefinition<TEncoding, TEncodedSolution>.Evaluate(TEncodedSolution solution, IRandom random) {
     53    ISingleObjectiveEvaluationResult ISingleObjectiveProblemDefinition<TEncoding, TEncodedSolution>.Evaluate(TEncodedSolution solution, IRandom random) {
    5454      return CompiledProblemDefinition.Evaluate(solution, random);
    5555    }
    5656
    57     double ISingleObjectiveProblemDefinition<TEncoding, TEncodedSolution>.Evaluate(TEncodedSolution solution, IRandom random, CancellationToken cancellationToken) {
     57    ISingleObjectiveEvaluationResult ISingleObjectiveProblemDefinition<TEncoding, TEncodedSolution>.Evaluate(TEncodedSolution solution, IRandom random, CancellationToken cancellationToken) {
    5858      return CompiledProblemDefinition.Evaluate(solution, random, cancellationToken);
    5959    }
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.Programmable/3.3/SingleObjectiveProgrammableProblem.cs

    r17363 r17382  
    111111      ProblemDefinition.Evaluate(solutionContext, random, cancellationToken);
    112112    }
    113     public override double Evaluate(TEncodedSolution individual, IRandom random, CancellationToken cancellationToken) {
     113    public override ISingleObjectiveEvaluationResult Evaluate(TEncodedSolution individual, IRandom random, CancellationToken cancellationToken) {
    114114      return ProblemDefinition.Evaluate(individual, random, cancellationToken);
    115115    }
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.Programmable/3.3/Templates/SingleObjectiveProblem_Template.cs

    r17381 r17382  
    2323    //TODO add other methods
    2424
    25     public override void Evaluate(ISingleObjectiveSolutionContext<SOLUTION_CLASS> solutionContext, IRandom random, CancellationToken cancellationToken) {
    26       var quality = Evaluate(solutionContext.EncodedSolution, random, cancellationToken);
     25    public override ISingleObjectiveEvaluationResult Evaluate(SOLUTION_CLASS solution, IRandom random, CancellationToken cancellationToken) {
     26      // Use vars.yourVariable to access variables in the variable store i.e. yourVariable
     27      var quality = 0.0;
    2728      var evaluationResult = new SingleObjectiveEvaluationResult(quality);
    28       solutionContext.EvaluationResult = evaluationResult;
     29      return evaluationResult;
    2930    }
    3031
    31     public override double Evaluate(SOLUTION_CLASS solution, IRandom random, CancellationToken cancellationToken) {
    32       // Use vars.yourVariable to access variables in the variable store i.e. yourVariable
    33       var quality = 0.0;
    34       return quality;
    35     }
    36 
    37     public override void Analyze(ISingleObjectiveSolutionContext<TEncodedSolution>[] solutionContexts, ResultCollection results, IRandom random) {
     32    public override void Analyze(ISingleObjectiveSolutionContext<SOLUTION_CLASS>[] solutionContexts, ResultCollection results, IRandom random) {
    3833      var solutions = solutionContexts.Select(c => c.EncodedSolution).ToArray();
    3934      var qualities = solutionContexts.Select(c => c.EvaluationResult.Quality).ToArray();
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.QuadraticAssignment/3.3/QuadraticAssignmentProblem.cs

    r17320 r17382  
    136136    }
    137137
    138     public override double Evaluate(Permutation assignment, IRandom random, CancellationToken cancellationToken) {
    139       return Evaluate(assignment, cancellationToken);
     138    public override ISingleObjectiveEvaluationResult Evaluate(Permutation assignment, IRandom random, CancellationToken cancellationToken) {
     139      var quality = Evaluate(assignment, cancellationToken);
     140      return new SingleObjectiveEvaluationResult(quality);
    140141    }
    141142
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.TestFunctions/3.3/SingleObjectiveTestFunctionProblem.cs

    r17320 r17382  
    109109    }
    110110
    111     public override double Evaluate(RealVector individual, IRandom random, CancellationToken cancellationToken) {
    112       return TestFunction.Evaluate(individual);
     111    public override ISingleObjectiveEvaluationResult Evaluate(RealVector individual, IRandom random, CancellationToken cancellationToken) {
     112      var quality = TestFunction.Evaluate(individual);
     113      return new SingleObjectiveEvaluationResult(quality);
    113114    }
    114115
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.TravelingSalesman/3.3/TSP.cs

    r17335 r17382  
    8383    }
    8484
    85     public override double Evaluate(Permutation tour, IRandom random, CancellationToken cancellationToken) {
    86       return Evaluate(tour);
     85    public override ISingleObjectiveEvaluationResult Evaluate(Permutation tour, IRandom random, CancellationToken cancellationToken) {
     86      var quality = Evaluate(tour);
     87      return new SingleObjectiveEvaluationResult(quality);
    8788    }
    8889
Note: See TracChangeset for help on using the changeset viewer.