Changeset 3534
- Timestamp:
- 04/26/10 15:47:10 (15 years ago)
- Location:
- trunk/sources
- Files:
-
- 4 added
- 16 edited
- 1 copied
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/ArchitectureAlteringOperators/ArgumentCreater.cs ¶
r3462 r3534 41 41 [Item("ArgumentCreater", "Manipulates a symbolic expression by creating a new argument within one function-defining branch.")] 42 42 [StorableClass] 43 public sealed class ArgumentCreater : SymbolicExpressionTreeArchitecture AlteringOperator {43 public sealed class ArgumentCreater : SymbolicExpressionTreeArchitectureManipulator { 44 44 public override sealed void ModifyArchitecture( 45 45 IRandom random, -
TabularUnified trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/ArchitectureAlteringOperators/ArgumentDeleter.cs ¶
r3462 r3534 40 40 [Item("ArgumentDeleter", "Manipulates a symbolic expression by deleting an argument from an existing function defining branch.")] 41 41 [StorableClass] 42 public sealed class ArgumentDeleter : SymbolicExpressionTreeArchitecture AlteringOperator {42 public sealed class ArgumentDeleter : SymbolicExpressionTreeArchitectureManipulator { 43 43 public override sealed void ModifyArchitecture( 44 44 IRandom random, -
TabularUnified trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/ArchitectureAlteringOperators/ArgumentDuplicater.cs ¶
r3462 r3534 41 41 [Item("ArgumentDuplicater", "Manipulates a symbolic expression by duplicating an existing argument node of a function-defining branch.")] 42 42 [StorableClass] 43 public sealed class ArgumentDuplicater : SymbolicExpressionTreeArchitecture AlteringOperator {43 public sealed class ArgumentDuplicater : SymbolicExpressionTreeArchitectureManipulator { 44 44 public override sealed void ModifyArchitecture( 45 45 IRandom random, -
TabularUnified trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/ArchitectureAlteringOperators/MultiSymbolicExpressionTreeArchitectureManipulator.cs ¶
r3529 r3534 22 22 using System; 23 23 using System.Linq; 24 using HeuristicLab.Co mmon;24 using HeuristicLab.Collections; 25 25 using HeuristicLab.Core; 26 using HeuristicLab.Data;27 26 using HeuristicLab.Operators; 28 27 using HeuristicLab.Optimization; 29 28 using HeuristicLab.Parameters; 30 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 31 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols; 32 using System.Collections.Generic; 33 using System.Text; 30 using HeuristicLab.Data; 31 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Interfaces; 34 32 35 33 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.ArchitectureAlteringOperators { 36 /// <summary> 37 /// Manipulates a symbolic expression by applying one architecture altering operator randomly. 38 /// </summary> 39 [Item("RandomArchitectureAlteringOperator", "Manipulates a symbolic expression by applying one architecture altering operator randomly.")] 34 [Item("MultiSymbolicExpressionTreeArchitectureManipulator", "Randomly selects and applies one of its architecture manipulators every time it is called.")] 40 35 [StorableClass] 41 public class RandomArchitectureAlteringOperator : SymbolicExpressionTreeArchitectureAlteringOperator { 42 #region Parameter Properties 43 public IValueParameter<ItemList<SymbolicExpressionTreeArchitectureAlteringOperator>> OperatorsParameter { 44 get { return (IValueParameter<ItemList<SymbolicExpressionTreeArchitectureAlteringOperator>>)Parameters["Operators"]; } 36 public class MultiSymbolicExpressionTreeArchitectureManipulator : StochasticMultiOperator<ISymbolicExpressionTreeArchitectureManipulator>, ISymbolicExpressionTreeArchitectureManipulator, 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 private const string MaxFunctionArgumentsParameterName = "MaxFunctionArguments"; 42 private const string MaxFunctionDefiningBranchesParameterName = "MaxFunctionDefiningBranches"; 43 44 public override bool CanChangeName { 45 get { return false; } 45 46 } 46 #endregion 47 #region Properties 48 public ItemList<SymbolicExpressionTreeArchitectureAlteringOperator> Operators { 49 get { return OperatorsParameter.Value; } 47 protected override bool CreateChildOperation { 48 get { return true; } 49 } 50 #region ISymbolicExpressionTreeArchitectureManipulator Members 51 public IValueLookupParameter<IntValue> MaxFunctionDefinitionsParameter { 52 get { return (IValueLookupParameter<IntValue>)Parameters[MaxFunctionDefiningBranchesParameterName]; } 53 } 54 public IValueLookupParameter<IntValue> MaxFunctionArgumentsParameter { 55 get { return (IValueLookupParameter<IntValue>)Parameters[MaxFunctionArgumentsParameterName]; } 50 56 } 51 57 #endregion 52 58 53 public RandomArchitectureAlteringOperator() 59 60 #region ISymbolicExpressionTreeManipulator Members 61 public ILookupParameter<SymbolicExpressionTree> SymbolicExpressionTreeParameter { 62 get { return (ILookupParameter<SymbolicExpressionTree>)Parameters[SymbolicExpressionTreeParameterName]; } 63 } 64 #endregion 65 66 #region ISymbolicExpressionTreeOperator Members 67 public IValueLookupParameter<IntValue> MaxTreeSizeParameter { 68 get { return (IValueLookupParameter<IntValue>)Parameters[MaxTreeSizeParameterName]; } 69 } 70 public IValueLookupParameter<IntValue> MaxTreeHeightParameter { 71 get { return (IValueLookupParameter<IntValue>)Parameters[MaxTreeHeightParameterName]; } 72 } 73 public ILookupParameter<ISymbolicExpressionGrammar> SymbolicExpressionGrammarParameter { 74 get { return (ILookupParameter<ISymbolicExpressionGrammar>)Parameters[SymbolicExpressionGrammarParameterName]; } 75 } 76 #endregion 77 78 79 [StorableConstructor] 80 private MultiSymbolicExpressionTreeArchitectureManipulator(bool deserializing) : base(deserializing) { } 81 public MultiSymbolicExpressionTreeArchitectureManipulator() 54 82 : base() { 55 var operators = new ItemList<SymbolicExpressionTreeArchitectureAlteringOperator>(); 56 operators.Add(new ArgumentCreater()); 57 operators.Add(new ArgumentDeleter()); 58 operators.Add(new ArgumentDuplicater()); 59 operators.Add(new SubroutineCreater()); 60 operators.Add(new SubroutineDeleter()); 61 operators.Add(new SubroutineDuplicater()); 62 Parameters.Add(new ValueParameter<ItemList<SymbolicExpressionTreeArchitectureAlteringOperator>>("Operators", 63 "The list of architecture altering operators from which a random operator should be called.", 64 operators)); 83 Parameters.Add(new LookupParameter<SymbolicExpressionTree>(SymbolicExpressionTreeParameterName, "The symbolic expression tree on which the operator should be applied.")); 84 Parameters.Add(new ValueLookupParameter<IntValue>(MaxFunctionDefiningBranchesParameterName, "The maximal allowed number of function defining branches.")); 85 Parameters.Add(new ValueLookupParameter<IntValue>(MaxFunctionArgumentsParameterName, "The maximal allowed number of arguments of a newly created function.")); 86 Parameters.Add(new ValueLookupParameter<IntValue>(MaxTreeSizeParameterName, "The maximal size (number of nodes) of the symbolic expression tree.")); 87 Parameters.Add(new ValueLookupParameter<IntValue>(MaxTreeHeightParameterName, "The maximal height of the symbolic expression tree (a tree with one node has height = 0).")); 88 Parameters.Add(new LookupParameter<ISymbolicExpressionGrammar>(SymbolicExpressionGrammarParameterName, "The grammar that defines the allowed symbols and syntax of the symbolic expression trees.")); 89 90 Operators.Add(new ArgumentCreater()); 91 Operators.Add(new ArgumentDeleter()); 92 Operators.Add(new ArgumentDuplicater()); 93 Operators.Add(new SubroutineCreater()); 94 Operators.Add(new SubroutineDeleter()); 95 Operators.Add(new SubroutineDuplicater()); 65 96 } 66 97 67 p ublic override void ModifyArchitecture(IRandom random, SymbolicExpressionTree tree, ISymbolicExpressionGrammar grammar, IntValue maxTreeSize, IntValue maxTreeHeight, IntValue maxFunctionDefiningBranches, IntValue maxFunctionArguments, out bool success) {68 var selectedOperator = Operators.SelectRandom(random);69 selectedOperator.ModifyArchitecture(random, tree, grammar, maxTreeSize, maxTreeHeight, maxFunctionDefiningBranches, maxFunctionArguments, out success);98 protected override void Operators_ItemsReplaced(object sender, CollectionItemsChangedEventArgs<IndexedItem<ISymbolicExpressionTreeArchitectureManipulator>> e) { 99 base.Operators_ItemsReplaced(sender, e); 100 ParameterizeManipulators(); 70 101 } 102 103 protected override void Operators_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IndexedItem<ISymbolicExpressionTreeArchitectureManipulator>> e) { 104 base.Operators_ItemsAdded(sender, e); 105 ParameterizeManipulators(); 106 } 107 108 private void ParameterizeManipulators() { 109 foreach (ISymbolicExpressionTreeArchitectureManipulator manipulator in Operators.OfType<ISymbolicExpressionTreeArchitectureManipulator>()) { 110 manipulator.MaxTreeSizeParameter.ActualName = MaxTreeSizeParameter.Name; 111 manipulator.MaxTreeHeightParameter.ActualName = MaxTreeHeightParameter.Name; 112 manipulator.SymbolicExpressionGrammarParameter.ActualName = SymbolicExpressionGrammarParameter.Name; 113 manipulator.SymbolicExpressionTreeParameter.ActualName = SymbolicExpressionTreeParameter.Name; 114 manipulator.MaxFunctionDefinitionsParameter.ActualName = MaxFunctionArgumentsParameter.Name; 115 manipulator.MaxFunctionArgumentsParameter.ActualName = MaxFunctionArgumentsParameter.Name; 116 } 117 118 foreach (IStochasticOperator manipulator in Operators.OfType<IStochasticOperator>()) { 119 manipulator.RandomParameter.ActualName = RandomParameter.Name; 120 } 121 } 122 123 public override IOperation Apply() { 124 if (Operators.Count == 0) throw new InvalidOperationException(Name + ": Please add at least one symbolic expression tree architecture manipulator to choose from."); 125 return base.Apply(); 126 } 127 128 #region ISymbolicExpressionTreeArchitectureManipulator Members 129 public void ModifyArchitecture(IRandom random, SymbolicExpressionTree symbolicExpressionTree, ISymbolicExpressionGrammar grammar, IntValue maxTreeSize, IntValue maxTreeHeight, IntValue maxFunctionDefiningBranches, IntValue maxFunctionArguments, out bool success) { 130 var op = Operators.SelectRandom(random); 131 op.ModifyArchitecture(random, symbolicExpressionTree, grammar, maxTreeSize, maxTreeHeight, maxFunctionDefiningBranches, maxFunctionArguments, out success); 132 } 133 #endregion 71 134 } 72 135 } -
TabularUnified trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/ArchitectureAlteringOperators/SubroutineCreater.cs ¶
r3462 r3534 42 42 [Item("SubroutineCreater", "Manipulates a symbolic expression by adding one new function-defining branch containing a proportion of a preexisting branch and by creating a reference to the new branch.")] 43 43 [StorableClass] 44 public sealed class SubroutineCreater : SymbolicExpressionTreeArchitecture AlteringOperator {44 public sealed class SubroutineCreater : SymbolicExpressionTreeArchitectureManipulator { 45 45 private const double ARGUMENT_CUTOFF_PROBABILITY = 0.05; 46 46 -
TabularUnified trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/ArchitectureAlteringOperators/SubroutineDeleter.cs ¶
r3462 r3534 42 42 [Item("SubroutineDeleter", "Manipulates a symbolic expression by deleting a preexisting function-defining branch.")] 43 43 [StorableClass] 44 public sealed class SubroutineDeleter : SymbolicExpressionTreeArchitecture AlteringOperator {44 public sealed class SubroutineDeleter : SymbolicExpressionTreeArchitectureManipulator { 45 45 public override sealed void ModifyArchitecture( 46 46 IRandom random, -
TabularUnified trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/ArchitectureAlteringOperators/SubroutineDuplicater.cs ¶
r3462 r3534 41 41 [Item("SubroutineDuplicater", "Manipulates a symbolic expression by duplicating a preexisting function-defining branch.")] 42 42 [StorableClass] 43 public sealed class SubroutineDuplicater : SymbolicExpressionTreeArchitecture AlteringOperator {43 public sealed class SubroutineDuplicater : SymbolicExpressionTreeArchitectureManipulator { 44 44 public override sealed void ModifyArchitecture( 45 45 IRandom random, -
TabularUnified trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/ArchitectureAlteringOperators/SymbolicExpressionTreeArchitectureAlteringOperator.cs ¶
r3462 r3534 33 33 using System.Text; 34 34 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Manipulators; 35 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Interfaces; 35 36 36 37 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.ArchitectureAlteringOperators { … … 39 40 /// </summary> 40 41 [StorableClass] 41 public abstract class SymbolicExpressionTreeArchitecture AlteringOperator : SymbolicExpressionTreeManipulator {42 public abstract class SymbolicExpressionTreeArchitectureManipulator : SymbolicExpressionTreeManipulator, ISymbolicExpressionTreeArchitectureManipulator { 42 43 private const string MaxFunctionArgumentsParameterName = "MaxFunctionArguments"; 43 44 private const string MaxFunctionDefiningBranchesParameterName = "MaxFunctionDefiningBranches"; … … 46 47 } 47 48 48 public IValueLookupParameter<IntValue> MaxFunctionDefini ngBranchesParameter {49 public IValueLookupParameter<IntValue> MaxFunctionDefinitionsParameter { 49 50 get { return (IValueLookupParameter<IntValue>)Parameters[MaxFunctionDefiningBranchesParameterName]; } 50 51 } … … 53 54 } 54 55 public IntValue MaxFunctionDefiningBranches { 55 get { return MaxFunctionDefini ngBranchesParameter.ActualValue; }56 get { return MaxFunctionDefinitionsParameter.ActualValue; } 56 57 } 57 58 public IntValue MaxFunctionArguments { 58 59 get { return MaxFunctionArgumentsParameter.ActualValue; } 59 60 } 60 public SymbolicExpressionTreeArchitecture AlteringOperator()61 public SymbolicExpressionTreeArchitectureManipulator() 61 62 : base() { 62 63 Parameters.Add(new ValueLookupParameter<IntValue>(MaxFunctionDefiningBranchesParameterName, "The maximal allowed number of function defining branches.")); … … 74 75 IntValue maxTreeSize, 75 76 IntValue maxTreeHeight, 76 IntValue maxFunctionDefini ngBranches,77 IntValue maxFunctionDefinitions, 77 78 IntValue maxFunctionArguments, 78 79 out bool success -
TabularUnified trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Creators/SymbolicExpressionTreeCreator.cs ¶
r3462 r3534 28 28 using HeuristicLab.Parameters; 29 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 30 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Interfaces; 30 31 31 32 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Creators { … … 35 36 [Item("SymbolicExpressionTreeCreator", "A base class for operators creating symbolic expression trees.")] 36 37 [StorableClass] 37 public abstract class SymbolicExpressionTreeCreator : SymbolicExpressionTreeOperator, IS olutionCreator {38 public abstract class SymbolicExpressionTreeCreator : SymbolicExpressionTreeOperator, ISymbolicExpressionTreeCreator { 38 39 private const string MaxFunctionDefinitionsParameterName = "MaxFunctionDefinitions"; 39 40 private const string MaxFunctionArgumentsParameterName = "MaxFunctionArguments"; 41 private const string SymbolicExpressionTreeParameterName = "SymbolicExpressionTree"; 40 42 #region Parameter Properties 41 43 public IValueLookupParameter<IntValue> MaxFunctionDefinitionsParameter { … … 44 46 public IValueLookupParameter<IntValue> MaxFunctionArgumentsParameter { 45 47 get { return (IValueLookupParameter<IntValue>)Parameters[MaxFunctionArgumentsParameterName]; } 48 } 49 public ILookupParameter<SymbolicExpressionTree> SymbolicExpressionTreeParameter { 50 get { return (ILookupParameter<SymbolicExpressionTree>)Parameters[SymbolicExpressionTreeParameterName]; } 46 51 } 47 52 #endregion … … 54 59 get { return MaxFunctionArgumentsParameter.ActualValue; } 55 60 } 61 public SymbolicExpressionTree SymbolicExpressionTree { 62 get { return SymbolicExpressionTreeParameter.ActualValue; } 63 set { SymbolicExpressionTreeParameter.ActualValue = value; } 64 } 56 65 57 66 #endregion … … 60 69 Parameters.Add(new ValueLookupParameter<IntValue>(MaxFunctionDefinitionsParameterName, "Maximal number of function definitions in the symbolic expression tree.")); 61 70 Parameters.Add(new ValueLookupParameter<IntValue>(MaxFunctionArgumentsParameterName, "Maximal number of arguments of automatically defined functions in the symbolic expression tree.")); 71 Parameters.Add(new LookupParameter<SymbolicExpressionTree>(SymbolicExpressionTreeParameterName, "The symbolic expression tree that should be created.")); 62 72 } 63 73 64 74 public sealed override IOperation Apply() { 65 SymbolicExpressionTree Parameter.ActualValue= Create(Random, SymbolicExpressionGrammar,75 SymbolicExpressionTree = Create(Random, SymbolicExpressionGrammar, 66 76 MaxTreeSize, MaxTreeHeight, MaxFunctionDefinitions, MaxFunctionArguments); 67 77 return null; -
TabularUnified trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Crossovers/SymbolicExpressionTreeCrossover.cs ¶
r3462 r3534 29 29 using System; 30 30 using System.Diagnostics; 31 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Interfaces; 31 32 32 33 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Crossovers { … … 36 37 [Item("SymbolicExpressionTreeCrossover", "A base class for operators that perform a crossover of symbolic expression trees.")] 37 38 [StorableClass] 38 public abstract class SymbolicExpressionTreeCrossover : SymbolicExpressionTreeOperator, I Crossover {39 public abstract class SymbolicExpressionTreeCrossover : SymbolicExpressionTreeOperator, ISymbolicExpressionTreeCrossover { 39 40 private const string ParentsParameterName = "Parents"; 40 41 private const string ChildParameterName = "Child"; -
TabularUnified trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.3.csproj ¶
r3512 r3534 87 87 <Compile Include="ArchitectureAlteringOperators\ArgumentDuplicater.cs" /> 88 88 <Compile Include="ArchitectureAlteringOperators\GrammarModifier.cs" /> 89 <Compile Include="ArchitectureAlteringOperators\ RandomArchitectureAlteringOperator.cs" />89 <Compile Include="ArchitectureAlteringOperators\MultiSymbolicExpressionTreeArchitectureManipulator.cs" /> 90 90 <Compile Include="ArchitectureAlteringOperators\SubroutineCreater.cs"> 91 91 <SubType>Code</SubType> … … 98 98 <Compile Include="Creators\SymbolicExpressionTreeCreator.cs" /> 99 99 <Compile Include="Crossovers\SymbolicExpressionTreeCrossover.cs" /> 100 <Compile Include="Interfaces\ISymbolicExpressionTreeArchitectureManipulator.cs" /> 101 <Compile Include="Interfaces\ISymbolicExpressionTreeCreator.cs" /> 102 <Compile Include="Interfaces\ISymbolicExpressionTreeCrossover.cs" /> 100 103 <Compile Include="Manipulators\ChangeNodeTypeManipulation.cs" /> 104 <Compile Include="Interfaces\ISymbolicExpressionTreeManipulator.cs" /> 101 105 <Compile Include="Manipulators\FullTreeShaker.cs" /> 106 <Compile Include="Manipulators\MultiSymbolicExpressionTreeManipulator.cs" /> 102 107 <Compile Include="Manipulators\OnePointShaker.cs" /> 103 108 <Compile Include="Manipulators\SymbolicExpressionTreeManipulator.cs" /> -
TabularUnified trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Interfaces/ISymbolicExpressionTreeOperator.cs ¶
r3376 r3534 30 30 using System.Diagnostics; 31 31 32 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {32 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Interfaces { 33 33 /// <summary> 34 34 /// Interface for operators that can be applied to symbolic expression trees. -
TabularUnified 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 } -
TabularUnified 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 -
TabularUnified trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/SymbolicExpressionTreeOperator.cs ¶
r3376 r3534 28 28 using HeuristicLab.Parameters; 29 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 30 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Interfaces; 30 31 31 32 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding { … … 37 38 public abstract class SymbolicExpressionTreeOperator : SingleSuccessorOperator, IStochasticOperator, ISymbolicExpressionTreeOperator { 38 39 private const string RandomParameterName = "Random"; 39 private const string SymbolicExpressionTreeParameterName = "SymbolicExpressionTree";40 40 private const string MaxTreeSizeParameterName = "MaxTreeSize"; 41 41 private const string MaxTreeHeightParameterName = "MaxTreeHeight"; … … 49 49 public ILookupParameter<IRandom> RandomParameter { 50 50 get { return (LookupParameter<IRandom>)Parameters[RandomParameterName]; } 51 }52 public ILookupParameter<SymbolicExpressionTree> SymbolicExpressionTreeParameter {53 get { return (ILookupParameter<SymbolicExpressionTree>)Parameters[SymbolicExpressionTreeParameterName]; }54 51 } 55 52 public IValueLookupParameter<IntValue> MaxTreeSizeParameter { … … 68 65 get { return RandomParameter.ActualValue; } 69 66 } 70 public SymbolicExpressionTree SymbolicExpressionTree {71 get { return SymbolicExpressionTreeParameter.ActualValue; }72 }73 67 public IntValue MaxTreeSize { 74 68 get { return MaxTreeSizeParameter.ActualValue; } … … 85 79 : base() { 86 80 Parameters.Add(new LookupParameter<IRandom>(RandomParameterName, "The pseudo random number generator which should be used for symbolic expression tree operators.")); 87 Parameters.Add(new LookupParameter<SymbolicExpressionTree>(SymbolicExpressionTreeParameterName, "The symbolic expression tree on which the operator should be applied."));88 81 Parameters.Add(new ValueLookupParameter<IntValue>(MaxTreeSizeParameterName, "The maximal size (number of nodes) of the symbolic expression tree.")); 89 82 Parameters.Add(new ValueLookupParameter<IntValue>(MaxTreeHeightParameterName, "The maximal height of the symbolic expression tree (a tree with one node has height = 0).")); -
TabularUnified trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Tests/AllArchitectureAlteringOperatorsTest.cs ¶
r3462 r3534 32 32 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Creators; 33 33 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Crossovers; 34 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Manipulators; 34 35 35 36 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding_3._3.Tests { … … 73 74 Stopwatch stopwatch = new Stopwatch(); 74 75 stopwatch.Start(); 75 var combinedAAOperator = new RandomArchitectureAlteringOperator();76 var combinedAAOperator = new MultiSymbolicExpressionTreeArchitectureManipulator(); 76 77 for (int g = 0; g < N_ITERATIONS; g++) { 77 78 for (int i = 0; i < POPULATION_SIZE; i++) { … … 80 81 var selectedTree = (SymbolicExpressionTree)trees.SelectRandom(random).Clone(); 81 82 var op = combinedAAOperator.Operators.SelectRandom(random); 82 bool success ;83 bool success = false; 83 84 op.ModifyArchitecture(random, selectedTree, grammar, maxTreeSize, maxTreeHeigth, maxDefuns, maxArgs, out success); 84 85 if (!success) failedEvents++; -
TabularUnified trunk/sources/HeuristicLab.Problems.ArtificialAnt/3.3/ArtificialAntProblem.cs ¶
r3528 r3534 36 36 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Manipulators; 37 37 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.ArchitectureAlteringOperators; 38 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Interfaces; 38 39 39 40 namespace HeuristicLab.Problems.ArtificialAnt { … … 368 369 op.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName; 369 370 } 370 foreach ( SymbolicExpressionTreeArchitectureAlteringOperator op in Operators.OfType<SymbolicExpressionTreeArchitectureAlteringOperator>()) {371 op.MaxFunctionDefini ngBranchesParameter.ActualName = MaxFunctionDefinitionsParameter.Name;371 foreach (ISymbolicExpressionTreeArchitectureManipulator op in Operators.OfType<ISymbolicExpressionTreeArchitectureManipulator>()) { 372 op.MaxFunctionDefinitionsParameter.ActualName = MaxFunctionDefinitionsParameter.Name; 372 373 op.MaxFunctionArgumentsParameter.ActualName = MaxFunctionArgumentsParameter.Name; 373 374 } -
TabularUnified trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/SymbolicRegressionProblem.cs ¶
r3532 r3534 38 38 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Crossovers; 39 39 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Creators; 40 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Interfaces; 40 41 41 42 namespace HeuristicLab.Problems.DataAnalysis.Regression.Symbolic { … … 194 195 195 196 creator.SymbolicExpressionTreeParameter.ActualName = "SymbolicRegressionModel"; 196 creator.MaxFunctionArgumentsParameter.ActualName = "MaxFunctionArguments";197 creator.MaxFunctionDefinitionsParameter.ActualName = "MaxFunctionDefiningBranches";197 creator.MaxFunctionArgumentsParameter.ActualName = MaxFunctionArgumentsParameter.Name; 198 creator.MaxFunctionDefinitionsParameter.ActualName = MaxFunctionDefiningBranchesParameter.Name; 198 199 DataAnalysisProblemDataParameter.ValueChanged += new EventHandler(DataAnalysisProblemDataParameter_ValueChanged); 199 200 DataAnalysisProblemData.ProblemDataChanged += new EventHandler(DataAnalysisProblemData_Changed); … … 373 374 op.RegressionProblemDataParameter.ActualName = DataAnalysisProblemDataParameter.Name; 374 375 } 375 foreach ( SymbolicExpressionTreeCrossover op in Operators.OfType<SymbolicExpressionTreeCrossover>()) {376 foreach (ISymbolicExpressionTreeCrossover op in Operators.OfType<ISymbolicExpressionTreeCrossover>()) { 376 377 op.ParentsParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName; 377 378 op.ChildParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName; 378 379 } 379 foreach ( SymbolicExpressionTreeManipulator op in Operators.OfType<SymbolicExpressionTreeManipulator>()) {380 foreach (ISymbolicExpressionTreeManipulator op in Operators.OfType<ISymbolicExpressionTreeManipulator>()) { 380 381 op.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName; 381 382 } 382 foreach (SymbolicExpressionTreeArchitectureAlteringOperator op in Operators.OfType<SymbolicExpressionTreeArchitectureAlteringOperator>()) { 383 foreach (ISymbolicExpressionTreeArchitectureManipulator op in Operators.OfType<ISymbolicExpressionTreeArchitectureManipulator>()) { 384 op.MaxFunctionArgumentsParameter.ActualName = MaxFunctionArgumentsParameter.Name; 385 op.MaxFunctionDefinitionsParameter.ActualName = MaxFunctionDefiningBranchesParameter.Name; 383 386 } 384 387 }
Note: See TracChangeset
for help on using the changeset viewer.