Free cookie consent management tool by TermsFeed Policy Generator

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

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

Fixed bugs related to dynamic symbol constraints with ADFs. #290 (Implement ADFs)

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