Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
08/01/11 17:48:53 (13 years ago)
Author:
mkommend
Message:

#1479: Integrated trunk changes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/GP.Grammar.Editor/HeuristicLab.Problems.VehicleRouting/3.3/VRPUtilities.cs

    r5445 r6618  
    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.