Changeset 4150 for trunk/sources/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Alba/Crossovers/AlbaPermutationCrossover.cs
- Timestamp:
- 08/04/10 16:11:59 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Alba/Crossovers/AlbaPermutationCrossover.cs
r4068 r4150 28 28 [Item("AlbaPermutationCrossover", "An operator which crosses two alba VRP representations.")] 29 29 [StorableClass] 30 public sealed class AlbaPermutationCrossover : VRPCrossover {30 public sealed class AlbaPermutationCrossover : AlbaCrossover { 31 31 public IValueLookupParameter<IPermutationCrossover> PermutationCrossoverParameter { 32 32 get { return (IValueLookupParameter<IPermutationCrossover>)Parameters["PermutationCrossover"]; } … … 38 38 } 39 39 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; 50 42 51 43 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); 53 46 op.Operator.Execute((IExecutionContext)op); 54 47 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); 58 52 59 53 ChildParameter.ActualValue = new AlbaEncoding(permutation, cities); 60 54 } else 61 55 ChildParameter.ActualValue = null; 62 63 return base.Apply();64 56 } 65 57 }
Note: See TracChangeset
for help on using the changeset viewer.