Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/14/12 11:19:36 (12 years ago)
Author:
abeham
Message:

#1841:

  • Corrected best known solutions in new taillard and microarray instances
  • Improved computation of an average fitness in the QAP
Location:
trunk/sources/HeuristicLab.Problems.QuadraticAssignment/3.3
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.QuadraticAssignment/3.3/BoundsCalculators/GilmoreLawlerBoundCalculator.cs

    r8092 r8910  
    2222using System;
    2323using HeuristicLab.Data;
     24using HeuristicLab.Encodings.PermutationEncoding;
    2425using HeuristicLab.Problems.LinearAssignment;
    2526
     
    2728  public static class GilmoreLawlerBoundCalculator {
    2829    public static double CalculateLowerBound(DoubleMatrix weights, DoubleMatrix distances) {
     30      Permutation tmp;
     31      return CalculateLowerBound(weights, distances, out tmp);
     32    }
     33
     34    public static double CalculateLowerBound(DoubleMatrix weights, DoubleMatrix distances, out Permutation solution) {
    2935      int N = weights.Rows;
    3036      DoubleMatrix sortedWeights = SortEachRowExceptDiagonal(weights), sortedDistances = SortEachRowExceptDiagonal(distances);
     
    4046
    4147      double result;
    42       LinearAssignmentProblemSolver.Solve(costs, out result);
     48      solution = new Permutation(PermutationTypes.Absolute, LinearAssignmentProblemSolver.Solve(costs, out result));
    4349      return result;
    4450    }
  • trunk/sources/HeuristicLab.Problems.QuadraticAssignment/3.3/QuadraticAssignmentProblem.cs

    r8553 r8910  
    177177      if (!Parameters.ContainsKey("AverageQuality")) {
    178178        Parameters.Add(new OptionalValueParameter<DoubleValue>("AverageQuality", "The expected quality of a random solution."));
    179         AverageQuality = new DoubleValue(Weights.Average() * Distances.Average() * Weights.Rows * Weights.Rows);
     179        AverageQuality = new DoubleValue(ComputeAverageQuality());
    180180      }
    181181      #endregion
     
    401401
    402402    private void UpdateParameterValues() {
    403       LowerBound = new DoubleValue(GilmoreLawlerBoundCalculator.CalculateLowerBound(Weights, Distances));
    404       AverageQuality = new DoubleValue(Weights.Average() * Distances.Average() * Weights.Rows * Weights.Rows);
     403      Permutation lbSolution;
     404      // calculate the optimum of a LAP relaxation and use it as lower bound of our QAP
     405      LowerBound = new DoubleValue(GilmoreLawlerBoundCalculator.CalculateLowerBound(Weights, Distances, out lbSolution));
     406      // evalute the LAP optimal solution as if it was a QAP solution
     407      var lbSolutionQuality = QAPEvaluator.Apply(lbSolution, Weights, Distances);
     408      // in case both qualities are the same it means that the LAP optimum is also a QAP optimum
     409      if (LowerBound.Value.IsAlmost(lbSolutionQuality)) {
     410        BestKnownSolution = lbSolution;
     411        BestKnownQuality = new DoubleValue(LowerBound.Value);
     412      }
     413      AverageQuality = new DoubleValue(ComputeAverageQuality());
     414    }
     415
     416    private double ComputeAverageQuality() {
     417      double rt = 0, rd = 0, wt = 0, wd = 0;
     418      int n = Weights.Rows;
     419      for (int i = 0; i < n; i++)
     420        for (int j = 0; j < n; j++) {
     421          if (i == j) {
     422            rd += Distances[i, i];
     423            wd += Weights[i, i];
     424          } else {
     425            rt += Distances[i, j];
     426            wt += Weights[i, j];
     427          }
     428        }
     429
     430      return rt * wt / (n * (n - 1)) + rd * wd / n;
    405431    }
    406432    #endregion
Note: See TracChangeset for help on using the changeset viewer.