Changeset 8910 for trunk/sources/HeuristicLab.Problems.QuadraticAssignment
- Timestamp:
- 11/14/12 11:19:36 (12 years ago)
- 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 22 22 using System; 23 23 using HeuristicLab.Data; 24 using HeuristicLab.Encodings.PermutationEncoding; 24 25 using HeuristicLab.Problems.LinearAssignment; 25 26 … … 27 28 public static class GilmoreLawlerBoundCalculator { 28 29 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) { 29 35 int N = weights.Rows; 30 36 DoubleMatrix sortedWeights = SortEachRowExceptDiagonal(weights), sortedDistances = SortEachRowExceptDiagonal(distances); … … 40 46 41 47 double result; 42 LinearAssignmentProblemSolver.Solve(costs, out result);48 solution = new Permutation(PermutationTypes.Absolute, LinearAssignmentProblemSolver.Solve(costs, out result)); 43 49 return result; 44 50 } -
trunk/sources/HeuristicLab.Problems.QuadraticAssignment/3.3/QuadraticAssignmentProblem.cs
r8553 r8910 177 177 if (!Parameters.ContainsKey("AverageQuality")) { 178 178 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()); 180 180 } 181 181 #endregion … … 401 401 402 402 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; 405 431 } 406 432 #endregion
Note: See TracChangeset
for help on using the changeset viewer.