Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Manipulators/SymbolicExpressionTreeManipulator.cs @ 4893

Last change on this file since 4893 was 4722, checked in by swagner, 14 years ago

Merged cloning refactoring branch back into trunk (#922)

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