[5333] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[5445] | 3 | * Copyright (C) 2002-2011 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[5333] | 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 |
|
---|
[5393] | 22 | using System.Collections.Generic;
|
---|
[5333] | 23 | using System.Linq;
|
---|
| 24 | using HeuristicLab.Common;
|
---|
| 25 | using HeuristicLab.Core;
|
---|
| 26 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
|
---|
| 27 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 28 | namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
|
---|
| 29 | [StorableClass]
|
---|
[6284] | 30 | [Item("Poly10Grammar", "Represents a grammar for modeling with fixed structures for the voest B1 MwDru target variable.")]
|
---|
| 31 | public class Poly10Grammar : SymbolicExpressionGrammar, ISymbolicDataAnalysisGrammar {
|
---|
[5333] | 32 |
|
---|
| 33 | [StorableConstructor]
|
---|
[6284] | 34 | protected Poly10Grammar(bool deserializing) : base(deserializing) { }
|
---|
| 35 | protected Poly10Grammar(Poly10Grammar original, Cloner cloner) : base(original, cloner) { }
|
---|
| 36 | public Poly10Grammar()
|
---|
| 37 | : base(ItemAttribute.GetName(typeof(Poly10Grammar)), ItemAttribute.GetDescription(typeof(TypeCoherentExpressionGrammar))) {
|
---|
[5333] | 38 | Initialize();
|
---|
| 39 | }
|
---|
| 40 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
[6284] | 41 | return new Poly10Grammar(this, cloner);
|
---|
[5333] | 42 | }
|
---|
| 43 |
|
---|
| 44 | private void Initialize() {
|
---|
| 45 | var add = new Addition();
|
---|
| 46 | var sub = new Subtraction();
|
---|
| 47 | var mul = new Multiplication();
|
---|
| 48 | var div = new Division();
|
---|
[5393] | 49 |
|
---|
[5333] | 50 | var constant = new Constant();
|
---|
[5574] | 51 | var variableSymbol = new HeuristicLab.Problems.DataAnalysis.Symbolic.Variable();
|
---|
[5333] | 52 |
|
---|
[6284] | 53 | var fixedAdd1 = new Addition();
|
---|
| 54 | fixedAdd1.Name = "fixed Addition1";
|
---|
| 55 | fixedAdd1.Fixed = true;
|
---|
[5333] | 56 |
|
---|
[6284] | 57 | var fixedAdd2 = new Addition();
|
---|
| 58 | fixedAdd2.Name = "fixed Addition2";
|
---|
| 59 | fixedAdd2.Fixed = true;
|
---|
[5333] | 60 |
|
---|
[6284] | 61 | var fixedAdd3 = new Addition();
|
---|
| 62 | fixedAdd3.Name = "fixed Addition3";
|
---|
| 63 | fixedAdd3.Fixed = true;
|
---|
[5333] | 64 |
|
---|
[6284] | 65 | var fixedMul1 = new Multiplication();
|
---|
| 66 | fixedMul1.Name = "fixed Multiplication1";
|
---|
| 67 | fixedMul1.Fixed = true;
|
---|
[5333] | 68 |
|
---|
[6284] | 69 | var fixedMul2 = new Multiplication();
|
---|
| 70 | fixedMul2.Name = "fixed Multiplication2";
|
---|
| 71 | fixedMul2.Fixed = true;
|
---|
[5333] | 72 |
|
---|
[6284] | 73 |
|
---|
| 74 | #region fixed variables
|
---|
| 75 | var x1 = new HeuristicLab.Problems.DataAnalysis.Symbolic.Variable();
|
---|
| 76 | x1.Name = "fixed X1";
|
---|
| 77 | x1.VariableNames = new List<string>() { "x1" };
|
---|
| 78 | x1.Fixed = true;
|
---|
| 79 |
|
---|
| 80 |
|
---|
| 81 | var x2 = new HeuristicLab.Problems.DataAnalysis.Symbolic.Variable();
|
---|
| 82 | x2.Name = "fixed X2";
|
---|
| 83 | x2.VariableNames = new List<string>() { "x2" };
|
---|
| 84 | x2.Fixed = true;
|
---|
| 85 |
|
---|
| 86 | var x3 = new HeuristicLab.Problems.DataAnalysis.Symbolic.Variable();
|
---|
| 87 | x3.Name = "fixed X3";
|
---|
| 88 | x3.VariableNames = new List<string>() { "x3" };
|
---|
| 89 | x3.Fixed = true;
|
---|
| 90 |
|
---|
| 91 | var x4 = new HeuristicLab.Problems.DataAnalysis.Symbolic.Variable();
|
---|
| 92 | x4.Name = "fixed X4";
|
---|
| 93 | x4.VariableNames = new List<string>() { "x4" };
|
---|
| 94 | x4.Fixed = true;
|
---|
| 95 |
|
---|
| 96 | var x5 = new HeuristicLab.Problems.DataAnalysis.Symbolic.Variable();
|
---|
| 97 | x5.Name = "fixed X5";
|
---|
| 98 | x5.VariableNames = new List<string>() { "x5" };
|
---|
| 99 | x5.Fixed = true;
|
---|
| 100 |
|
---|
| 101 | var x6 = new HeuristicLab.Problems.DataAnalysis.Symbolic.Variable();
|
---|
| 102 | x6.Name = "fixed X6";
|
---|
| 103 | x6.VariableNames = new List<string>() { "x6" };
|
---|
| 104 | x6.Fixed = true;
|
---|
| 105 |
|
---|
| 106 | var x7 = new HeuristicLab.Problems.DataAnalysis.Symbolic.Variable();
|
---|
| 107 | x7.Name = "fixed X7";
|
---|
| 108 | x7.VariableNames = new List<string>() { "x7" };
|
---|
| 109 | x7.Fixed = true;
|
---|
| 110 |
|
---|
| 111 | var x8 = new HeuristicLab.Problems.DataAnalysis.Symbolic.Variable();
|
---|
| 112 | x8.Name = "fixed X8";
|
---|
| 113 | x8.VariableNames = new List<string>() { "x8" };
|
---|
| 114 | x8.Fixed = true;
|
---|
| 115 |
|
---|
| 116 | var x9 = new HeuristicLab.Problems.DataAnalysis.Symbolic.Variable();
|
---|
| 117 | x9.Name = "fixed X9";
|
---|
| 118 | x9.VariableNames = new List<string>() { "x9" };
|
---|
| 119 | x9.Fixed = true;
|
---|
| 120 |
|
---|
| 121 | var x10 = new HeuristicLab.Problems.DataAnalysis.Symbolic.Variable();
|
---|
| 122 | x10.Name = "fixed X10";
|
---|
| 123 | x10.VariableNames = new List<string>() { "x10" };
|
---|
| 124 | x10.Fixed = true;
|
---|
| 125 | #endregion
|
---|
| 126 |
|
---|
| 127 | var fixedTerminalSymbols = new List<HeuristicLab.Problems.DataAnalysis.Symbolic.Variable>() { x1, x2, x3, x4, x5, x6, x7, x8, x9, x10 };
|
---|
| 128 | var allSymbols = new List<Symbol>()
|
---|
| 129 | { add, sub, mul, div, constant, variableSymbol,
|
---|
| 130 | fixedAdd1,fixedMul1,fixedMul2}.Union(fixedTerminalSymbols);
|
---|
| 131 |
|
---|
| 132 | var binaryFunctionSymbols = new List<Symbol>() { add, sub, mul, div };
|
---|
| 133 | var terminalSymbols = new List<Symbol>() { variableSymbol, constant };
|
---|
| 134 | var realValuedSymbols = binaryFunctionSymbols.Concat(terminalSymbols);
|
---|
| 135 |
|
---|
[5333] | 136 | foreach (var symb in allSymbols)
|
---|
| 137 | AddSymbol(symb);
|
---|
[6284] | 138 | foreach (var terminalSymbol in terminalSymbols.Union(fixedTerminalSymbols)) {
|
---|
| 139 | SetSubtreeCount(terminalSymbol, 0, 0);
|
---|
[5333] | 140 | }
|
---|
[6284] | 141 | foreach (var binaryFun in binaryFunctionSymbols) {
|
---|
[5686] | 142 | SetSubtreeCount(binaryFun, 2, 2);
|
---|
[5333] | 143 | }
|
---|
[6284] | 144 | SetSubtreeCount(fixedAdd1, 3, 3);
|
---|
| 145 | SetSubtreeCount(fixedMul1, 3, 3);
|
---|
| 146 | SetSubtreeCount(fixedMul2, 3, 3);
|
---|
[5333] | 147 |
|
---|
[6284] | 148 | AddAllowedChildSymbol(StartSymbol, fixedAdd1);
|
---|
| 149 | foreach (var symb in realValuedSymbols) {
|
---|
| 150 | AddAllowedChildSymbol(fixedAdd1, symb, 0);
|
---|
[5333] | 151 | }
|
---|
| 152 |
|
---|
[6284] | 153 | AddAllowedChildSymbol(fixedAdd1, fixedMul1, 1);
|
---|
| 154 | AddAllowedChildSymbol(fixedAdd1, fixedMul2, 2);
|
---|
[5333] | 155 |
|
---|
| 156 |
|
---|
[6284] | 157 | AddAllowedChildSymbol(fixedMul1, x1, 0);
|
---|
| 158 | AddAllowedChildSymbol(fixedMul1, x7, 1);
|
---|
| 159 | AddAllowedChildSymbol(fixedMul1, x9, 2);
|
---|
[5333] | 160 |
|
---|
[6284] | 161 | AddAllowedChildSymbol(fixedMul2, x3, 0);
|
---|
| 162 | AddAllowedChildSymbol(fixedMul2, x6, 1);
|
---|
| 163 | AddAllowedChildSymbol(fixedMul2, x10, 2);
|
---|
[5333] | 164 |
|
---|
| 165 | foreach (var symb in binaryFunctionSymbols) {
|
---|
| 166 | foreach (var childSymb in realValuedSymbols) {
|
---|
[5686] | 167 | AddAllowedChildSymbol(symb, childSymb);
|
---|
[5333] | 168 | }
|
---|
| 169 | }
|
---|
| 170 | }
|
---|
| 171 | }
|
---|
| 172 | }
|
---|