Free cookie consent management tool by TermsFeed Policy Generator

source: branches/SpectralKernelForGaussianProcesses/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/ArchitectureManipulators/MultiSymbolicExpressionTreeArchitectureManipulator.cs @ 10479

Last change on this file since 10479 was 10479, checked in by gkronber, 10 years ago

#2124 merged all changes from trunk to prepare for trunk-reintegration

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