Free cookie consent management tool by TermsFeed Policy Generator

source: branches/DataAnalysis.Extensions/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/ArchitectureManipulators/SymbolicExpressionTreeArchitectureManipulator.cs @ 7663

Last change on this file since 7663 was 4803, checked in by swinkler, 14 years ago

Created branch for implementing Smalltalk representation of formulas. (#1270)

File size: 3.8 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.Common;
23using HeuristicLab.Core;
24using HeuristicLab.Data;
25using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Interfaces;
26using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Manipulators;
27using HeuristicLab.Parameters;
28using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
29
30namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.ArchitectureManipulators {
31  /// <summary>
32  /// Base class for architecture altering operators for symbolic expression trees.
33  /// </summary>
34  [StorableClass]
35  public abstract class SymbolicExpressionTreeArchitectureManipulator : SymbolicExpressionTreeManipulator, ISymbolicExpressionTreeArchitectureManipulator {
36    private const string MaxFunctionArgumentsParameterName = "MaxFunctionArguments";
37    private const string MaxFunctionDefiningBranchesParameterName = "MaxFunctionDefiningBranches";
38    public override bool CanChangeName {
39      get { return false; }
40    }
41
42    public IValueLookupParameter<IntValue> MaxFunctionDefinitionsParameter {
43      get { return (IValueLookupParameter<IntValue>)Parameters[MaxFunctionDefiningBranchesParameterName]; }
44    }
45    public IValueLookupParameter<IntValue> MaxFunctionArgumentsParameter {
46      get { return (IValueLookupParameter<IntValue>)Parameters[MaxFunctionArgumentsParameterName]; }
47    }
48    public IntValue MaxFunctionDefiningBranches {
49      get { return MaxFunctionDefinitionsParameter.ActualValue; }
50    }
51    public IntValue MaxFunctionArguments {
52      get { return MaxFunctionArgumentsParameter.ActualValue; }
53    }
54    [StorableConstructor]
55    protected SymbolicExpressionTreeArchitectureManipulator(bool deserializing) : base(deserializing) { }
56    protected SymbolicExpressionTreeArchitectureManipulator(SymbolicExpressionTreeArchitectureManipulator original, Cloner cloner) : base(original, cloner) { }
57    public SymbolicExpressionTreeArchitectureManipulator()
58      : base() {
59      Parameters.Add(new ValueLookupParameter<IntValue>(MaxFunctionDefiningBranchesParameterName, "The maximal allowed number of function defining branches."));
60      Parameters.Add(new ValueLookupParameter<IntValue>(MaxFunctionArgumentsParameterName, "The maximal allowed number of arguments of a newly created function."));
61    }
62
63    protected override sealed void Manipulate(IRandom random, SymbolicExpressionTree symbolicExpressionTree, ISymbolicExpressionGrammar grammar, IntValue maxTreeSize, IntValue maxTreeHeight, out bool success) {
64      ModifyArchitecture(random, symbolicExpressionTree, grammar, maxTreeSize, maxTreeHeight, MaxFunctionDefiningBranches, MaxFunctionArguments, out success);
65    }
66
67    public abstract void ModifyArchitecture(
68      IRandom random,
69      SymbolicExpressionTree tree,
70      ISymbolicExpressionGrammar grammar,
71      IntValue maxTreeSize,
72      IntValue maxTreeHeight,
73      IntValue maxFunctionDefinitions,
74      IntValue maxFunctionArguments,
75      out bool success
76      );
77  }
78}
Note: See TracBrowser for help on using the repository browser.