Free cookie consent management tool by TermsFeed Policy Generator

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

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

File:
1 edited

Legend:

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