Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
10/31/13 14:31:42 (11 years ago)
Author:
ascheibe
Message:

#1886 added PermutationPointcut and refactored pointcut code

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.SolutionCaching/3.3/RealVectorEncoding/RealVectorCrossoverPointcut.cs

    r10096 r10101  
    3535  [Item("RealVectorCrossoverPointcut", "Wraps a crossover and applies after-crossover actions.")]
    3636  [StorableClass]
    37   public class RealVectorCrossoverPointcut : SingleSuccessorOperator, IRealVectorCrossover, IStochasticOperator, IRealVectorPointcut {
    38     private const string AdviceParameterName = "Advice";
    39     private const string CrossoversParameterName = "Crossovers";
    40 
    41     public ConstrainedValueParameter<IRealVectorCrossover> CrossoversParameter {
    42       get { return (ConstrainedValueParameter<IRealVectorCrossover>)Parameters[CrossoversParameterName]; }
    43     }
    44     public ConstrainedValueParameter<IRealVectorAdvice> AdviceParameter {
    45       get { return (ConstrainedValueParameter<IRealVectorAdvice>)Parameters[AdviceParameterName]; }
    46     }
     37  public class RealVectorCrossoverPointcut : CrossoverPointcut<IRealVectorAdvice, IRealVectorCrossover>, IRealVectorCrossover, IRealVectorPointcut {
    4738    public ILookupParameter<ItemArray<RealVector>> ParentsParameter {
    4839      get { return (ScopeTreeLookupParameter<RealVector>)Parameters["Parents"]; }
     
    5445      get { return (IValueLookupParameter<DoubleMatrix>)Parameters["Bounds"]; }
    5546    }
    56     public ILookupParameter<IRandom> RandomParameter {
    57       get { return (ILookupParameter<IRandom>)Parameters["Random"]; }
    58     }
    5947
    6048    [StorableConstructor]
     
    6452    public RealVectorCrossoverPointcut()
    6553      : base() {
    66       var cxs = new ConstrainedValueParameter<IRealVectorCrossover>(CrossoversParameterName, "The crossovers.");
     54      Parameters.Add(new ScopeTreeLookupParameter<RealVector>("Parents", "The parent vectors which should be crossed."));
     55      ParentsParameter.ActualName = "RealVector";
     56      Parameters.Add(new LookupParameter<RealVector>("Child", "The child vector resulting from the crossover."));
     57      ChildParameter.ActualName = "RealVector";
     58      Parameters.Add(new ValueLookupParameter<DoubleMatrix>("Bounds", "The lower and upper bounds of the real vector."));
     59
    6760      //Would be nicer if it comes from operator collection, but MultiRealVector Crossover does the same thing.
    6861      //Also: MultiRealVectorCrossover cannot be used here as it would generate a cyclic recursion
     
    7164        if ((!typeof(RealVectorCrossoverPointcut).IsAssignableFrom(t)) &&
    7265          (!typeof(MultiOperator<IRealVectorCrossover>).IsAssignableFrom(t))) {
    73           cxs.ValidValues.Add((IRealVectorCrossover)Activator.CreateInstance(t));
     66          CrossoversParameter.ValidValues.Add((IRealVectorCrossover)Activator.CreateInstance(t));
    7467        }
    7568      }
    76       Parameters.Add(cxs);
    77 
    78       var advices = new ConstrainedValueParameter<IRealVectorAdvice>(AdviceParameterName,
    79         "Advice to introduce after crossover");
    80       foreach (var a in ApplicationManager.Manager.GetInstances<IRealVectorAdvice>()) {
    81         advices.ValidValues.Add(a);
    82       }
    83       Parameters.Add(advices);
    84 
    85       Parameters.Add(new ScopeTreeLookupParameter<RealVector>("Parents", "The parent vectors which should be crossed."));
    86       ParentsParameter.ActualName = "RealVector";
    87       Parameters.Add(new LookupParameter<RealVector>("Child", "The child vector resulting from the crossover."));
    88       ChildParameter.ActualName = "RealVector";
    89       Parameters.Add(new ValueLookupParameter<DoubleMatrix>("Bounds", "The lower and upper bounds of the real vector."));
    90       Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator to use."));
    9169
    9270      ParameterizeCrossovers();
     
    9573    public override IDeepCloneable Clone(Cloner cloner) {
    9674      return new RealVectorCrossoverPointcut(this, cloner);
    97     }
    98 
    99     public override IOperation Apply() {
    100       IOperation successor = base.Apply();
    101       IOperation crossoverOperation = ExecutionContext.CreateChildOperation(CrossoversParameter.Value);
    102       IOperation adviceOperation = ExecutionContext.CreateChildOperation(AdviceParameter.Value);
    103 
    104       var opCol = new OperationCollection();
    105       opCol.Add(crossoverOperation);
    106       opCol.Add(adviceOperation);
    107       if (successor != null)
    108         opCol.Add(successor);
    109 
    110       return opCol;
    11175    }
    11276
Note: See TracChangeset for help on using the changeset viewer.