Free cookie consent management tool by TermsFeed Policy Generator

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

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

Location:
trunk/sources/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Zhu
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Zhu/Crossovers/ZhuPermutationCrossover.cs

    r5445 r6449  
    4848
    4949    protected override ZhuEncoding Crossover(IRandom random, ZhuEncoding parent1, ZhuEncoding parent2) {
    50       //note - the inner crossover is called here and the result is converted to a prins representation
     50      //note - the inner crossover is called here and the solution is converted to a prins representation
    5151      //some refactoring should be done here in the future - the crossover operation should be called directly
    5252
    53       InnerCrossoverParameter.ActualValue.ParentsParameter.ActualName = ParentsParameter.ActualName;
    54       IAtomicOperation op = this.ExecutionContext.CreateOperation(
    55         InnerCrossoverParameter.ActualValue, this.ExecutionContext.Scope);
    56       op.Operator.Execute((IExecutionContext)op, CancellationToken);
     53      if (parent1.Length == parent2.Length) {
     54        InnerCrossoverParameter.ActualValue.ParentsParameter.ActualName = ParentsParameter.ActualName;
     55        IAtomicOperation op = this.ExecutionContext.CreateOperation(
     56          InnerCrossoverParameter.ActualValue, this.ExecutionContext.Scope);
     57        op.Operator.Execute((IExecutionContext)op, CancellationToken);
    5758
    58       string childName = InnerCrossoverParameter.ActualValue.ChildParameter.ActualName;
    59       if (ExecutionContext.Scope.Variables.ContainsKey(childName)) {
    60         Permutation permutation = ExecutionContext.Scope.Variables[childName].Value as Permutation;
    61         ExecutionContext.Scope.Variables.Remove(childName);
     59        string childName = InnerCrossoverParameter.ActualValue.ChildParameter.ActualName;
     60        if (ExecutionContext.Scope.Variables.ContainsKey(childName)) {
     61          Permutation permutation = ExecutionContext.Scope.Variables[childName].Value as Permutation;
     62          ExecutionContext.Scope.Variables.Remove(childName);
    6263
    63         return new ZhuEncoding(permutation, Cities,
    64           DueTimeParameter.ActualValue,
    65             ServiceTimeParameter.ActualValue,
    66             ReadyTimeParameter.ActualValue,
    67             DemandParameter.ActualValue,
    68             CapacityParameter.ActualValue,
    69             CoordinatesParameter.ActualValue,
    70             UseDistanceMatrixParameter.ActualValue);
    71       } else
    72         return null;
     64          return new ZhuEncoding(permutation, Cities,
     65            DueTimeParameter.ActualValue,
     66              ServiceTimeParameter.ActualValue,
     67              ReadyTimeParameter.ActualValue,
     68              DemandParameter.ActualValue,
     69              CapacityParameter.ActualValue,
     70              CoordinatesParameter.ActualValue,
     71              UseDistanceMatrixParameter.ActualValue);
     72        } else
     73          return null;
     74      } else {
     75        return parent1.Clone() as ZhuEncoding;
     76      }
    7377    }
    7478  }
  • trunk/sources/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Zhu/ZhuEncoding.cs

    r5445 r6449  
    6363      Tour newTour = new Tour();
    6464
     65      DistanceMatrix distMatrix = VRPUtilities.GetDistanceMatrix(coordinates, distanceMatrix, useDistanceMatrix);
     66
    6567      for (int i = 0; i < this.Length; i++) {
    6668        int city = this[i] + 1;
     
    7274          demandArray,
    7375          capacity,
    74           coordinates,
    75           distanceMatrix,
    76           useDistanceMatrix)) {
     76          distMatrix)) {
    7777          newTour.Cities.Remove(city);
    7878          if (newTour.Cities.Count > 0)
Note: See TracChangeset for help on using the changeset viewer.