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/Encodings/Prins/Crossovers/PrinsPermutationCrossover.cs

    r5445 r6449  
    4646
    4747    protected override PrinsEncoding Crossover(IRandom random, PrinsEncoding parent1, PrinsEncoding parent2) {
    48       //note - the inner crossover is called here and the result is converted to a prins representation
     48      //note - the inner crossover is called here and the solution is converted to a prins representation
    4949      //some refactoring should be done here in the future - the crossover operation should be called directly
    5050
    51       InnerCrossoverParameter.ActualValue.ParentsParameter.ActualName = ParentsParameter.ActualName;
    52       IAtomicOperation op = this.ExecutionContext.CreateOperation(
    53         InnerCrossoverParameter.ActualValue, this.ExecutionContext.Scope);
    54       op.Operator.Execute((IExecutionContext)op, CancellationToken);
     51      if (parent1.Length == parent2.Length) {
     52        InnerCrossoverParameter.ActualValue.ParentsParameter.ActualName = ParentsParameter.ActualName;
     53        IAtomicOperation op = this.ExecutionContext.CreateOperation(
     54          InnerCrossoverParameter.ActualValue, this.ExecutionContext.Scope);
     55        op.Operator.Execute((IExecutionContext)op, CancellationToken);
    5556
    56       string childName = InnerCrossoverParameter.ActualValue.ChildParameter.ActualName;
    57       if (ExecutionContext.Scope.Variables.ContainsKey(childName)) {
    58         Permutation permutation = ExecutionContext.Scope.Variables[childName].Value as Permutation;
    59         ExecutionContext.Scope.Variables.Remove(childName);
     57        string childName = InnerCrossoverParameter.ActualValue.ChildParameter.ActualName;
     58        if (ExecutionContext.Scope.Variables.ContainsKey(childName)) {
     59          Permutation permutation = ExecutionContext.Scope.Variables[childName].Value as Permutation;
     60          ExecutionContext.Scope.Variables.Remove(childName);
    6061
    61         return new PrinsEncoding(permutation, Cities,
    62           DueTimeParameter.ActualValue,
    63             ServiceTimeParameter.ActualValue,
    64             ReadyTimeParameter.ActualValue,
    65             DemandParameter.ActualValue,
    66             CapacityParameter.ActualValue,
    67             FleetUsageFactor.ActualValue,
    68             TimeFactor.ActualValue,
    69             DistanceFactor.ActualValue,
    70             OverloadPenalty.ActualValue,
    71             TardinessPenalty.ActualValue,
    72             CoordinatesParameter.ActualValue,
    73             UseDistanceMatrixParameter.ActualValue);
    74       } else
    75         return null;
     62          return new PrinsEncoding(permutation, Cities,
     63            DueTimeParameter.ActualValue,
     64              ServiceTimeParameter.ActualValue,
     65              ReadyTimeParameter.ActualValue,
     66              DemandParameter.ActualValue,
     67              CapacityParameter.ActualValue,
     68              FleetUsageFactor.ActualValue,
     69              TimeFactor.ActualValue,
     70              DistanceFactor.ActualValue,
     71              OverloadPenalty.ActualValue,
     72              TardinessPenalty.ActualValue,
     73              CoordinatesParameter.ActualValue,
     74              UseDistanceMatrixParameter.ActualValue);
     75        } else
     76          return null;
     77      } else {
     78        return parent1.Clone() as PrinsEncoding;
     79      }
    7680    }
    7781  }
Note: See TracChangeset for help on using the changeset viewer.