Changeset 17320


Ignore:
Timestamp:
10/04/19 17:31:54 (10 days ago)
Author:
mkommend
Message:

#2521: Added cancellation token to evaluate function of problems.

Location:
branches/2521_ProblemRefactoring
Files:
39 edited

Legend:

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

    r17270 r17320  
    2222using System;
    2323using System.Linq;
     24using System.Threading;
    2425using HEAL.Attic;
    2526using HeuristicLab.Common;
     
    197198    private readonly object syncRoot = new object();
    198199    // Does not produce the same result for the same seed when using parallel engine (see below)!
    199     public override double Evaluate(ISymbolicExpressionTree tree, IRandom random) {
     200    public override double Evaluate(ISymbolicExpressionTree tree, IRandom random, CancellationToken cancellationToken) {
    200201      var meanFunction = new MeanConst();
    201202      var problemData = ProblemData;
  • branches/2521_ProblemRefactoring/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/EvaluationTracker.cs

    r17226 r17320  
    2323using System;
    2424using System.Collections.Generic;
     25using System.Threading;
     26using HEAL.Attic;
    2527using HeuristicLab.Common;
    2628using HeuristicLab.Core;
    2729using HeuristicLab.Encodings.BinaryVectorEncoding;
    2830using HeuristicLab.Optimization;
    29 using HEAL.Attic;
    3031
    3132namespace HeuristicLab.Algorithms.ParameterlessPopulationPyramid {
     
    9394    }
    9495
     96    public double Evaluate(BinaryVector vector, IRandom random) {
     97      return Evaluate(vector, random, CancellationToken.None);
     98    }
    9599
    96 
    97     public double Evaluate(BinaryVector vector, IRandom random) {
     100    public double Evaluate(BinaryVector vector, IRandom random, CancellationToken cancellationToken) {
    98101      if (Evaluations >= maxEvaluations) throw new OperationCanceledException("Maximum Evaluation Limit Reached");
    99102      Evaluations++;
  • branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Interfaces/IMultiObjectiveProblem.cs

    r17317 r17320  
    3333    where TEncoding : class, IEncoding<TEncodedSolution>
    3434    where TEncodedSolution : class, IEncodedSolution { }
     35
     36  //TODO derive IMutliObjectiveProblem from IMultiObjectiveProblemDefinition?
    3537}
  • branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Interfaces/IMultiObjectiveProblemDefinition.cs

    r17315 r17320  
    2121
    2222using System.Collections.Generic;
     23using System.Threading;
    2324using HEAL.Attic;
    2425using HeuristicLab.Core;
     
    3839    where TEncodedSolution : class, IEncodedSolution {
    3940    double[] Evaluate(TEncodedSolution solution, IRandom random);
     41    double[] Evaluate(TEncodedSolution solution, IRandom random, CancellationToken cancellationToken);
    4042    void Analyze(TEncodedSolution[] solutions, double[][] qualities, ResultCollection results, IRandom random);
    4143  }
  • branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Interfaces/ISingleObjectiveProblem.cs

    r17317 r17320  
    3333    where TEncoding : class, IEncoding<TEncodedSolution>
    3434    where TEncodedSolution : class, IEncodedSolution { }
     35  //TODO derive ISingleObjectiveProblem from ISingleObjectiveProblemDefinition?
    3536}
  • branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Interfaces/ISingleObjectiveProblemDefinition.cs

    r17257 r17320  
    2121
    2222using System.Collections.Generic;
     23using System.Threading;
    2324using HEAL.Attic;
    2425using HeuristicLab.Core;
     
    3536    where TEncoding : class, IEncoding<TEncodedSolution>
    3637    where TEncodedSolution : class, IEncodedSolution {
     38
    3739    double Evaluate(TEncodedSolution solution, IRandom random);
     40    double Evaluate(TEncodedSolution solution, IRandom random, CancellationToken cancellationToken);
     41
    3842    void Analyze(TEncodedSolution[] solutions, double[] qualities, ResultCollection results, IRandom random);
    3943    IEnumerable<TEncodedSolution> GetNeighbors(TEncodedSolution solution, IRandom random);
  • branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/MultiObjectiveProblem.cs

    r17317 r17320  
    2323using System.Collections.Generic;
    2424using System.Linq;
     25using System.Threading;
    2526using HEAL.Attic;
    2627using HeuristicLab.Common;
     
    133134    }
    134135
    135     public abstract double[] Evaluate(TEncodedSolution solution, IRandom random);
     136    public virtual double[] Evaluate(TEncodedSolution solution, IRandom random) {
     137      return Evaluate(solution, random, CancellationToken.None);
     138    }
     139
     140    public abstract double[] Evaluate(TEncodedSolution solution, IRandom random, CancellationToken cancellationToken);
    136141    public virtual void Analyze(TEncodedSolution[] solutions, double[][] qualities, ResultCollection results, IRandom random) { }
    137142
  • branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/SingleObjectiveProblem.cs

    r17317 r17320  
    2323using System.Collections.Generic;
    2424using System.Linq;
     25using System.Threading;
    2526using HEAL.Attic;
    2627using HeuristicLab.Common;
     
    112113    }
    113114
    114     public abstract double Evaluate(TEncodedSolution solution, IRandom random);
     115    public virtual double Evaluate(TEncodedSolution solution, IRandom random) {
     116      return Evaluate(solution, random, CancellationToken.None);
     117    }
     118    public abstract double Evaluate(TEncodedSolution solution, IRandom random, CancellationToken cancellationToken);
    115119    public virtual void Analyze(TEncodedSolution[] solutions, double[] qualities, ResultCollection results, IRandom random) { }
    116120    public virtual IEnumerable<TEncodedSolution> GetNeighbors(TEncodedSolution solution, IRandom random) {
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.Binary/3.3/DeceptiveTrapProblem.cs

    r17270 r17320  
    2323
    2424using System;
     25using System.Threading;
    2526using HEAL.Attic;
    2627using HeuristicLab.Common;
     
    8081    }
    8182
    82     public override double Evaluate(BinaryVector individual, IRandom random) {
     83    public override double Evaluate(BinaryVector individual, IRandom random, CancellationToken cancellationToken) {
    8384      if (individual.Length != Length) throw new ArgumentException("The individual has not the correct length.");
    8485      int total = 0;
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.Binary/3.3/HIFFProblem.cs

    r17270 r17320  
    2323
    2424using System;
     25using System.Threading;
    2526using HEAL.Attic;
    2627using HeuristicLab.Common;
     
    4748    }
    4849    // In the GECCO paper, Section 4.1
    49     public override double Evaluate(BinaryVector individual, IRandom random) {
     50    public override double Evaluate(BinaryVector individual, IRandom random, CancellationToken cancellationToken) {
    5051      int[] level = new int[individual.Length];
    5152      int levelLength = individual.Length;
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.Binary/3.3/OneMaxProblem.cs

    r17270 r17320  
    2222using System;
    2323using System.Linq;
     24using System.Threading;
    2425using HEAL.Attic;
    2526using HeuristicLab.Common;
     
    4748    }
    4849
    49     public override double Evaluate(BinaryVector vector, IRandom random) {
     50    public override double Evaluate(BinaryVector vector, IRandom random, CancellationToken cancellationToken) {
    5051      return vector.Count(b => b);
    5152    }
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.ExternalEvaluation/3.4/EvaluationCache.cs

    r17226 r17320  
    3131using System.Threading;
    3232using Google.ProtocolBuffers;
     33using HEAL.Attic;
    3334using HeuristicLab.Common;
    3435using HeuristicLab.Common.Resources;
     
    3637using HeuristicLab.Data;
    3738using HeuristicLab.Parameters;
    38 using HEAL.Attic;
    3939
    4040namespace HeuristicLab.Problems.ExternalEvaluation {
     
    5050      private byte[] rawMessage;
    5151
    52       private object lockObject = new object();
     52      private readonly object lockObject = new object();
    5353
    5454      public byte[] RawMessage {
     
    116116    }
    117117
    118     public delegate QualityMessage Evaluator(SolutionMessage message);
     118    public delegate QualityMessage Evaluator(SolutionMessage message, CancellationToken cancellationToken);
    119119    #endregion
    120120
     
    124124
    125125    private HashSet<string> activeEvaluations = new HashSet<string>();
    126     private object cacheLock = new object();
     126    private readonly object cacheLock = new object();
    127127    #endregion
    128128
     
    221221    }
    222222
    223     void CapacityChanged(object sender, EventArgs e) {
     223    private void CapacityChanged(object sender, EventArgs e) {
    224224      if (Capacity < 0)
    225225        throw new ArgumentOutOfRangeException("Cache capacity cannot be less than zero");
     
    240240    }
    241241
    242     public QualityMessage GetValue(SolutionMessage message, Evaluator evaluate, ExtensionRegistry extensions) {
     242    public QualityMessage GetValue(SolutionMessage message, Evaluator evaluate, ExtensionRegistry extensions, CancellationToken cancellationToken) {
    243243      var entry = new CacheEntry(message.ToString());
    244244      bool lockTaken = false;
     
    267267              OnChanged();
    268268              try {
    269                 entry.SetMessage(evaluate(message));
     269                entry.SetMessage(evaluate(message, cancellationToken));
    270270                Monitor.Enter(cacheLock, ref lockTaken);
    271271                index[entry] = list.AddLast(entry);
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.ExternalEvaluation/3.4/Interfaces/IExternalEvaluationProblem.cs

    r17226 r17320  
    2020#endregion
    2121
     22using System.Threading;
    2223using Google.ProtocolBuffers;
     24using HEAL.Attic;
    2325using HeuristicLab.Core;
    2426using HeuristicLab.Optimization;
    25 using HEAL.Attic;
    2627
    2728namespace HeuristicLab.Problems.ExternalEvaluation {
     
    3233    CheckedItemCollection<IEvaluationServiceClient> Clients { get; }
    3334
    34     QualityMessage Evaluate(SolutionMessage solutionMessage);
     35    QualityMessage Evaluate(SolutionMessage solutionMessage, CancellationToken cancellationToken);
    3536    ExtensionRegistry GetQualityMessageExtensions();
    3637  }
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.ExternalEvaluation/3.4/MultiObjectiveExternalEvaluationProblem.cs

    r17317 r17320  
    106106    }
    107107
    108     public override double[] Evaluate(TEncodedSolution individual, IRandom random) {
    109       var qualityMessage = Evaluate(BuildSolutionMessage(individual));
     108    public override double[] Evaluate(TEncodedSolution individual, IRandom random, CancellationToken cancellationToken) {
     109      var qualityMessage = Evaluate(BuildSolutionMessage(individual), cancellationToken);
    110110      if (!qualityMessage.HasExtension(MultiObjectiveQualityMessage.QualityMessage_))
    111111        throw new InvalidOperationException("The received message is not a MultiObjectiveQualityMessage.");
    112112      return qualityMessage.GetExtension(MultiObjectiveQualityMessage.QualityMessage_).QualitiesList.ToArray();
    113113    }
    114     public virtual QualityMessage Evaluate(SolutionMessage solutionMessage) {
     114    public virtual QualityMessage Evaluate(SolutionMessage solutionMessage, CancellationToken cancellationToken) {
    115115      return Cache == null
    116         ? EvaluateOnNextAvailableClient(solutionMessage)
    117         : Cache.GetValue(solutionMessage, EvaluateOnNextAvailableClient, GetQualityMessageExtensions());
     116        ? EvaluateOnNextAvailableClient(solutionMessage, cancellationToken)
     117        : Cache.GetValue(solutionMessage, EvaluateOnNextAvailableClient, GetQualityMessageExtensions(), cancellationToken);
    118118    }
    119119
     
    132132    #region Evaluation
    133133    private HashSet<IEvaluationServiceClient> activeClients = new HashSet<IEvaluationServiceClient>();
    134     private object clientLock = new object();
     134    private readonly object clientLock = new object();
    135135
    136     private QualityMessage EvaluateOnNextAvailableClient(SolutionMessage message) {
     136    private QualityMessage EvaluateOnNextAvailableClient(SolutionMessage message, CancellationToken cancellationToken) {
    137137      IEvaluationServiceClient client = null;
    138138      lock (clientLock) {
     
    147147      try {
    148148        return client.Evaluate(message, GetQualityMessageExtensions());
    149       }
    150       finally {
     149      } finally {
    151150        lock (clientLock) {
    152151          activeClients.Remove(client);
     
    165164          try {
    166165            MessageBuilder.AddToMessage(variable.Value, variable.Name, protobufBuilder);
    167           }
    168           catch (ArgumentException ex) {
     166          } catch (ArgumentException ex) {
    169167            throw new InvalidOperationException(string.Format("ERROR while building solution message: Parameter {0} cannot be added to the message", Name), ex);
    170168          }
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.ExternalEvaluation/3.4/SingleObjectiveExternalEvaluationProblem.cs

    r17279 r17320  
    103103
    104104    #region Single Objective Problem Overrides
    105     public override double Evaluate(TEncodedSolution solution, IRandom random) {
    106       var qualityMessage = Evaluate(BuildSolutionMessage(solution));
     105    public override double Evaluate(TEncodedSolution solution, IRandom random, CancellationToken cancellationToken) {
     106      var qualityMessage = Evaluate(BuildSolutionMessage(solution), cancellationToken);
    107107      if (!qualityMessage.HasExtension(SingleObjectiveQualityMessage.QualityMessage_))
    108108        throw new InvalidOperationException("The received message is not a SingleObjectiveQualityMessage.");
    109109      return qualityMessage.GetExtension(SingleObjectiveQualityMessage.QualityMessage_).Quality;
    110110    }
    111     public virtual QualityMessage Evaluate(SolutionMessage solutionMessage) {
     111    public virtual QualityMessage Evaluate(SolutionMessage solutionMessage, CancellationToken cancellationToken) {
    112112      return Cache == null
    113         ? EvaluateOnNextAvailableClient(solutionMessage)
    114         : Cache.GetValue(solutionMessage, EvaluateOnNextAvailableClient, GetQualityMessageExtensions());
     113        ? EvaluateOnNextAvailableClient(solutionMessage,cancellationToken)
     114        : Cache.GetValue(solutionMessage, EvaluateOnNextAvailableClient, GetQualityMessageExtensions(), cancellationToken);
    115115    }
    116116
     
    132132    #region Evaluation
    133133    private HashSet<IEvaluationServiceClient> activeClients = new HashSet<IEvaluationServiceClient>();
    134     private object clientLock = new object();
     134    private readonly object clientLock = new object();
    135135
    136     private QualityMessage EvaluateOnNextAvailableClient(SolutionMessage message) {
     136    private QualityMessage EvaluateOnNextAvailableClient(SolutionMessage message, CancellationToken cancellationToken) {
    137137      IEvaluationServiceClient client = null;
    138138      lock (clientLock) {
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.GeneticProgramming/3.3/ArtificialAnt/Problem.cs

    r17270 r17320  
    2323using System.Diagnostics.Contracts;
    2424using System.Linq;
     25using System.Threading;
    2526using HEAL.Attic;
    2627using HeuristicLab.Common;
     
    134135
    135136
    136     public override double Evaluate(ISymbolicExpressionTree tree, IRandom random) {
     137    public override double Evaluate(ISymbolicExpressionTree tree, IRandom random, CancellationToken cancellationToken) {
    137138      var interpreter = new Interpreter(tree, World, MaxTimeSteps);
    138139      interpreter.Run();
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.GeneticProgramming/3.3/BasicSymbolicRegression/Problem.cs

    r17270 r17320  
    2323using System.Collections.Generic;
    2424using System.Linq;
     25using System.Threading;
    2526using HEAL.Attic;
    2627using HeuristicLab.Common;
     
    8990
    9091
    91     public override double Evaluate(ISymbolicExpressionTree tree, IRandom random) {
     92    public override double Evaluate(ISymbolicExpressionTree tree, IRandom random, CancellationToken cancellationToken) {
    9293      // Doesn't use classes from HeuristicLab.Problems.DataAnalysis.Symbolic to make sure that the implementation can be fully understood easily.
    9394      // HeuristicLab.Problems.DataAnalysis.Symbolic would already provide all the necessary functionality (esp. interpreter) but at a much higher complexity.
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.GeneticProgramming/3.3/Boolean/EvenParityProblem.cs

    r17270 r17320  
    2323using System.Collections.Generic;
    2424using System.Linq;
     25using System.Threading;
    2526using HEAL.Attic;
    2627using HeuristicLab.Common;
     
    103104
    104105
    105     public override double Evaluate(ISymbolicExpressionTree tree, IRandom random) {
     106    public override double Evaluate(ISymbolicExpressionTree tree, IRandom random, CancellationToken cancellationToken) {
    106107      if (NumberOfBits <= 0) throw new NotSupportedException("Number of bits must be larger than zero.");
    107108      if (NumberOfBits > 10) throw new NotSupportedException("Even parity does not support problems with number of bits > 10.");
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.GeneticProgramming/3.3/Boolean/MultiplexerProblem.cs

    r17270 r17320  
    2424using System.Diagnostics.Contracts;
    2525using System.Linq;
     26using System.Threading;
    2627using HEAL.Attic;
    2728using HeuristicLab.Common;
     
    117118
    118119
    119     public override double Evaluate(ISymbolicExpressionTree tree, IRandom random) {
     120    public override double Evaluate(ISymbolicExpressionTree tree, IRandom random, CancellationToken cancellationToken) {
    120121      if (NumberOfBits <= 0) throw new NotSupportedException("Number of bits must be larger than zero.");
    121122      if (NumberOfBits > 37) throw new NotSupportedException("Multiplexer does not support problems with number of bits > 37.");
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.GeneticProgramming/3.3/LawnMower/Problem.cs

    r17270 r17320  
    2222using System;
    2323using System.Linq;
     24using System.Threading;
    2425using HEAL.Attic;
    2526using HeuristicLab.Common;
     
    9293    }
    9394
    94     public override double Evaluate(ISymbolicExpressionTree tree, IRandom random) {
     95    public override double Evaluate(ISymbolicExpressionTree tree, IRandom random, CancellationToken cancellationToken) {
    9596      var length = LawnLengthParameter.Value.Value;
    9697      var width = LawnWidthParameter.Value.Value;
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.GeneticProgramming/3.3/robocode/Problem.cs

    r17270 r17320  
    2020#endregion
    2121
     22using System.Threading;
    2223using HEAL.Attic;
    2324using HeuristicLab.Common;
     
    9899    private void AfterDeserialization() { RegisterEventHandlers(); }
    99100
    100     public override double Evaluate(ISymbolicExpressionTree tree, IRandom random) {
     101    public override double Evaluate(ISymbolicExpressionTree tree, IRandom random, CancellationToken cancellationToken) {
    101102      return Interpreter.EvaluateTankProgram(tree, RobocodePath, Enemies, null, false, NrOfRounds);
    102103    }
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.GrammaticalEvolution/3.4/ArtificialAnt/GEArtificialAntProblem.cs

    r17270 r17320  
    2323
    2424using System.Linq;
     25using System.Threading;
    2526using HEAL.Attic;
    2627using HeuristicLab.Common;
     
    9596
    9697    private readonly object syncRoot = new object();
    97     public override double Evaluate(IntegerVector solution, IRandom random) {
     98    public override double Evaluate(IntegerVector solution, IRandom random, CancellationToken cancellationToken) {
    9899      var bounds = Encoding.Bounds;
    99100      var len = Encoding.Length;
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.GraphColoring/3.3/GraphColoringProblem.cs

    r17270 r17320  
    2222using System;
    2323using System.Linq;
     24using System.Threading;
    2425using HEAL.Attic;
    2526using HeuristicLab.Analysis;
     
    128129    }
    129130
    130     public override double Evaluate(LinearLinkage lle, IRandom random) {
     131    public override double Evaluate(LinearLinkage lle, IRandom random, CancellationToken cancellationToken) {
    131132      var adjList = adjacencyListParameter.Value;
    132133      var llee = lle.ToEndLinks(); // LLE-e encoding uses the highest indexed member as group number
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.Knapsack/3.3/KnapsackProblem.cs

    r17270 r17320  
    2323using System.Collections.Generic;
    2424using System.Linq;
     25using System.Threading;
    2526using HEAL.Attic;
    2627using HeuristicLab.Analysis;
     
    9697    }
    9798
    98     public override double Evaluate(BinaryVector solution, IRandom random) {
     99    public override double Evaluate(BinaryVector solution, IRandom random, CancellationToken cancellationToken) {
    99100      var totalWeight = 0.0;
    100101      var totalValue = 0.0;
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.NK/3.3/NKLandscape.cs

    r17270 r17320  
    2323using System.Linq;
    2424using System.Security.Cryptography;
     25using System.Threading;
    2526using HEAL.Attic;
    2627using HeuristicLab.Common;
     
    334335    }
    335336
    336     public override double Evaluate(BinaryVector vector, IRandom random) {
     337    public override double Evaluate(BinaryVector vector, IRandom random, CancellationToken cancellationToken) {
    337338      double[] f_i; //useful for debugging
    338339      double quality = Evaluate(vector, GeneInteractions, Weights, InteractionSeed.Value, out f_i, Q, P);
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.PTSP.Views/3.3/HeuristicLab.Problems.PTSP.Views-3.3.csproj

    r17264 r17320  
    7373      <Private>False</Private>
    7474    </ProjectReference>
     75    <ProjectReference Include="..\..\HeuristicLab.Common.Resources\3.3\HeuristicLab.Common.Resources-3.3.csproj">
     76      <Project>{0e27a536-1c4a-4624-a65e-dc4f4f23e3e1}</Project>
     77      <Name>HeuristicLab.Common.Resources-3.3</Name>
     78    </ProjectReference>
    7579    <ProjectReference Include="..\..\HeuristicLab.Common\3.3\HeuristicLab.Common-3.3.csproj">
    7680      <Project>{A9AD58B9-3EF9-4CC1-97E5-8D909039FF5C}</Project>
     
    157161      <Private>False</Private>
    158162    </ProjectReference>
    159     <Reference Include="HeuristicLab.Common.Resources-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL" />
    160163    <Reference Include="System" />
    161164    <Reference Include="System.Core" />
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.PTSP/3.3/AnalyticalPTSP.cs

    r17264 r17320  
    2020#endregion
    2121
     22using System.Threading;
    2223using HEAL.Attic;
    2324using HeuristicLab.Common;
     
    5960    }
    6061
    61     public override double Evaluate(Permutation tour, IRandom random) {
    62       return Evaluate(tour, ProbabilisticTSPData);
     62    public override double Evaluate(Permutation tour, IRandom random, CancellationToken cancellationToken) {
     63      return Evaluate(tour, ProbabilisticTSPData, cancellationToken);
    6364    }
    6465
    65     public static double Evaluate(Permutation tour, IProbabilisticTSPData data) {
     66    public static double Evaluate(Permutation tour, IProbabilisticTSPData data, CancellationToken cancellationToken) {
    6667      // Analytical evaluation
    6768      var firstSum = 0.0;
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.PTSP/3.3/EstimatedPTSP.cs

    r17264 r17320  
    2323using System.Collections.Generic;
    2424using System.Linq;
     25using System.Threading;
    2526using HEAL.Attic;
    2627using HeuristicLab.Common;
     
    101102    }
    102103
    103     public override double Evaluate(Permutation tour, IRandom random) {
    104       return Evaluate(tour, ProbabilisticTSPData, RealizationData);
     104    public override double Evaluate(Permutation tour, IRandom random, CancellationToken cancellationToken) {
     105      return Evaluate(tour, ProbabilisticTSPData, RealizationData, cancellationToken);
    105106    }
    106107
     
    110111    }
    111112
    112     public static double Evaluate(Permutation tour, IProbabilisticTSPData data, IEnumerable<BoolArray> realizations) {
     113    public static double Evaluate(Permutation tour, IProbabilisticTSPData data, IEnumerable<BoolArray> realizations, CancellationToken cancellationToken) {
    113114      // Estimation-based evaluation, here without calculating variance for faster evaluation
    114115      var estimatedSum = 0.0;
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.PTSP/3.3/Moves/OneShift/PTSPAnalyticalInsertionMoveEvaluator.cs

    r17253 r17320  
    2020#endregion
    2121
     22using System.Threading;
    2223using HEAL.Attic;
    2324using HeuristicLab.Common;
     
    5051      var afterMove = (Permutation)tour.Clone();
    5152      TranslocationManipulator.Apply(afterMove, move.Index1, move.Index1, move.Index3);
    52       return AnalyticalPTSP.Evaluate(afterMove, data);
     53      return AnalyticalPTSP.Evaluate(afterMove, data, CancellationToken.None);
    5354    }
    5455
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.PTSP/3.3/Moves/TwoOpt/PTSPAnalyticalInversionMoveEvaluator.cs

    r17253 r17320  
    2020#endregion
    2121
     22using System.Threading;
    2223using HEAL.Attic;
    2324using HeuristicLab.Common;
     
    5051      var afterMove = (Permutation)tour.Clone();
    5152      InversionManipulator.Apply(afterMove, move.Index1, move.Index2);
    52       return AnalyticalPTSP.Evaluate(afterMove, data);
     53      return AnalyticalPTSP.Evaluate(afterMove, data, CancellationToken.None);
    5354    }
    5455
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.Programmable/3.3/CompiledProblemDefinition.cs

    r17315 r17320  
    2222using System;
    2323using System.Collections.Generic;
     24using System.Threading;
    2425using HeuristicLab.Core;
    25 using HeuristicLab.Data;
    2626using HeuristicLab.Optimization;
    2727
     
    5959    #region ISingleObjectiveProblemDefinition<TEncoding,TEncodedSolution> Members
    6060    public abstract bool Maximization { get; }
    61     public abstract double Evaluate(TEncodedSolution individual, IRandom random);
     61
     62    public virtual double Evaluate(TEncodedSolution solution, IRandom random) {
     63      return Evaluate(solution, random, CancellationToken.None);
     64    }
     65    public abstract double Evaluate(TEncodedSolution solution, IRandom random, CancellationToken cancellationToken);
    6266    public abstract void Analyze(TEncodedSolution[] individuals, double[] qualities, ResultCollection results, IRandom random);
    6367    public abstract IEnumerable<TEncodedSolution> GetNeighbors(TEncodedSolution individual, IRandom random);
     
    8286    public abstract IReadOnlyList<double[]> BestKnownFront { get; }
    8387    public abstract double[] ReferencePoint { get; }
    84     public abstract double[] Evaluate(TEncodedSolution individual, IRandom random);
     88
     89    public virtual double[] Evaluate(TEncodedSolution solution, IRandom random) {
     90      return Evaluate(solution, random, CancellationToken.None);
     91    }
     92    public abstract double[] Evaluate(TEncodedSolution solution, IRandom random, CancellationToken cancellationToken);
    8593    public abstract void Analyze(TEncodedSolution[] individuals, double[][] qualities, ResultCollection results, IRandom random);
    8694    public abstract IEnumerable<TEncodedSolution> GetNeighbors(TEncodedSolution individual, IRandom random);
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.Programmable/3.3/MultiObjectiveProblemDefinitionScript.cs

    r17315 r17320  
    2121
    2222using System.Collections.Generic;
     23using System.Threading;
    2324using HEAL.Attic;
    2425using HeuristicLab.Common;
    2526using HeuristicLab.Core;
    26 using HeuristicLab.Data;
    2727using HeuristicLab.Optimization;
    2828
     
    5959    }
    6060
     61    double[] IMultiObjectiveProblemDefinition<TEncoding, TEncodedSolution>.Evaluate(TEncodedSolution individual, IRandom random, CancellationToken cancellationToken) {
     62      return CompiledProblemDefinition.Evaluate(individual, random, cancellationToken);
     63    }
     64
    6165    void IMultiObjectiveProblemDefinition<TEncoding, TEncodedSolution>.Analyze(TEncodedSolution[] individuals, double[][] qualities, ResultCollection results, IRandom random) {
    6266      CompiledProblemDefinition.Analyze(individuals, qualities, results, random);
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.Programmable/3.3/MultiObjectiveProgrammableProblem.cs

    r17317 r17320  
    2222using System.Collections.Generic;
    2323using System.Drawing;
     24using System.Threading;
    2425using HEAL.Attic;
    2526using HeuristicLab.Common;
     
    118119      return ProblemDefinition.Evaluate(individual, random);
    119120    }
     121    public override double[] Evaluate(TEncodedSolution individual, IRandom random, CancellationToken cancellationToken) {
     122      return ProblemDefinition.Evaluate(individual, random, cancellationToken);
     123    }
    120124
    121125    public override void Analyze(TEncodedSolution[] individuals, double[][] qualities, ResultCollection results, IRandom random) {
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.Programmable/3.3/SingleObjectiveProblemDefinitionScript.cs

    r17226 r17320  
    2121
    2222using System.Collections.Generic;
     23using System.Threading;
    2324using HEAL.Attic;
    2425using HeuristicLab.Common;
     
    5051    public bool Maximization => CompiledProblemDefinition.Maximization;
    5152
    52     double ISingleObjectiveProblemDefinition<TEncoding, TEncodedSolution>.Evaluate(TEncodedSolution individual, IRandom random) {
    53       return CompiledProblemDefinition.Evaluate(individual, random);
     53    double ISingleObjectiveProblemDefinition<TEncoding, TEncodedSolution>.Evaluate(TEncodedSolution solution, IRandom random) {
     54      return CompiledProblemDefinition.Evaluate(solution, random);
     55    }
     56
     57    double ISingleObjectiveProblemDefinition<TEncoding, TEncodedSolution>.Evaluate(TEncodedSolution solution, IRandom random, CancellationToken cancellationToken) {
     58      return CompiledProblemDefinition.Evaluate(solution, random, cancellationToken);
    5459    }
    5560
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.Programmable/3.3/SingleObjectiveProgrammableProblem.cs

    r17270 r17320  
    2222using System.Collections.Generic;
    2323using System.Drawing;
     24using System.Threading;
    2425using HEAL.Attic;
    2526using HeuristicLab.Analysis;
     
    107108    }
    108109
    109     public override double Evaluate(TEncodedSolution individual, IRandom random) {
    110       return ProblemDefinition.Evaluate(individual, random);
     110    public override double Evaluate(TEncodedSolution individual, IRandom random, CancellationToken cancellationToken) {
     111      return ProblemDefinition.Evaluate(individual, random, cancellationToken);
    111112    }
    112113
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.QuadraticAssignment/3.3/QuadraticAssignmentProblem.cs

    r17270 r17320  
    2424using System.Drawing;
    2525using System.Linq;
     26using System.Threading;
    2627using HEAL.Attic;
    2728using HeuristicLab.Common;
     
    135136    }
    136137
    137     public override double Evaluate(Permutation assignment, IRandom random) {
    138       return Evaluate(assignment);
    139     }
    140 
    141     public double Evaluate(Permutation assignment) {
     138    public override double Evaluate(Permutation assignment, IRandom random, CancellationToken cancellationToken) {
     139      return Evaluate(assignment, cancellationToken);
     140    }
     141
     142    public double Evaluate(Permutation assignment, CancellationToken cancellationToken) {
    142143      double quality = 0;
    143144      for (int i = 0; i < assignment.Length; i++) {
     
    283284      // calculate the optimum of a LAP relaxation and use it as lower bound of our QAP
    284285      LowerBound = new DoubleValue(GilmoreLawlerBoundCalculator.CalculateLowerBound(Weights, Distances, out lbSolution));
    285       // evalute the LAP optimal solution as if it was a QAP solution
    286       var lbSolutionQuality = Evaluate(lbSolution);
     286      // evaluate the LAP optimal solution as if it was a QAP solution
     287      var lbSolutionQuality = Evaluate(lbSolution, CancellationToken.None);
    287288      // in case both qualities are the same it means that the LAP optimum is also a QAP optimum
    288289      if (LowerBound.Value.IsAlmost(lbSolutionQuality)) {
     
    312313
    313314    public void Load(QAPData data) {
    314       if (data.Dimension > ProblemSizeLimit) throw new System.IO.InvalidDataException("The problem is limited to instance of size " + ProblemSizeLimit + ". You can change this limit by modifying " + nameof(QuadraticAssignmentProblem) + "." + nameof(ProblemSizeLimit) +"!");
     315      if (data.Dimension > ProblemSizeLimit) throw new System.IO.InvalidDataException("The problem is limited to instance of size " + ProblemSizeLimit + ". You can change this limit by modifying " + nameof(QuadraticAssignmentProblem) + "." + nameof(ProblemSizeLimit) + "!");
    315316      var weights = new DoubleMatrix(data.Weights, @readonly: true);
    316317      var distances = new DoubleMatrix(data.Distances, @readonly: true);
     
    363364      if (assignment == null || assignment.Length == 0) return;
    364365      var vector = new Permutation(PermutationTypes.Absolute, assignment);
    365       var result = Evaluate(vector);
     366      var result = Evaluate(vector, CancellationToken.None);
    366367      BestKnownQuality = result;
    367368      BestKnownSolution = vector;
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/MultiObjectiveTestFunctionProblem.cs

    r17317 r17320  
    2020#endregion
    2121using System;
     22using System.Threading;
    2223using HEAL.Attic;
    2324using HeuristicLab.Analysis;
     
    121122    }
    122123
    123     public override double[] Evaluate(RealVector solution, IRandom random) {
     124    public override double[] Evaluate(RealVector solution, IRandom random, CancellationToken cancellationToken) {
    124125      return TestFunction.Evaluate(solution, Objectives);
    125126    }
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.TestFunctions/3.3/SingleObjectiveTestFunctionProblem.cs

    r17270 r17320  
    2323using System.Collections.Generic;
    2424using System.Linq;
     25using System.Threading;
    2526using HEAL.Attic;
    2627using HeuristicLab.Analysis;
     
    108109    }
    109110
    110     public override double Evaluate(RealVector individual, IRandom random) {
     111    public override double Evaluate(RealVector individual, IRandom random, CancellationToken cancellationToken) {
    111112      return TestFunction.Evaluate(individual);
    112113    }
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.TravelingSalesman/3.3/TSP.cs

    r17270 r17320  
    2323using System.Collections.Generic;
    2424using System.Linq;
     25using System.Threading;
    2526using HEAL.Attic;
    2627using HeuristicLab.Common;
     
    8283    }
    8384
    84     public override double Evaluate(Permutation tour, IRandom random) {
     85    public override double Evaluate(Permutation tour, IRandom random, CancellationToken cancellationToken) {
    8586      return Evaluate(tour);
    8687    }
Note: See TracChangeset for help on using the changeset viewer.