Changeset 3534


Ignore:
Timestamp:
04/26/10 15:47:10 (12 years ago)
Author:
gkronber
Message:

Added interfaces for symbolic expression tree operators and added multi manipulation operators. #937 (Data types and operators for symbolic expression tree encoding)

Location:
trunk/sources
Files:
4 added
16 edited
1 copied
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/ArchitectureAlteringOperators/ArgumentCreater.cs

    r3462 r3534  
    4141  [Item("ArgumentCreater", "Manipulates a symbolic expression by creating a new argument within one function-defining branch.")]
    4242  [StorableClass]
    43   public sealed class ArgumentCreater : SymbolicExpressionTreeArchitectureAlteringOperator {
     43  public sealed class ArgumentCreater : SymbolicExpressionTreeArchitectureManipulator {
    4444    public override sealed void ModifyArchitecture(
    4545      IRandom random,
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/ArchitectureAlteringOperators/ArgumentDeleter.cs

    r3462 r3534  
    4040  [Item("ArgumentDeleter", "Manipulates a symbolic expression by deleting an argument from an existing function defining branch.")]
    4141  [StorableClass]
    42   public sealed class ArgumentDeleter : SymbolicExpressionTreeArchitectureAlteringOperator {
     42  public sealed class ArgumentDeleter : SymbolicExpressionTreeArchitectureManipulator {
    4343    public override sealed void ModifyArchitecture(
    4444      IRandom random,
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/ArchitectureAlteringOperators/ArgumentDuplicater.cs

    r3462 r3534  
    4141  [Item("ArgumentDuplicater", "Manipulates a symbolic expression by duplicating an existing argument node of a function-defining branch.")]
    4242  [StorableClass]
    43   public sealed class ArgumentDuplicater : SymbolicExpressionTreeArchitectureAlteringOperator {
     43  public sealed class ArgumentDuplicater : SymbolicExpressionTreeArchitectureManipulator {
    4444    public override sealed void ModifyArchitecture(
    4545      IRandom random,
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/ArchitectureAlteringOperators/MultiSymbolicExpressionTreeArchitectureManipulator.cs

    r3529 r3534  
    2222using System;
    2323using System.Linq;
    24 using HeuristicLab.Common;
     24using HeuristicLab.Collections;
    2525using HeuristicLab.Core;
    26 using HeuristicLab.Data;
    2726using HeuristicLab.Operators;
    2827using HeuristicLab.Optimization;
    2928using HeuristicLab.Parameters;
    3029using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    31 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols;
    32 using System.Collections.Generic;
    33 using System.Text;
     30using HeuristicLab.Data;
     31using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Interfaces;
    3432
    3533namespace 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.")]
    4035  [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; }
    4546    }
    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]; }
    5056    }
    5157    #endregion
    5258
    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()
    5482      : 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());
    6596    }
    6697
    67     public 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();
    70101    }
     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
    71134  }
    72135}
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/ArchitectureAlteringOperators/SubroutineCreater.cs

    r3462 r3534  
    4242  [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.")]
    4343  [StorableClass]
    44   public sealed class SubroutineCreater : SymbolicExpressionTreeArchitectureAlteringOperator {
     44  public sealed class SubroutineCreater : SymbolicExpressionTreeArchitectureManipulator {
    4545    private const double ARGUMENT_CUTOFF_PROBABILITY = 0.05;
    4646
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/ArchitectureAlteringOperators/SubroutineDeleter.cs

    r3462 r3534  
    4242  [Item("SubroutineDeleter", "Manipulates a symbolic expression by deleting a preexisting function-defining branch.")]
    4343  [StorableClass]
    44   public sealed class SubroutineDeleter : SymbolicExpressionTreeArchitectureAlteringOperator {
     44  public sealed class SubroutineDeleter : SymbolicExpressionTreeArchitectureManipulator {
    4545    public override sealed void ModifyArchitecture(
    4646      IRandom random,
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/ArchitectureAlteringOperators/SubroutineDuplicater.cs

    r3462 r3534  
    4141  [Item("SubroutineDuplicater", "Manipulates a symbolic expression by duplicating a preexisting function-defining branch.")]
    4242  [StorableClass]
    43   public sealed class SubroutineDuplicater : SymbolicExpressionTreeArchitectureAlteringOperator {
     43  public sealed class SubroutineDuplicater : SymbolicExpressionTreeArchitectureManipulator {
    4444    public override sealed void ModifyArchitecture(
    4545      IRandom random,
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/ArchitectureAlteringOperators/SymbolicExpressionTreeArchitectureAlteringOperator.cs

    r3462 r3534  
    3333using System.Text;
    3434using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Manipulators;
     35using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Interfaces;
    3536
    3637namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.ArchitectureAlteringOperators {
     
    3940  /// </summary>
    4041  [StorableClass]
    41   public abstract class SymbolicExpressionTreeArchitectureAlteringOperator : SymbolicExpressionTreeManipulator {
     42  public abstract class SymbolicExpressionTreeArchitectureManipulator : SymbolicExpressionTreeManipulator, ISymbolicExpressionTreeArchitectureManipulator {
    4243    private const string MaxFunctionArgumentsParameterName = "MaxFunctionArguments";
    4344    private const string MaxFunctionDefiningBranchesParameterName = "MaxFunctionDefiningBranches";
     
    4647    }
    4748
    48     public IValueLookupParameter<IntValue> MaxFunctionDefiningBranchesParameter {
     49    public IValueLookupParameter<IntValue> MaxFunctionDefinitionsParameter {
    4950      get { return (IValueLookupParameter<IntValue>)Parameters[MaxFunctionDefiningBranchesParameterName]; }
    5051    }
     
    5354    }
    5455    public IntValue MaxFunctionDefiningBranches {
    55       get { return MaxFunctionDefiningBranchesParameter.ActualValue; }
     56      get { return MaxFunctionDefinitionsParameter.ActualValue; }
    5657    }
    5758    public IntValue MaxFunctionArguments {
    5859      get { return MaxFunctionArgumentsParameter.ActualValue; }
    5960    }
    60     public SymbolicExpressionTreeArchitectureAlteringOperator()
     61    public SymbolicExpressionTreeArchitectureManipulator()
    6162      : base() {
    6263      Parameters.Add(new ValueLookupParameter<IntValue>(MaxFunctionDefiningBranchesParameterName, "The maximal allowed number of function defining branches."));
     
    7475      IntValue maxTreeSize,
    7576      IntValue maxTreeHeight,
    76       IntValue maxFunctionDefiningBranches,
     77      IntValue maxFunctionDefinitions,
    7778      IntValue maxFunctionArguments,
    7879      out bool success
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Creators/SymbolicExpressionTreeCreator.cs

    r3462 r3534  
    2828using HeuristicLab.Parameters;
    2929using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     30using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Interfaces;
    3031
    3132namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Creators {
     
    3536  [Item("SymbolicExpressionTreeCreator", "A base class for operators creating symbolic expression trees.")]
    3637  [StorableClass]
    37   public abstract class SymbolicExpressionTreeCreator : SymbolicExpressionTreeOperator, ISolutionCreator {
     38  public abstract class SymbolicExpressionTreeCreator : SymbolicExpressionTreeOperator, ISymbolicExpressionTreeCreator {
    3839    private const string MaxFunctionDefinitionsParameterName = "MaxFunctionDefinitions";
    3940    private const string MaxFunctionArgumentsParameterName = "MaxFunctionArguments";
     41    private const string SymbolicExpressionTreeParameterName = "SymbolicExpressionTree";
    4042    #region Parameter Properties
    4143    public IValueLookupParameter<IntValue> MaxFunctionDefinitionsParameter {
     
    4446    public IValueLookupParameter<IntValue> MaxFunctionArgumentsParameter {
    4547      get { return (IValueLookupParameter<IntValue>)Parameters[MaxFunctionArgumentsParameterName]; }
     48    }
     49    public ILookupParameter<SymbolicExpressionTree> SymbolicExpressionTreeParameter {
     50      get { return (ILookupParameter<SymbolicExpressionTree>)Parameters[SymbolicExpressionTreeParameterName]; }
    4651    }
    4752    #endregion
     
    5459      get { return MaxFunctionArgumentsParameter.ActualValue; }
    5560    }
     61    public SymbolicExpressionTree SymbolicExpressionTree {
     62      get { return SymbolicExpressionTreeParameter.ActualValue; }
     63      set { SymbolicExpressionTreeParameter.ActualValue = value; }
     64    }
    5665
    5766    #endregion
     
    6069      Parameters.Add(new ValueLookupParameter<IntValue>(MaxFunctionDefinitionsParameterName, "Maximal number of function definitions in the symbolic expression tree."));
    6170      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."));
    6272    }
    6373
    6474    public sealed override IOperation Apply() {
    65       SymbolicExpressionTreeParameter.ActualValue = Create(Random, SymbolicExpressionGrammar,
     75      SymbolicExpressionTree = Create(Random, SymbolicExpressionGrammar,
    6676        MaxTreeSize, MaxTreeHeight, MaxFunctionDefinitions, MaxFunctionArguments);
    6777      return null;
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Crossovers/SymbolicExpressionTreeCrossover.cs

    r3462 r3534  
    2929using System;
    3030using System.Diagnostics;
     31using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Interfaces;
    3132
    3233namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Crossovers {
     
    3637  [Item("SymbolicExpressionTreeCrossover", "A base class for operators that perform a crossover of symbolic expression trees.")]
    3738  [StorableClass]
    38   public abstract class SymbolicExpressionTreeCrossover : SymbolicExpressionTreeOperator, ICrossover {
     39  public abstract class SymbolicExpressionTreeCrossover : SymbolicExpressionTreeOperator, ISymbolicExpressionTreeCrossover {
    3940    private const string ParentsParameterName = "Parents";
    4041    private const string ChildParameterName = "Child";
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.3.csproj

    r3512 r3534  
    8787    <Compile Include="ArchitectureAlteringOperators\ArgumentDuplicater.cs" />
    8888    <Compile Include="ArchitectureAlteringOperators\GrammarModifier.cs" />
    89     <Compile Include="ArchitectureAlteringOperators\RandomArchitectureAlteringOperator.cs" />
     89    <Compile Include="ArchitectureAlteringOperators\MultiSymbolicExpressionTreeArchitectureManipulator.cs" />
    9090    <Compile Include="ArchitectureAlteringOperators\SubroutineCreater.cs">
    9191      <SubType>Code</SubType>
     
    9898    <Compile Include="Creators\SymbolicExpressionTreeCreator.cs" />
    9999    <Compile Include="Crossovers\SymbolicExpressionTreeCrossover.cs" />
     100    <Compile Include="Interfaces\ISymbolicExpressionTreeArchitectureManipulator.cs" />
     101    <Compile Include="Interfaces\ISymbolicExpressionTreeCreator.cs" />
     102    <Compile Include="Interfaces\ISymbolicExpressionTreeCrossover.cs" />
    100103    <Compile Include="Manipulators\ChangeNodeTypeManipulation.cs" />
     104    <Compile Include="Interfaces\ISymbolicExpressionTreeManipulator.cs" />
    101105    <Compile Include="Manipulators\FullTreeShaker.cs" />
     106    <Compile Include="Manipulators\MultiSymbolicExpressionTreeManipulator.cs" />
    102107    <Compile Include="Manipulators\OnePointShaker.cs" />
    103108    <Compile Include="Manipulators\SymbolicExpressionTreeManipulator.cs" />
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Interfaces/ISymbolicExpressionTreeOperator.cs

    r3376 r3534  
    3030using System.Diagnostics;
    3131
    32 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
     32namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Interfaces {
    3333  /// <summary>
    3434  /// Interface for operators that can be applied to symbolic expression trees.
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Manipulators/MultiSymbolicExpressionTreeManipulator.cs

    r3529 r3534  
    2828using HeuristicLab.Parameters;
    2929using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     30using HeuristicLab.Data;
     31using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Interfaces;
    3032
    31 namespace HeuristicLab.Encodings.PermutationEncoding {
    32   [Item("MultiPermutationCrossover", "Randomly selects and applies one of its crossovers every time it is called.")]
     33namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Manipulators {
     34  [Item("MultiSymbolicExpressionTreeManipulator", "Randomly selects and applies one of its manipulators every time it is called.")]
    3335  [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
    3542    public override bool CanChangeName {
    3643      get { return false; }
     
    4047    }
    4148
    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());
    4480    }
    4581
    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();
    4885    }
    4986
    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();
    5890    }
    5991
    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      }
    6499
    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;
    77102      }
    78103    }
    79104
    80105    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.");
    82107      return base.Apply();
    83108    }
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Manipulators/SymbolicExpressionTreeManipulator.cs

    r3462 r3534  
    2727using HeuristicLab.Parameters;
    2828using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     29using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Interfaces;
    2930
    3031namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Manipulators {
     
    3435  [Item("SymbolicExpressionTreeManipulator", "A base class for operators that manipulate symbolic expression trees.")]
    3536  [StorableClass]
    36   public abstract class SymbolicExpressionTreeManipulator : SymbolicExpressionTreeOperator, IManipulator {
     37  public abstract class SymbolicExpressionTreeManipulator : SymbolicExpressionTreeOperator, ISymbolicExpressionTreeManipulator {
    3738    private const string FailedManipulationEventsParameterName = "FailedManipulationEvents";
     39    private const string SymbolicExpressionTreeParameterName = "SymbolicExpressionTree";
    3840
    3941    #region Parameter Properties
    4042    public IValueParameter<IntValue> FailedManipulationEventsParameter {
    4143      get { return (IValueParameter<IntValue>)Parameters[FailedManipulationEventsParameterName]; }
     44    }
     45    public ILookupParameter<SymbolicExpressionTree> SymbolicExpressionTreeParameter {
     46      get { return (ILookupParameter<SymbolicExpressionTree>)Parameters[SymbolicExpressionTreeParameterName]; }
    4247    }
    4348    #endregion
     
    4752      get { return FailedManipulationEventsParameter.Value; }
    4853    }
     54    public SymbolicExpressionTree SymbolicExpressionTree {
     55      get { return SymbolicExpressionTreeParameter.ActualValue; }
     56    }
    4957    #endregion
    5058
     
    5260      : base() {
    5361      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."));
    5463    }
    5564
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/SymbolicExpressionTreeOperator.cs

    r3376 r3534  
    2828using HeuristicLab.Parameters;
    2929using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     30using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Interfaces;
    3031
    3132namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
     
    3738  public abstract class SymbolicExpressionTreeOperator : SingleSuccessorOperator, IStochasticOperator, ISymbolicExpressionTreeOperator {
    3839    private const string RandomParameterName = "Random";
    39     private const string SymbolicExpressionTreeParameterName = "SymbolicExpressionTree";
    4040    private const string MaxTreeSizeParameterName = "MaxTreeSize";
    4141    private const string MaxTreeHeightParameterName = "MaxTreeHeight";
     
    4949    public ILookupParameter<IRandom> RandomParameter {
    5050      get { return (LookupParameter<IRandom>)Parameters[RandomParameterName]; }
    51     }
    52     public ILookupParameter<SymbolicExpressionTree> SymbolicExpressionTreeParameter {
    53       get { return (ILookupParameter<SymbolicExpressionTree>)Parameters[SymbolicExpressionTreeParameterName]; }
    5451    }
    5552    public IValueLookupParameter<IntValue> MaxTreeSizeParameter {
     
    6865      get { return RandomParameter.ActualValue; }
    6966    }
    70     public SymbolicExpressionTree SymbolicExpressionTree {
    71       get { return SymbolicExpressionTreeParameter.ActualValue; }
    72     }
    7367    public IntValue MaxTreeSize {
    7468      get { return MaxTreeSizeParameter.ActualValue; }
     
    8579      : base() {
    8680      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."));
    8881      Parameters.Add(new ValueLookupParameter<IntValue>(MaxTreeSizeParameterName, "The maximal size (number of nodes) of the symbolic expression tree."));
    8982      Parameters.Add(new ValueLookupParameter<IntValue>(MaxTreeHeightParameterName, "The maximal height of the symbolic expression tree (a tree with one node has height = 0)."));
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Tests/AllArchitectureAlteringOperatorsTest.cs

    r3462 r3534  
    3232using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Creators;
    3333using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Crossovers;
     34using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Manipulators;
    3435
    3536namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding_3._3.Tests {
     
    7374      Stopwatch stopwatch = new Stopwatch();
    7475      stopwatch.Start();
    75       var combinedAAOperator = new RandomArchitectureAlteringOperator();
     76      var combinedAAOperator = new MultiSymbolicExpressionTreeArchitectureManipulator();
    7677      for (int g = 0; g < N_ITERATIONS; g++) {
    7778        for (int i = 0; i < POPULATION_SIZE; i++) {
     
    8081            var selectedTree = (SymbolicExpressionTree)trees.SelectRandom(random).Clone();
    8182            var op = combinedAAOperator.Operators.SelectRandom(random);
    82             bool success;
     83            bool success = false;
    8384            op.ModifyArchitecture(random, selectedTree, grammar, maxTreeSize, maxTreeHeigth, maxDefuns, maxArgs, out success);
    8485            if (!success) failedEvents++;
  • trunk/sources/HeuristicLab.Problems.ArtificialAnt/3.3/ArtificialAntProblem.cs

    r3528 r3534  
    3636using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Manipulators;
    3737using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.ArchitectureAlteringOperators;
     38using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Interfaces;
    3839
    3940namespace HeuristicLab.Problems.ArtificialAnt {
     
    368369        op.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
    369370      }
    370       foreach (SymbolicExpressionTreeArchitectureAlteringOperator op in Operators.OfType<SymbolicExpressionTreeArchitectureAlteringOperator>()) {
    371         op.MaxFunctionDefiningBranchesParameter.ActualName = MaxFunctionDefinitionsParameter.Name;
     371      foreach (ISymbolicExpressionTreeArchitectureManipulator op in Operators.OfType<ISymbolicExpressionTreeArchitectureManipulator>()) {
     372        op.MaxFunctionDefinitionsParameter.ActualName = MaxFunctionDefinitionsParameter.Name;
    372373        op.MaxFunctionArgumentsParameter.ActualName = MaxFunctionArgumentsParameter.Name;
    373374      }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/SymbolicRegressionProblem.cs

    r3532 r3534  
    3838using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Crossovers;
    3939using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Creators;
     40using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Interfaces;
    4041
    4142namespace HeuristicLab.Problems.DataAnalysis.Regression.Symbolic {
     
    194195
    195196      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;
    198199      DataAnalysisProblemDataParameter.ValueChanged += new EventHandler(DataAnalysisProblemDataParameter_ValueChanged);
    199200      DataAnalysisProblemData.ProblemDataChanged += new EventHandler(DataAnalysisProblemData_Changed);
     
    373374        op.RegressionProblemDataParameter.ActualName = DataAnalysisProblemDataParameter.Name;
    374375      }
    375       foreach (SymbolicExpressionTreeCrossover op in Operators.OfType<SymbolicExpressionTreeCrossover>()) {
     376      foreach (ISymbolicExpressionTreeCrossover op in Operators.OfType<ISymbolicExpressionTreeCrossover>()) {
    376377        op.ParentsParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
    377378        op.ChildParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
    378379      }
    379       foreach (SymbolicExpressionTreeManipulator op in Operators.OfType<SymbolicExpressionTreeManipulator>()) {
     380      foreach (ISymbolicExpressionTreeManipulator op in Operators.OfType<ISymbolicExpressionTreeManipulator>()) {
    380381        op.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
    381382      }
    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;
    383386      }
    384387    }
Note: See TracChangeset for help on using the changeset viewer.