Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/SymbolicExpressionTreeCreator.cs @ 3239

Last change on this file since 3239 was 3239, checked in by gkronber, 14 years ago

Extracted view for artificial ant problem into a separate plugin/project. #952 (Artificial Ant Problem for 3.3)

File size: 4.3 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.Core;
23using HeuristicLab.Data;
24using HeuristicLab.Operators;
25using HeuristicLab.Optimization;
26using HeuristicLab.Parameters;
27using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
28
29namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
30  /// <summary>
31  /// A base class for operators creating symbolic expression trees.
32  /// </summary>
33  [Item("SymbolicExpressionTreeCreator", "A base class for operators creating symbolic expression trees.")]
34  [StorableClass]
35  public abstract class SymbolicExpressionTreeCreator : SingleSuccessorOperator, ISolutionCreator, IStochasticOperator, ISymbolicExpressionTreeOperator {
36    private const string RandomParameterName = "Random";
37    private const string SymbolicExpressionTreeParameterName = "SymbolicExpressionTree";
38    private const string MaxTreeSizeParameterName = "MaxTreeSize";
39    private const string MaxTreeHeightParameterName = "MaxTreeHeight";
40    private const string SymbolicExpressionGrammarParameterName = "SymbolicExpressionGrammar";
41
42    public override bool CanChangeName {
43      get { return false; }
44    }
45
46    public ILookupParameter<IRandom> RandomParameter {
47      get { return (LookupParameter<IRandom>)Parameters[RandomParameterName]; }
48    }
49    public ILookupParameter<SymbolicExpressionTree> SymbolicExpressionTreeParameter {
50      get { return (ILookupParameter<SymbolicExpressionTree>)Parameters[SymbolicExpressionTreeParameterName]; }
51    }
52    public IValueLookupParameter<IntValue> MaxTreeSizeParameter {
53      get { return (IValueLookupParameter<IntValue>)Parameters[MaxTreeSizeParameterName]; }
54    }
55    public IValueLookupParameter<IntValue> MaxTreeHeightParameter {
56      get { return (IValueLookupParameter<IntValue>)Parameters[MaxTreeHeightParameterName]; }
57    }
58    public ILookupParameter<ISymbolicExpressionGrammar> SymbolicExpressionGrammarParameter {
59      get { return (ILookupParameter<ISymbolicExpressionGrammar>)Parameters[SymbolicExpressionGrammarParameterName]; }
60    }
61
62    protected SymbolicExpressionTreeCreator()
63      : base() {
64      Parameters.Add(new LookupParameter<IRandom>(RandomParameterName, "The pseudo random number generator which should be used for stochastic solution creation operators."));
65      Parameters.Add(new LookupParameter<SymbolicExpressionTree>(SymbolicExpressionTreeParameterName, "The symbolic expression tree that should be initialized."));
66      Parameters.Add(new ValueLookupParameter<IntValue>(MaxTreeSizeParameterName, "The maximal size (number of nodes) of the symbolic expression tree that should be initialized."));
67      Parameters.Add(new ValueLookupParameter<IntValue>(MaxTreeHeightParameterName, "The maximal height of the symbolic expression tree that should be initialized (a tree with one node has height = 0)."));
68      Parameters.Add(new LookupParameter<ISymbolicExpressionGrammar>(SymbolicExpressionGrammarParameterName, "The grammar that defines the allowed symbols and syntax of the symbolic expression trees."));
69    }
70
71    public sealed override IOperation Apply() {
72      SymbolicExpressionTreeParameter.ActualValue = Create(RandomParameter.ActualValue, SymbolicExpressionGrammarParameter.ActualValue,
73        MaxTreeSizeParameter.ActualValue, MaxTreeHeightParameter.ActualValue);
74      return base.Apply();
75    }
76
77    protected abstract SymbolicExpressionTree Create(IRandom random, ISymbolicExpressionGrammar grammar, IntValue maxTreeSize, IntValue maxTreeHeight);
78  }
79}
Note: See TracBrowser for help on using the repository browser.