Free cookie consent management tool by TermsFeed Policy Generator

source: branches/DataAnalysis.Extensions/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Manipulators/SymbolicExpressionTreeManipulator.cs @ 5637

Last change on this file since 5637 was 4803, checked in by swinkler, 14 years ago

Created branch for implementing Smalltalk representation of formulas. (#1270)

File size: 3.7 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
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 HeuristicLab.Common;
23using HeuristicLab.Core;
24using HeuristicLab.Data;
25using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Interfaces;
26using HeuristicLab.Parameters;
27using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
28
29namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Manipulators {
30  /// <summary>
31  /// A base class for operators that manipulate real-valued vectors.
32  /// </summary>
33  [Item("SymbolicExpressionTreeManipulator", "A base class for operators that manipulate symbolic expression trees.")]
34  [StorableClass]
35  public abstract class SymbolicExpressionTreeManipulator : SymbolicExpressionTreeOperator, ISymbolicExpressionTreeManipulator {
36    private const string FailedManipulationEventsParameterName = "FailedManipulationEvents";
37    private const string SymbolicExpressionTreeParameterName = "SymbolicExpressionTree";
38
39    #region Parameter Properties
40    public IValueParameter<IntValue> FailedManipulationEventsParameter {
41      get { return (IValueParameter<IntValue>)Parameters[FailedManipulationEventsParameterName]; }
42    }
43    public ILookupParameter<SymbolicExpressionTree> SymbolicExpressionTreeParameter {
44      get { return (ILookupParameter<SymbolicExpressionTree>)Parameters[SymbolicExpressionTreeParameterName]; }
45    }
46    #endregion
47
48    #region Properties
49    public IntValue FailedManipulationEvents {
50      get { return FailedManipulationEventsParameter.Value; }
51    }
52    public SymbolicExpressionTree SymbolicExpressionTree {
53      get { return SymbolicExpressionTreeParameter.ActualValue; }
54    }
55    #endregion
56
57    [StorableConstructor]
58    protected SymbolicExpressionTreeManipulator(bool deserializing) : base(deserializing) { }
59    protected SymbolicExpressionTreeManipulator(SymbolicExpressionTreeManipulator original, Cloner cloner) : base(original, cloner) { }
60    public SymbolicExpressionTreeManipulator()
61      : base() {
62      Parameters.Add(new ValueParameter<IntValue>(FailedManipulationEventsParameterName, "The number of failed manipulation events.", new IntValue()));
63      Parameters.Add(new LookupParameter<SymbolicExpressionTree>(SymbolicExpressionTreeParameterName, "The symbolic expression tree on which the operator should be applied."));
64    }
65
66    public sealed override IOperation Apply() {
67      SymbolicExpressionTree tree = SymbolicExpressionTreeParameter.ActualValue;
68      bool success;
69      Manipulate(RandomParameter.ActualValue, tree, SymbolicExpressionGrammarParameter.ActualValue,
70        MaxTreeSizeParameter.ActualValue, MaxTreeHeightParameter.ActualValue, out success);
71
72      if (!success) FailedManipulationEvents.Value++;
73      return base.Apply();
74    }
75
76    protected abstract void Manipulate(IRandom random, SymbolicExpressionTree symbolicExpressionTree, ISymbolicExpressionGrammar grammar,
77      IntValue maxTreeSize, IntValue maxTreeHeight, out bool success);
78  }
79}
Note: See TracBrowser for help on using the repository browser.