Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Manipulators/MultiSymbolicExpressionTreeManipulator.cs @ 5494

Last change on this file since 5494 was 5445, checked in by swagner, 14 years ago

Updated year of copyrights (#1406)

File size: 5.8 KB
RevLine 
[3418]1#region License Information
2/* HeuristicLab
[5445]3 * Copyright (C) 2002-2011 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[3418]4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
[3527]22using System;
[3425]23using System.Linq;
[3418]24using HeuristicLab.Collections;
[4722]25using HeuristicLab.Common;
[3418]26using HeuristicLab.Core;
[4068]27using HeuristicLab.Data;
28using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Interfaces;
[3418]29using HeuristicLab.Operators;
30using HeuristicLab.Optimization;
31using HeuristicLab.Parameters;
32using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
[3569]33using HeuristicLab.PluginInfrastructure;
[3418]34
[3534]35namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Manipulators {
36  [Item("MultiSymbolicExpressionTreeManipulator", "Randomly selects and applies one of its manipulators every time it is called.")]
[3419]37  [StorableClass]
[4722]38  public sealed class MultiSymbolicExpressionTreeManipulator : StochasticMultiBranch<ISymbolicExpressionTreeManipulator>, ISymbolicExpressionTreeManipulator, IStochasticOperator {
[3534]39    private const string MaxTreeSizeParameterName = "MaxTreeSize";
40    private const string MaxTreeHeightParameterName = "MaxTreeHeight";
41    private const string SymbolicExpressionGrammarParameterName = "SymbolicExpressionGrammar";
42    private const string SymbolicExpressionTreeParameterName = "SymbolicExpressionTree";
43
[3418]44    public override bool CanChangeName {
45      get { return false; }
46    }
[3425]47    protected override bool CreateChildOperation {
48      get { return true; }
49    }
50
[3534]51    #region ISymbolicExpressionTreeManipulator Members
52    public ILookupParameter<SymbolicExpressionTree> SymbolicExpressionTreeParameter {
53      get { return (ILookupParameter<SymbolicExpressionTree>)Parameters[SymbolicExpressionTreeParameterName]; }
[3418]54    }
[3534]55    #endregion
[3418]56
[3534]57    #region ISymbolicExpressionTreeOperator Members
58    public IValueLookupParameter<IntValue> MaxTreeSizeParameter {
59      get { return (IValueLookupParameter<IntValue>)Parameters[MaxTreeSizeParameterName]; }
[3418]60    }
[3534]61    public IValueLookupParameter<IntValue> MaxTreeHeightParameter {
62      get { return (IValueLookupParameter<IntValue>)Parameters[MaxTreeHeightParameterName]; }
63    }
64    public ILookupParameter<ISymbolicExpressionGrammar> SymbolicExpressionGrammarParameter {
65      get { return (ILookupParameter<ISymbolicExpressionGrammar>)Parameters[SymbolicExpressionGrammarParameterName]; }
66    }
67    #endregion
[3418]68
69    [StorableConstructor]
[3534]70    private MultiSymbolicExpressionTreeManipulator(bool deserializing) : base(deserializing) { }
[4722]71    private MultiSymbolicExpressionTreeManipulator(MultiSymbolicExpressionTreeManipulator original, Cloner cloner) : base(original, cloner) { }
[3534]72    public MultiSymbolicExpressionTreeManipulator()
[3418]73      : base() {
[3534]74      Parameters.Add(new LookupParameter<SymbolicExpressionTree>(SymbolicExpressionTreeParameterName, "The symbolic expression tree on which the operator should be applied."));
75      Parameters.Add(new ValueLookupParameter<IntValue>(MaxTreeSizeParameterName, "The maximal size (number of nodes) of the symbolic expression tree."));
76      Parameters.Add(new ValueLookupParameter<IntValue>(MaxTreeHeightParameterName, "The maximal height of the symbolic expression tree (a tree with one node has height = 0)."));
77      Parameters.Add(new LookupParameter<ISymbolicExpressionGrammar>(SymbolicExpressionGrammarParameterName, "The grammar that defines the allowed symbols and syntax of the symbolic expression trees."));
[3674]78
79      foreach (Type type in ApplicationManager.Manager.GetTypes(typeof(ISymbolicExpressionTreeManipulator))) {
80        if (!typeof(MultiOperator<ISymbolicExpressionTreeManipulator>).IsAssignableFrom(type) && !typeof(ISymbolicExpressionTreeArchitectureManipulator).IsAssignableFrom(type))
81          Operators.Add((ISymbolicExpressionTreeManipulator)Activator.CreateInstance(type), true);
82      }
[3418]83    }
84
[4722]85    public override IDeepCloneable Clone(Cloner cloner) {
86      return new MultiSymbolicExpressionTreeManipulator(this, cloner);
87    }
88
[3534]89    protected override void Operators_ItemsReplaced(object sender, CollectionItemsChangedEventArgs<IndexedItem<ISymbolicExpressionTreeManipulator>> e) {
[3445]90      base.Operators_ItemsReplaced(sender, e);
[3534]91      ParameterizeManipulators();
[3425]92    }
93
[3534]94    protected override void Operators_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IndexedItem<ISymbolicExpressionTreeManipulator>> e) {
[3445]95      base.Operators_ItemsAdded(sender, e);
[3534]96      ParameterizeManipulators();
[3418]97    }
98
[3534]99    private void ParameterizeManipulators() {
100      foreach (ISymbolicExpressionTreeManipulator manipulator in Operators.OfType<ISymbolicExpressionTreeManipulator>()) {
101        manipulator.MaxTreeSizeParameter.ActualName = MaxTreeSizeParameter.Name;
102        manipulator.MaxTreeHeightParameter.ActualName = MaxTreeHeightParameter.Name;
103        manipulator.SymbolicExpressionGrammarParameter.ActualName = SymbolicExpressionGrammarParameter.Name;
104        manipulator.SymbolicExpressionTreeParameter.ActualName = SymbolicExpressionTreeParameter.Name;
[3418]105      }
[3534]106
107      foreach (IStochasticOperator manipulator in Operators.OfType<IStochasticOperator>()) {
108        manipulator.RandomParameter.ActualName = RandomParameter.Name;
[3418]109      }
110    }
111  }
112}
Note: See TracBrowser for help on using the repository browser.