Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
08/04/10 16:11:59 (14 years ago)
Author:
svonolfe
Message:

Refactored VRP, added Potvin encoding (WIP) (#1039)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Alba/Crossovers/AlbaPermutationCrossover.cs

    r4068 r4150  
    2828  [Item("AlbaPermutationCrossover", "An operator which crosses two alba VRP representations.")]
    2929  [StorableClass]
    30   public sealed class AlbaPermutationCrossover : VRPCrossover {
     30  public sealed class AlbaPermutationCrossover : AlbaCrossover {
    3131    public IValueLookupParameter<IPermutationCrossover> PermutationCrossoverParameter {
    3232      get { return (IValueLookupParameter<IPermutationCrossover>)Parameters["PermutationCrossover"]; }
     
    3838    }
    3939
    40     public override IOperation Apply() {
    41       int cities = 0;
    42 
    43       for (int i = 0; i < ParentsParameter.ActualValue.Length; i++) {
    44         IVRPEncoding solution = ParentsParameter.ActualValue[i];
    45         cities = solution.Cities;
    46         if (!(solution is AlbaEncoding)) {
    47           ParentsParameter.ActualValue[i] = AlbaEncoding.ConvertFrom(solution);
    48         }
    49       }
     40    protected override void Crossover() {
     41      int cities = ParentsParameter.ActualValue[0].Cities;
    5042
    5143      PermutationCrossoverParameter.ActualValue.ParentsParameter.ActualName = ParentsParameter.ActualName;
    52       IAtomicOperation op = this.ExecutionContext.CreateOperation(PermutationCrossoverParameter.ActualValue);
     44      IAtomicOperation op = this.ExecutionContext.CreateOperation(
     45        PermutationCrossoverParameter.ActualValue, this.ExecutionContext.Scope);
    5346      op.Operator.Execute((IExecutionContext)op);
    5447
    55       if (ExecutionContext.Scope.Variables.ContainsKey("Permutation")) {
    56         Permutation permutation = ExecutionContext.Scope.Variables["Permutation"].Value as Permutation;
    57         ExecutionContext.Scope.Variables.Remove("Permutation");
     48      string childName = PermutationCrossoverParameter.ActualValue.ChildParameter.ActualName;
     49      if (ExecutionContext.Scope.Variables.ContainsKey(childName)) {
     50        Permutation permutation = ExecutionContext.Scope.Variables[childName].Value as Permutation;
     51        ExecutionContext.Scope.Variables.Remove(childName);
    5852
    5953        ChildParameter.ActualValue = new AlbaEncoding(permutation, cities);
    6054      } else
    6155        ChildParameter.ActualValue = null;
    62 
    63       return base.Apply();
    6456    }
    6557  }
Note: See TracChangeset for help on using the changeset viewer.