Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/20/11 13:36:49 (13 years ago)
Author:
svonolfe
Message:

Improved performance of many VRP operators by optimizing the parameter lookup (#1561)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.VehicleRouting/3.3/VRPUtilities.cs

    r5445 r6449  
    2525
    2626namespace HeuristicLab.Problems.VehicleRouting {
     27  public struct DistanceMatrix {
     28    public DoubleMatrix Matrix { get; set; }
     29    public BoolValue UseDistanceMatrix { get; set; }
     30  }
     31
    2732  public sealed class VRPUtilities {
    2833    public static double CalculateDistance(int start, int end, DoubleMatrix coordinates) {
     
    5055
    5156      return distanceMatrix;
     57    }
     58
     59    public static DistanceMatrix GetDistanceMatrix(DoubleMatrix coordinates, IParameter distanceMatrix, BoolValue useDistanceMatrix) {
     60      DistanceMatrix result = new DistanceMatrix();
     61     
     62      if (useDistanceMatrix.Value) {
     63        result.UseDistanceMatrix = new BoolValue(true);
     64        if (distanceMatrix is IValueParameter<DoubleMatrix>) {
     65          if ((distanceMatrix as IValueParameter<DoubleMatrix>).Value == null) {
     66            (distanceMatrix as IValueParameter<DoubleMatrix>).Value = CreateDistanceMatrix(coordinates);
     67          }
     68
     69          result.Matrix = (distanceMatrix as IValueParameter<DoubleMatrix>).Value;
     70        } else {
     71          if (distanceMatrix.ActualValue == null) {
     72            distanceMatrix.ActualValue = CreateDistanceMatrix(coordinates);
     73          }
     74
     75          result.Matrix = (distanceMatrix.ActualValue as DoubleMatrix);
     76        }
     77      } else {
     78        result.UseDistanceMatrix = new BoolValue(false);
     79        result.Matrix = coordinates;
     80      }
     81
     82      return result;
     83    }
     84
     85    public static double GetDistance(int start, int end, DistanceMatrix distMatrix) {
     86      double distance = 0.0;
     87
     88      if (distMatrix.UseDistanceMatrix.Value)
     89        distance = distMatrix.Matrix[start, end];
     90      else
     91        distance = CalculateDistance(start, end, distMatrix.Matrix);
     92
     93      return distance;
    5294    }
    5395
Note: See TracChangeset for help on using the changeset viewer.