Changeset 3534 for trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Manipulators
- Timestamp:
- 04/26/10 15:47:10 (15 years ago)
- Location:
- trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Manipulators
- Files:
-
- 1 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Manipulators/MultiSymbolicExpressionTreeManipulator.cs
r3529 r3534 28 28 using HeuristicLab.Parameters; 29 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 30 using HeuristicLab.Data; 31 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Interfaces; 30 32 31 namespace HeuristicLab.Encodings. PermutationEncoding{32 [Item("Multi PermutationCrossover", "Randomly selects and applies one of its crossovers every time it is called.")]33 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Manipulators { 34 [Item("MultiSymbolicExpressionTreeManipulator", "Randomly selects and applies one of its manipulators every time it is called.")] 33 35 [StorableClass] 34 public class MultiPermutationCrossover : StochasticMultiOperator<IPermutationCrossover>, IPermutationCrossover, IStochasticOperator { 36 public class MultiSymbolicExpressionTreeManipulator : StochasticMultiOperator<ISymbolicExpressionTreeManipulator>, ISymbolicExpressionTreeManipulator, IStochasticOperator { 37 private const string MaxTreeSizeParameterName = "MaxTreeSize"; 38 private const string MaxTreeHeightParameterName = "MaxTreeHeight"; 39 private const string SymbolicExpressionGrammarParameterName = "SymbolicExpressionGrammar"; 40 private const string SymbolicExpressionTreeParameterName = "SymbolicExpressionTree"; 41 35 42 public override bool CanChangeName { 36 43 get { return false; } … … 40 47 } 41 48 42 public ILookupParameter<ItemArray<Permutation>> ParentsParameter { 43 get { return (ILookupParameter<ItemArray<Permutation>>)Parameters["Parents"]; } 49 #region ISymbolicExpressionTreeManipulator Members 50 public ILookupParameter<SymbolicExpressionTree> SymbolicExpressionTreeParameter { 51 get { return (ILookupParameter<SymbolicExpressionTree>)Parameters[SymbolicExpressionTreeParameterName]; } 52 } 53 #endregion 54 55 #region ISymbolicExpressionTreeOperator Members 56 public IValueLookupParameter<IntValue> MaxTreeSizeParameter { 57 get { return (IValueLookupParameter<IntValue>)Parameters[MaxTreeSizeParameterName]; } 58 } 59 public IValueLookupParameter<IntValue> MaxTreeHeightParameter { 60 get { return (IValueLookupParameter<IntValue>)Parameters[MaxTreeHeightParameterName]; } 61 } 62 public ILookupParameter<ISymbolicExpressionGrammar> SymbolicExpressionGrammarParameter { 63 get { return (ILookupParameter<ISymbolicExpressionGrammar>)Parameters[SymbolicExpressionGrammarParameterName]; } 64 } 65 #endregion 66 67 68 [StorableConstructor] 69 private MultiSymbolicExpressionTreeManipulator(bool deserializing) : base(deserializing) { } 70 public MultiSymbolicExpressionTreeManipulator() 71 : base() { 72 Parameters.Add(new LookupParameter<SymbolicExpressionTree>(SymbolicExpressionTreeParameterName, "The symbolic expression tree on which the operator should be applied.")); 73 Parameters.Add(new ValueLookupParameter<IntValue>(MaxTreeSizeParameterName, "The maximal size (number of nodes) of the symbolic expression tree.")); 74 Parameters.Add(new ValueLookupParameter<IntValue>(MaxTreeHeightParameterName, "The maximal height of the symbolic expression tree (a tree with one node has height = 0).")); 75 Parameters.Add(new LookupParameter<ISymbolicExpressionGrammar>(SymbolicExpressionGrammarParameterName, "The grammar that defines the allowed symbols and syntax of the symbolic expression trees.")); 76 77 Operators.Add(new FullTreeShaker()); 78 Operators.Add(new OnePointShaker()); 79 Operators.Add(new ChangeNodeTypeManipulation()); 44 80 } 45 81 46 public ILookupParameter<Permutation> ChildParameter { 47 get { return (ILookupParameter<Permutation>)Parameters["Child"]; } 82 protected override void Operators_ItemsReplaced(object sender, CollectionItemsChangedEventArgs<IndexedItem<ISymbolicExpressionTreeManipulator>> e) { 83 base.Operators_ItemsReplaced(sender, e); 84 ParameterizeManipulators(); 48 85 } 49 86 50 [StorableConstructor] 51 private MultiPermutationCrossover(bool deserializing) : base(deserializing) { } 52 public MultiPermutationCrossover() 53 : base() { 54 Parameters.Add(new SubScopesLookupParameter<Permutation>("Parents", "The parent permutations which should be crossed.")); 55 ParentsParameter.ActualName = "Permutation"; 56 Parameters.Add(new LookupParameter<Permutation>("Child", "The child permutation resulting from the crossover.")); 57 ChildParameter.ActualName = "Permutation"; 87 protected override void Operators_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IndexedItem<ISymbolicExpressionTreeManipulator>> e) { 88 base.Operators_ItemsAdded(sender, e); 89 ParameterizeManipulators(); 58 90 } 59 91 60 protected override void Operators_ItemsReplaced(object sender, CollectionItemsChangedEventArgs<IndexedItem<IPermutationCrossover>> e) { 61 base.Operators_ItemsReplaced(sender, e); 62 ParameterizeCrossovers(); 63 } 92 private void ParameterizeManipulators() { 93 foreach (ISymbolicExpressionTreeManipulator manipulator in Operators.OfType<ISymbolicExpressionTreeManipulator>()) { 94 manipulator.MaxTreeSizeParameter.ActualName = MaxTreeSizeParameter.Name; 95 manipulator.MaxTreeHeightParameter.ActualName = MaxTreeHeightParameter.Name; 96 manipulator.SymbolicExpressionGrammarParameter.ActualName = SymbolicExpressionGrammarParameter.Name; 97 manipulator.SymbolicExpressionTreeParameter.ActualName = SymbolicExpressionTreeParameter.Name; 98 } 64 99 65 protected override void Operators_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IndexedItem<IPermutationCrossover>> e) { 66 base.Operators_ItemsAdded(sender, e); 67 ParameterizeCrossovers(); 68 } 69 70 private void ParameterizeCrossovers() { 71 foreach (IPermutationCrossover crossover in Operators.OfType<IPermutationCrossover>()) { 72 crossover.ChildParameter.ActualName = ChildParameter.Name; 73 crossover.ParentsParameter.ActualName = ParentsParameter.Name; 74 } 75 foreach (IStochasticOperator crossover in Operators.OfType<IStochasticOperator>()) { 76 crossover.RandomParameter.ActualName = RandomParameter.Name; 100 foreach (IStochasticOperator manipulator in Operators.OfType<IStochasticOperator>()) { 101 manipulator.RandomParameter.ActualName = RandomParameter.Name; 77 102 } 78 103 } 79 104 80 105 public override IOperation Apply() { 81 if (Operators.Count == 0) throw new InvalidOperationException(Name + ": Please add at least one permutation crossover to choose from.");106 if (Operators.Count == 0) throw new InvalidOperationException(Name + ": Please add at least one symbolic expression tree manipulator to choose from."); 82 107 return base.Apply(); 83 108 } -
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Manipulators/SymbolicExpressionTreeManipulator.cs
r3462 r3534 27 27 using HeuristicLab.Parameters; 28 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 29 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Interfaces; 29 30 30 31 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Manipulators { … … 34 35 [Item("SymbolicExpressionTreeManipulator", "A base class for operators that manipulate symbolic expression trees.")] 35 36 [StorableClass] 36 public abstract class SymbolicExpressionTreeManipulator : SymbolicExpressionTreeOperator, I Manipulator {37 public abstract class SymbolicExpressionTreeManipulator : SymbolicExpressionTreeOperator, ISymbolicExpressionTreeManipulator { 37 38 private const string FailedManipulationEventsParameterName = "FailedManipulationEvents"; 39 private const string SymbolicExpressionTreeParameterName = "SymbolicExpressionTree"; 38 40 39 41 #region Parameter Properties 40 42 public IValueParameter<IntValue> FailedManipulationEventsParameter { 41 43 get { return (IValueParameter<IntValue>)Parameters[FailedManipulationEventsParameterName]; } 44 } 45 public ILookupParameter<SymbolicExpressionTree> SymbolicExpressionTreeParameter { 46 get { return (ILookupParameter<SymbolicExpressionTree>)Parameters[SymbolicExpressionTreeParameterName]; } 42 47 } 43 48 #endregion … … 47 52 get { return FailedManipulationEventsParameter.Value; } 48 53 } 54 public SymbolicExpressionTree SymbolicExpressionTree { 55 get { return SymbolicExpressionTreeParameter.ActualValue; } 56 } 49 57 #endregion 50 58 … … 52 60 : base() { 53 61 Parameters.Add(new ValueParameter<IntValue>(FailedManipulationEventsParameterName, "The number of failed manipulation events.", new IntValue())); 62 Parameters.Add(new LookupParameter<SymbolicExpressionTree>(SymbolicExpressionTreeParameterName, "The symbolic expression tree on which the operator should be applied.")); 54 63 } 55 64
Note: See TracChangeset
for help on using the changeset viewer.