Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
08/04/11 10:04:09 (13 years ago)
Author:
abeham
Message:

#1541, #1603, #1606, #1607

  • merged to trunk
Location:
trunk/sources
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources

  • trunk/sources/HeuristicLab.Problems.QuadraticAssignment/3.3/Evaluators/QAPSwap2MoveEvaluator.cs

    r5933 r6628  
    4949    }
    5050
     51    /// <summary>
     52    /// Calculates the quality of the move <paramref name="move"/> by evaluating the changes.
     53    /// The runtime complexity of this method is O(N) with N being the size of the permutation.
     54    /// </summary>
     55    /// <param name="assignment">The current permutation.</param>
     56    /// <param name="move">The move that is to be evaluated if it was applied to the current permutation.</param>
     57    /// <param name="weights">The weights matrix.</param>
     58    /// <param name="distances">The distances matrix.</param>
     59    /// <returns>The relative change in quality if <paramref name="move"/> was applied to <paramref name="assignment"/>.</returns>
    5160    public static double Apply(Permutation assignment, Swap2Move move, DoubleMatrix weights, DoubleMatrix distances) {
    5261      if (move.Index1 == move.Index2) return 0;
     
    7382    }
    7483
     84    /// <summary>
     85    /// Is able to compute the move qualities faster O(1) in some cases if it knows the quality of
     86    /// performing the move <paramref name="move"/> previously. In other cases it performs a
     87    /// standard move quality calculation with runtime complexity O(N).
     88    /// </summary>
     89    /// <remarks>
     90    /// The number of cases that the calculation can be performed faster grows with N^2
     91    /// while the number of cases which require a larger recalculation grows linearly with N.
     92    /// Larger problem instances thus benefit from this faster method to a larger degree.
     93    /// </remarks>
     94    /// <param name="assignment">The current permutation.</param>
     95    /// <param name="move">The current move that is to be evaluated.</param>
     96    /// <param name="previousQuality">The quality of that move as evaluated for the previous permutation.</param>
     97    /// <param name="weights">The weigths matrix.</param>
     98    /// <param name="distances">The distances matrix.</param>
     99    /// <param name="lastMove">The move that was applied to transform the permutation from the previous to the current one.</param>
     100    /// <returns>The relative change in quality if <paramref name="move"/> was applied to <paramref name="assignment"/>.</returns>
     101    public static double Apply(Permutation assignment, Swap2Move move, double previousQuality,
     102      DoubleMatrix weights, DoubleMatrix distances, Swap2Move lastMove) {
     103      bool overlapsLastMove = move.Index1 == lastMove.Index1
     104                           || move.Index2 == lastMove.Index1
     105                           || move.Index1 == lastMove.Index2
     106                           || move.Index2 == lastMove.Index2;
     107
     108      if (!overlapsLastMove) {
     109        int r = lastMove.Index1, u = move.Index1, s = lastMove.Index2, v = move.Index2;
     110        int pR = assignment[lastMove.Index1], pU = assignment[move.Index1], pS = assignment[lastMove.Index2], pV = assignment[move.Index2];
     111
     112        return previousQuality
     113          + (weights[r, u] - weights[r, v] + weights[s, v] - weights[s, u])
     114            * (distances[pS, pU] - distances[pS, pV] + distances[pR, pV] - distances[pR, pU])
     115          + (weights[u, r] - weights[v, r] + weights[v, s] - weights[u, s])
     116            * (distances[pU, pS] - distances[pV, pS] + distances[pV, pR] - distances[pU, pR]);
     117      } else {
     118        return Apply(assignment, move, weights, distances);
     119      }
     120    }
     121
    75122    public override IOperation Apply() {
    76123      Swap2Move move = Swap2MoveParameter.ActualValue;
Note: See TracChangeset for help on using the changeset viewer.