Changeset 10101 for branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.SolutionCaching/3.3/RealVectorEncoding
- Timestamp:
- 10/31/13 14:31:42 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.SolutionCaching/3.3/RealVectorEncoding/RealVectorCrossoverPointcut.cs
r10096 r10101 35 35 [Item("RealVectorCrossoverPointcut", "Wraps a crossover and applies after-crossover actions.")] 36 36 [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 { 47 38 public ILookupParameter<ItemArray<RealVector>> ParentsParameter { 48 39 get { return (ScopeTreeLookupParameter<RealVector>)Parameters["Parents"]; } … … 54 45 get { return (IValueLookupParameter<DoubleMatrix>)Parameters["Bounds"]; } 55 46 } 56 public ILookupParameter<IRandom> RandomParameter {57 get { return (ILookupParameter<IRandom>)Parameters["Random"]; }58 }59 47 60 48 [StorableConstructor] … … 64 52 public RealVectorCrossoverPointcut() 65 53 : 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 67 60 //Would be nicer if it comes from operator collection, but MultiRealVector Crossover does the same thing. 68 61 //Also: MultiRealVectorCrossover cannot be used here as it would generate a cyclic recursion … … 71 64 if ((!typeof(RealVectorCrossoverPointcut).IsAssignableFrom(t)) && 72 65 (!typeof(MultiOperator<IRealVectorCrossover>).IsAssignableFrom(t))) { 73 cxs.ValidValues.Add((IRealVectorCrossover)Activator.CreateInstance(t));66 CrossoversParameter.ValidValues.Add((IRealVectorCrossover)Activator.CreateInstance(t)); 74 67 } 75 68 } 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."));91 69 92 70 ParameterizeCrossovers(); … … 95 73 public override IDeepCloneable Clone(Cloner cloner) { 96 74 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;111 75 } 112 76
Note: See TracChangeset
for help on using the changeset viewer.