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.Algorithms.ParameterlessPopulationPyramid/3.3
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • 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);
Note: See TracChangeset for help on using the changeset viewer.