Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/ArchitectureManipulators/MultiSymbolicExpressionTreeArchitectureManipulator.cs @ 6206

Last change on this file since 6206 was 5809, checked in by mkommend, 13 years ago

#1418: Reintegrated branch into trunk.

File size: 7.7 KB
RevLine 
[3294]1#region License Information
2/* HeuristicLab
[5445]3 * Copyright (C) 2002-2011 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[3294]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
22using System;
23using System.Linq;
[3534]24using HeuristicLab.Collections;
[4722]25using HeuristicLab.Common;
[3294]26using HeuristicLab.Core;
[4068]27using HeuristicLab.Data;
[3294]28using HeuristicLab.Operators;
29using HeuristicLab.Optimization;
30using HeuristicLab.Parameters;
31using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
[3569]32using HeuristicLab.PluginInfrastructure;
[3294]33
[5499]34namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
[3534]35  [Item("MultiSymbolicExpressionTreeArchitectureManipulator", "Randomly selects and applies one of its architecture manipulators every time it is called.")]
[3294]36  [StorableClass]
[5719]37  public sealed class MultiSymbolicExpressionTreeArchitectureManipulator : StochasticMultiBranch<ISymbolicExpressionTreeManipulator>,
38    ISymbolicExpressionTreeArchitectureManipulator,
[5510]39    ISymbolicExpressionTreeSizeConstraintOperator,
40    IStochasticOperator {
41    private const string MaximumSymbolicExpressionTreeLengthParameterName = "MaximumSymbolicExpressionTreeLength";
42    private const string MaximumSymbolicExpressionTreeDepthParameterName = "MaximumSymbolicExpressionTreeDepth";
[3534]43    private const string SymbolicExpressionTreeParameterName = "SymbolicExpressionTree";
[5510]44    private const string MaximumFunctionArgumentsParameterName = "MaximumFunctionArguments";
45    private const string MaximumFunctionDefinitionsParameterName = "MaximumFunctionDefinitions";
[3534]46
47    public override bool CanChangeName {
48      get { return false; }
[3294]49    }
[3534]50    protected override bool CreateChildOperation {
51      get { return true; }
52    }
[5510]53    #region Parameter properties
54    public ILookupParameter<ISymbolicExpressionTree> SymbolicExpressionTreeParameter {
55      get { return (ILookupParameter<ISymbolicExpressionTree>)Parameters[SymbolicExpressionTreeParameterName]; }
[3534]56    }
[5510]57    public IValueLookupParameter<IntValue> MaximumFunctionDefinitionsParameter {
58      get { return (IValueLookupParameter<IntValue>)Parameters[MaximumFunctionDefinitionsParameterName]; }
[3534]59    }
[5510]60    public IValueLookupParameter<IntValue> MaximumFunctionArgumentsParameter {
61      get { return (IValueLookupParameter<IntValue>)Parameters[MaximumFunctionArgumentsParameterName]; }
[3294]62    }
[5510]63    public IValueLookupParameter<IntValue> MaximumSymbolicExpressionTreeLengthParameter {
64      get { return (IValueLookupParameter<IntValue>)Parameters[MaximumSymbolicExpressionTreeLengthParameterName]; }
65    }
66    public IValueLookupParameter<IntValue> MaximumSymbolicExpressionTreeDepthParameter {
67      get { return (IValueLookupParameter<IntValue>)Parameters[MaximumSymbolicExpressionTreeDepthParameterName]; }
68    }
[3294]69    #endregion
[5510]70    #region Parameter Properties
71    public IntValue MaximumFunctionDefinitions {
72      get { return MaximumFunctionDefinitionsParameter.ActualValue; }
[3534]73    }
[5510]74    public IntValue MaximumFunctionArguments {
75      get { return MaximumFunctionArgumentsParameter.ActualValue; }
[3534]76    }
[5510]77    public IntValue MaximumSymbolicExpressionTreeLength {
78      get { return MaximumSymbolicExpressionTreeLengthParameter.ActualValue; }
[3534]79    }
[5510]80    public IntValue MaximumSymbolicExpressionTreeDepth {
81      get { return MaximumSymbolicExpressionTreeDepthParameter.ActualValue; }
82    }
[3534]83    #endregion
84
85
86    [StorableConstructor]
87    private MultiSymbolicExpressionTreeArchitectureManipulator(bool deserializing) : base(deserializing) { }
[4722]88    private MultiSymbolicExpressionTreeArchitectureManipulator(MultiSymbolicExpressionTreeArchitectureManipulator original, Cloner cloner) : base(original, cloner) { }
[3534]89    public MultiSymbolicExpressionTreeArchitectureManipulator()
[3294]90      : base() {
[5510]91      Parameters.Add(new LookupParameter<ISymbolicExpressionTree>(SymbolicExpressionTreeParameterName, "The symbolic expression tree on which the operator should be applied."));
92      Parameters.Add(new ValueLookupParameter<IntValue>(MaximumFunctionDefinitionsParameterName, "The maximal allowed number of automatically defined functions."));
93      Parameters.Add(new ValueLookupParameter<IntValue>(MaximumFunctionArgumentsParameterName, "The maximal allowed number of arguments of a automatically defined functions."));
94      Parameters.Add(new ValueLookupParameter<IntValue>(MaximumSymbolicExpressionTreeLengthParameterName, "The maximal length (number of nodes) of the symbolic expression tree."));
95      Parameters.Add(new ValueLookupParameter<IntValue>(MaximumSymbolicExpressionTreeDepthParameterName, "The maximal depth of the symbolic expression tree (a tree with one node has depth = 0)."));
[3674]96
[5719]97      CheckedItemList<ISymbolicExpressionTreeManipulator> list = new CheckedItemList<ISymbolicExpressionTreeManipulator>();
98      foreach (Type type in ApplicationManager.Manager.GetTypes(typeof(ISymbolicExpressionTreeManipulator))) {
99        if (!typeof(IMultiOperator<ISymbolicExpressionTreeManipulator>).IsAssignableFrom(type))
100          list.Add((ISymbolicExpressionTreeManipulator)Activator.CreateInstance(type), true);
[3674]101      }
[5719]102      Operators = list.AsReadOnly();
103      Operators_ItemsAdded(this, new CollectionItemsChangedEventArgs<IndexedItem<ISymbolicExpressionTreeManipulator>>(Operators.CheckedItems));
[3294]104    }
105
[4722]106    public override IDeepCloneable Clone(Cloner cloner) {
107      return new MultiSymbolicExpressionTreeArchitectureManipulator(this, cloner);
108    }
109
[5719]110    protected override void Operators_ItemsReplaced(object sender, CollectionItemsChangedEventArgs<IndexedItem<ISymbolicExpressionTreeManipulator>> e) {
[3534]111      base.Operators_ItemsReplaced(sender, e);
112      ParameterizeManipulators();
[3294]113    }
[3534]114
[5719]115    protected override void Operators_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IndexedItem<ISymbolicExpressionTreeManipulator>> e) {
[3534]116      base.Operators_ItemsAdded(sender, e);
117      ParameterizeManipulators();
118    }
119
120    private void ParameterizeManipulators() {
121      foreach (ISymbolicExpressionTreeArchitectureManipulator manipulator in Operators.OfType<ISymbolicExpressionTreeArchitectureManipulator>()) {
[5510]122        manipulator.MaximumFunctionArgumentsParameter.ActualName = MaximumFunctionArgumentsParameter.Name;
123        manipulator.MaximumFunctionDefinitionsParameter.ActualName = MaximumFunctionDefinitionsParameter.Name;
124      }
[5719]125      foreach (ISymbolicExpressionTreeSizeConstraintOperator manipulator in Operators.OfType<ISymbolicExpressionTreeSizeConstraintOperator>()) {
[5510]126        manipulator.MaximumSymbolicExpressionTreeDepthParameter.ActualName = MaximumSymbolicExpressionTreeDepthParameter.Name;
127        manipulator.MaximumSymbolicExpressionTreeLengthParameter.ActualName = MaximumSymbolicExpressionTreeLengthParameter.Name;
128      }
[5719]129      foreach (ISymbolicExpressionTreeManipulator manipulator in Operators.OfType<ISymbolicExpressionTreeManipulator>()) {
[3534]130        manipulator.SymbolicExpressionTreeParameter.ActualName = SymbolicExpressionTreeParameter.Name;
131      }
132      foreach (IStochasticOperator manipulator in Operators.OfType<IStochasticOperator>()) {
133        manipulator.RandomParameter.ActualName = RandomParameter.Name;
134      }
135    }
[3294]136  }
137}
Note: See TracBrowser for help on using the repository browser.