Free cookie consent management tool by TermsFeed Policy Generator

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

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

Refactored symbolic expression tree encoding and problem classes for symbolic regression. #937 , #938

File size: 3.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 System.Linq;
23using HeuristicLab.Common;
24using HeuristicLab.Core;
25using HeuristicLab.Data;
26using HeuristicLab.Operators;
27using HeuristicLab.Optimization;
28using HeuristicLab.Parameters;
29using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
30
31namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Creators {
32  /// <summary>
33  /// A base class for operators creating symbolic expression trees.
34  /// </summary>
35  [Item("SymbolicExpressionTreeCreator", "A base class for operators creating symbolic expression trees.")]
36  [StorableClass]
37  public abstract class SymbolicExpressionTreeCreator : SymbolicExpressionTreeOperator, ISolutionCreator {
38    private const string MaxFunctionDefinitionsParameterName = "MaxFunctionDefinitions";
39    private const string MaxFunctionArgumentsParameterName = "MaxFunctionArguments";
40    #region Parameter Properties
41    public IValueLookupParameter<IntValue> MaxFunctionDefinitionsParameter {
42      get { return (IValueLookupParameter<IntValue>)Parameters[MaxFunctionDefinitionsParameterName]; }
43    }
44    public IValueLookupParameter<IntValue> MaxFunctionArgumentsParameter {
45      get { return (IValueLookupParameter<IntValue>)Parameters[MaxFunctionArgumentsParameterName]; }
46    }
47    #endregion
48
49    #region Propeties
50    public IntValue MaxFunctionDefinitions {
51      get { return MaxFunctionDefinitionsParameter.ActualValue; }
52    }
53    public IntValue MaxFunctionArguments {
54      get { return MaxFunctionArgumentsParameter.ActualValue; }
55    }
56
57    #endregion
58    protected SymbolicExpressionTreeCreator()
59      : base() {
60      Parameters.Add(new ValueLookupParameter<IntValue>(MaxFunctionDefinitionsParameterName, "Maximal number of function definitions in the symbolic expression tree."));
61      Parameters.Add(new ValueLookupParameter<IntValue>(MaxFunctionArgumentsParameterName, "Maximal number of arguments of automatically defined functions in the symbolic expression tree."));
62    }
63
64    public sealed override IOperation Apply() {
65      SymbolicExpressionTreeParameter.ActualValue = Create(Random, SymbolicExpressionGrammar,
66        MaxTreeSize, MaxTreeHeight, MaxFunctionDefinitions, MaxFunctionArguments);
67      return null;
68    }
69
70    protected abstract SymbolicExpressionTree Create(
71      IRandom random,
72      ISymbolicExpressionGrammar grammar,
73      IntValue maxTreeSize, IntValue maxTreeHeight,
74      IntValue maxFunctionDefinitions, IntValue maxFunctionArguments
75      );
76  }
77}
Note: See TracBrowser for help on using the repository browser.