Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/21/19 17:58:32 (5 years ago)
Author:
mkommend
Message:

#2521: First version of contexts in problem evaluation.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2521_ProblemRefactoring/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/EvaluationTracker.cs

    r17320 r17363  
    2323using System;
    2424using System.Collections.Generic;
     25using System.Linq;
    2526using System.Threading;
    2627using HEAL.Attic;
     
    110111    }
    111112
     113    public void Evaluate(ISingleObjectiveSolutionContext<BinaryVector> solutionContext, IRandom random) {
     114      Evaluate(solutionContext, random, CancellationToken.None);
     115    }
     116    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    }
     120
    112121    public bool Maximization {
    113122      get {
     
    125134    }
    126135
     136    public void Analyze(ISingleObjectiveSolutionContext<BinaryVector>[] solutionContexts, ResultCollection results, IRandom random) {
     137      var solutions = solutionContexts.Select(c => c.EncodedSolution).ToArray();
     138      var qualities = solutionContexts.Select(c => c.EvaluationResult.Quality).ToArray();
     139      Analyze(solutions, qualities, results, random);
     140    }
     141
    127142    public IEnumerable<BinaryVector> GetNeighbors(BinaryVector individual, IRandom random) {
    128143      return problem.GetNeighbors(individual, random);
    129144    }
     145    public IEnumerable<ISingleObjectiveSolutionContext<BinaryVector>> GetNeighbors(ISingleObjectiveSolutionContext<BinaryVector> solutionContext, IRandom random) {
     146      return GetNeighbors(solutionContext.EncodedSolution, random).Select(n => new SingleObjectiveSolutionContext<BinaryVector>(n));
     147    }
    130148  }
    131149}
Note: See TracChangeset for help on using the changeset viewer.