- Timestamp:
- 08/12/10 14:36:13 (14 years ago)
- Location:
- trunk/sources/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Alba/Crossovers
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Alba/Crossovers/AlbaCrossover.cs
r4179 r4204 25 25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 26 26 using HeuristicLab.Data; 27 using HeuristicLab.Optimization; 27 28 28 29 namespace HeuristicLab.Problems.VehicleRouting.Encodings.Alba { 29 30 [Item("AlbaCrossover", "An operator which crosses two Alba VRP representations.")] 30 31 [StorableClass] 31 public sealed class AlbaCrossover : VRPCrossover {32 public I ValueLookupParameter<IPermutationCrossover> InnerCrossoverParameter {33 get { return ( IValueLookupParameter<IPermutationCrossover>)Parameters["InnerCrossover"]; }32 public abstract class AlbaCrossover : VRPCrossover, IStochasticOperator { 33 public ILookupParameter<IRandom> RandomParameter { 34 get { return (LookupParameter<IRandom>)Parameters["Random"]; } 34 35 } 35 36 36 37 [StorableConstructor] 37 pr ivateAlbaCrossover(bool deserializing) : base(deserializing) { }38 protected AlbaCrossover(bool deserializing) : base(deserializing) { } 38 39 39 40 public AlbaCrossover() 40 41 : base() { 41 Parameters.Add(new ValueLookupParameter<IPermutationCrossover>("InnerCrossover", "The permutation crossover.", new EdgeRecombinationCrossover()));42 42 Parameters.Add(new LookupParameter<IRandom>("Random", "The pseudo random number generator which should be used for stochastic manipulation operators.")); 43 43 44 AlbaEncoding.RemoveUnusedParameters(Parameters); 44 45 } 45 46 46 private void Crossover() { 47 //note - the inner crossover is called here and the result is converted to an alba representation 48 //some refactoring should be done here in the future - the crossover operation should be called directly 49 50 InnerCrossoverParameter.ActualValue.ParentsParameter.ActualName = ParentsParameter.ActualName; 51 IAtomicOperation op = this.ExecutionContext.CreateOperation( 52 InnerCrossoverParameter.ActualValue, this.ExecutionContext.Scope); 53 op.Operator.Execute((IExecutionContext)op); 54 55 string childName = InnerCrossoverParameter.ActualValue.ChildParameter.ActualName; 56 if (ExecutionContext.Scope.Variables.ContainsKey(childName)) { 57 Permutation permutation = ExecutionContext.Scope.Variables[childName].Value as Permutation; 58 ExecutionContext.Scope.Variables.Remove(childName); 59 60 ChildParameter.ActualValue = new AlbaEncoding(permutation, Cities); 61 } else 62 ChildParameter.ActualValue = null; 63 } 47 protected abstract AlbaEncoding Crossover(IRandom random, AlbaEncoding parent1, AlbaEncoding parent2); 64 48 65 49 public override IOperation Apply() { … … 76 60 ParentsParameter.ActualValue = parents; 77 61 78 Crossover(); 62 ChildParameter.ActualValue = 63 Crossover(RandomParameter.ActualValue, parents[0] as AlbaEncoding, parents[1] as AlbaEncoding); 79 64 80 65 return base.Apply();
Note: See TracChangeset
for help on using the changeset viewer.