Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
08/12/10 14:36:13 (14 years ago)
Author:
svonolfe
Message:

Added operations for the Alba encoding (#1039)

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  
    2525using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2626using HeuristicLab.Data;
     27using HeuristicLab.Optimization;
    2728
    2829namespace HeuristicLab.Problems.VehicleRouting.Encodings.Alba {
    2930  [Item("AlbaCrossover", "An operator which crosses two Alba VRP representations.")]
    3031  [StorableClass]
    31   public sealed class AlbaCrossover : VRPCrossover {   
    32     public IValueLookupParameter<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"]; }
    3435    }
    35 
     36   
    3637    [StorableConstructor]
    37     private AlbaCrossover(bool deserializing) : base(deserializing) { }
     38    protected AlbaCrossover(bool deserializing) : base(deserializing) { }
    3839
    3940    public AlbaCrossover()
    4041      : 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   
    4344      AlbaEncoding.RemoveUnusedParameters(Parameters);
    4445    }
    4546
    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);
    6448
    6549    public override IOperation Apply() {
     
    7660      ParentsParameter.ActualValue = parents;
    7761
    78       Crossover();
     62      ChildParameter.ActualValue =
     63        Crossover(RandomParameter.ActualValue, parents[0] as AlbaEncoding, parents[1] as AlbaEncoding);
    7964
    8065      return base.Apply();
Note: See TracChangeset for help on using the changeset viewer.