[3294] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[5445] | 3 | * Copyright (C) 2002-2011 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[3294] | 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;
|
---|
[3294] | 23 | using HeuristicLab.Core;
|
---|
| 24 | using HeuristicLab.Data;
|
---|
[4068] | 25 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Interfaces;
|
---|
| 26 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Manipulators;
|
---|
[3294] | 27 | using HeuristicLab.Parameters;
|
---|
| 28 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 29 |
|
---|
[3539] | 30 | namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.ArchitectureManipulators {
|
---|
[3294] | 31 | /// <summary>
|
---|
| 32 | /// Base class for architecture altering operators for symbolic expression trees.
|
---|
| 33 | /// </summary>
|
---|
| 34 | [StorableClass]
|
---|
[3534] | 35 | public abstract class SymbolicExpressionTreeArchitectureManipulator : SymbolicExpressionTreeManipulator, ISymbolicExpressionTreeArchitectureManipulator {
|
---|
[3294] | 36 | private const string MaxFunctionArgumentsParameterName = "MaxFunctionArguments";
|
---|
| 37 | private const string MaxFunctionDefiningBranchesParameterName = "MaxFunctionDefiningBranches";
|
---|
| 38 | public override bool CanChangeName {
|
---|
| 39 | get { return false; }
|
---|
| 40 | }
|
---|
| 41 |
|
---|
[3534] | 42 | public IValueLookupParameter<IntValue> MaxFunctionDefinitionsParameter {
|
---|
[3294] | 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 {
|
---|
[3534] | 49 | get { return MaxFunctionDefinitionsParameter.ActualValue; }
|
---|
[3294] | 50 | }
|
---|
| 51 | public IntValue MaxFunctionArguments {
|
---|
| 52 | get { return MaxFunctionArgumentsParameter.ActualValue; }
|
---|
| 53 | }
|
---|
[4722] | 54 | [StorableConstructor]
|
---|
| 55 | protected SymbolicExpressionTreeArchitectureManipulator(bool deserializing) : base(deserializing) { }
|
---|
| 56 | protected SymbolicExpressionTreeArchitectureManipulator(SymbolicExpressionTreeArchitectureManipulator original, Cloner cloner) : base(original, cloner) { }
|
---|
[3534] | 57 | public SymbolicExpressionTreeArchitectureManipulator()
|
---|
[3294] | 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,
|
---|
[3534] | 73 | IntValue maxFunctionDefinitions,
|
---|
[3294] | 74 | IntValue maxFunctionArguments,
|
---|
| 75 | out bool success
|
---|
| 76 | );
|
---|
| 77 | }
|
---|
| 78 | }
|
---|