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/Alba/Crossovers/AlbaPermutationCrossover.cs

    r5445 r6449  
    4848
    4949    protected override AlbaEncoding Crossover(IRandom random, AlbaEncoding parent1, AlbaEncoding parent2) {
    50       //note - the inner crossover is called here and the result is converted to an alba representation
     50      //note - the inner crossover is called here and the solution is converted to an alba 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 AlbaEncoding(permutation, Cities);
    64       } else
    65         return null;
     64          return new AlbaEncoding(permutation, Cities);
     65        } else
     66          return null;
     67      } else {
     68        return parent1.Clone() as AlbaEncoding;
     69      }
    6670    }
    6771  }
Note: See TracChangeset for help on using the changeset viewer.