[3223] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[17180] | 3 | * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[3223] | 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] | 22 | using HeuristicLab.Common;
|
---|
[3223] | 23 | using HeuristicLab.Core;
|
---|
[12422] | 24 | using HeuristicLab.Data;
|
---|
[3223] | 25 | using HeuristicLab.Parameters;
|
---|
[16565] | 26 | using HEAL.Attic;
|
---|
[3223] | 27 |
|
---|
[5499] | 28 | namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
|
---|
[3223] | 29 | /// <summary>
|
---|
| 30 | /// A base class for operators creating symbolic expression trees.
|
---|
| 31 | /// </summary>
|
---|
| 32 | [Item("SymbolicExpressionTreeCreator", "A base class for operators creating symbolic expression trees.")]
|
---|
[16565] | 33 | [StorableType("88CC0F00-5674-4598-A3C4-756B3B7E80CB")]
|
---|
[3534] | 34 | public abstract class SymbolicExpressionTreeCreator : SymbolicExpressionTreeOperator, ISymbolicExpressionTreeCreator {
|
---|
[12422] | 35 | private const string MaximumSymbolicExpressionTreeLengthParameterName = "MaximumSymbolicExpressionTreeLength";
|
---|
| 36 | private const string MaximumSymbolicExpressionTreeDepthParameterName = "MaximumSymbolicExpressionTreeDepth";
|
---|
| 37 |
|
---|
[11496] | 38 | private const string SymbolicExpressionTreeGrammarParameterName = "SymbolicExpressionTreeGrammar";
|
---|
| 39 |
|
---|
[3338] | 40 | #region Parameter Properties
|
---|
[12422] | 41 | public IValueLookupParameter<IntValue> MaximumSymbolicExpressionTreeLengthParameter {
|
---|
| 42 | get { return (IValueLookupParameter<IntValue>)Parameters[MaximumSymbolicExpressionTreeLengthParameterName]; }
|
---|
[3534] | 43 | }
|
---|
[12422] | 44 | public IValueLookupParameter<IntValue> MaximumSymbolicExpressionTreeDepthParameter {
|
---|
| 45 | get { return (IValueLookupParameter<IntValue>)Parameters[MaximumSymbolicExpressionTreeDepthParameterName]; }
|
---|
| 46 | }
|
---|
[11496] | 47 | public IValueLookupParameter<ISymbolicExpressionGrammar> SymbolicExpressionTreeGrammarParameter {
|
---|
| 48 | get { return (IValueLookupParameter<ISymbolicExpressionGrammar>)Parameters[SymbolicExpressionTreeGrammarParameterName]; }
|
---|
[3534] | 49 | }
|
---|
[3338] | 50 | #endregion
|
---|
[11496] | 51 |
|
---|
[4722] | 52 | [StorableConstructor]
|
---|
[16565] | 53 | protected SymbolicExpressionTreeCreator(StorableConstructorFlag _) : base(_) { }
|
---|
[4722] | 54 | protected SymbolicExpressionTreeCreator(SymbolicExpressionTreeCreator original, Cloner cloner) : base(original, cloner) { }
|
---|
[3223] | 55 | protected SymbolicExpressionTreeCreator()
|
---|
| 56 | : base() {
|
---|
[12422] | 57 | Parameters.Add(new ValueLookupParameter<IntValue>(MaximumSymbolicExpressionTreeLengthParameterName, "The maximal length (number of nodes) of the symbolic expression tree."));
|
---|
| 58 | Parameters.Add(new ValueLookupParameter<IntValue>(MaximumSymbolicExpressionTreeDepthParameterName, "The maximal depth of the symbolic expression tree (a tree with one node has depth = 0)."));
|
---|
| 59 | Parameters.Add(new ValueLookupParameter<ISymbolicExpressionGrammar>(SymbolicExpressionTreeGrammarParameterName, "The tree grammar that defines the correct syntax of symbolic expression trees that should be created."));
|
---|
[3223] | 60 | }
|
---|
| 61 |
|
---|
[10291] | 62 | public override IOperation InstrumentedApply() {
|
---|
[18064] | 63 | var rand = RandomParameter.ActualValue;
|
---|
| 64 | var grammar = SymbolicExpressionTreeGrammarParameter.ActualValue;
|
---|
| 65 | var maxTreeLength = MaximumSymbolicExpressionTreeLengthParameter.ActualValue.Value;
|
---|
| 66 | var maxTreeDepth = MaximumSymbolicExpressionTreeDepthParameter.ActualValue.Value;
|
---|
[11496] | 67 |
|
---|
[18064] | 68 | SymbolicExpressionTreeParameter.ActualValue = CreateTree(rand, grammar, maxTreeLength, maxTreeDepth);
|
---|
[10291] | 69 | return base.InstrumentedApply();
|
---|
[3223] | 70 | }
|
---|
[7012] | 71 | public abstract ISymbolicExpressionTree CreateTree(IRandom random, ISymbolicExpressionGrammar grammar, int maxTreeLength, int maxTreeDepth);
|
---|
[3223] | 72 | }
|
---|
| 73 | }
|
---|