Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/26/10 15:47:10 (15 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/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  
    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
Note: See TracChangeset for help on using the changeset viewer.