[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 |
|
---|
[6284] | 22 | using System;
|
---|
[5393] | 23 | using System.Collections.Generic;
|
---|
[5333] | 24 | using System.Linq;
|
---|
| 25 | using HeuristicLab.Common;
|
---|
| 26 | using HeuristicLab.Core;
|
---|
| 27 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
|
---|
| 28 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 29 | namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
|
---|
| 30 | [StorableClass]
|
---|
[6284] | 31 | [Item("MwDruGrammar", "Represents a grammar for modeling with fixed structures for the voest B1 MwDru target variable.")]
|
---|
| 32 | public class MwDruGrammar : SymbolicExpressionGrammar, ISymbolicDataAnalysisGrammar {
|
---|
[5333] | 33 |
|
---|
| 34 | [StorableConstructor]
|
---|
[6284] | 35 | protected MwDruGrammar(bool deserializing) : base(deserializing) { }
|
---|
| 36 | protected MwDruGrammar(MwDruGrammar original, Cloner cloner) : base(original, cloner) { }
|
---|
| 37 | public MwDruGrammar()
|
---|
| 38 | : base(ItemAttribute.GetName(typeof(MwDruGrammar)), ItemAttribute.GetDescription(typeof(TypeCoherentExpressionGrammar))) {
|
---|
[5333] | 39 | Initialize();
|
---|
| 40 | }
|
---|
| 41 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
[6284] | 42 | return new MwDruGrammar(this, cloner);
|
---|
[5333] | 43 | }
|
---|
| 44 |
|
---|
[6284] | 45 | private HeuristicLab.Problems.DataAnalysis.Symbolic.Variable ggDru;
|
---|
| 46 | private HeuristicLab.Problems.DataAnalysis.Symbolic.Variable flamTmp;
|
---|
| 47 |
|
---|
[5333] | 48 | private void Initialize() {
|
---|
| 49 | var add = new Addition();
|
---|
| 50 | var sub = new Subtraction();
|
---|
| 51 | var mul = new Multiplication();
|
---|
| 52 | var div = new Division();
|
---|
| 53 | var log = new Logarithm();
|
---|
| 54 | var exp = new Exponential();
|
---|
[5393] | 55 |
|
---|
[5333] | 56 | var constant = new Constant();
|
---|
| 57 | constant.MinValue = -20;
|
---|
| 58 | constant.MaxValue = 20;
|
---|
[5574] | 59 | var variableSymbol = new HeuristicLab.Problems.DataAnalysis.Symbolic.Variable();
|
---|
[5333] | 60 |
|
---|
[6284] | 61 | var fixedAdd1 = new Addition();
|
---|
| 62 | fixedAdd1.Name = "fixed Addition 1";
|
---|
| 63 | fixedAdd1.Fixed = true;
|
---|
[5333] | 64 |
|
---|
[6284] | 65 | var fixedAdd2 = new Addition();
|
---|
| 66 | fixedAdd2.Name = "fixed Addition 2";
|
---|
| 67 | fixedAdd2.Fixed = true;
|
---|
[5333] | 68 |
|
---|
[6284] | 69 | var fixedMul = new Multiplication();
|
---|
| 70 | fixedMul.Name = "fixed Multiplication";
|
---|
| 71 | fixedMul.Fixed = true;
|
---|
[5333] | 72 |
|
---|
[6284] | 73 | ggDru = new HeuristicLab.Problems.DataAnalysis.Symbolic.Variable();
|
---|
| 74 | ggDru.Name = "fixed Variable GGDru";
|
---|
| 75 | ggDru.Fixed = true;
|
---|
| 76 | ggDru.VariableNames = new List<string>() { "GGDRU" };
|
---|
| 77 | ggDru.WeightManipulatorMu = 1;
|
---|
| 78 | ggDru.WeightManipulatorSigma = 0;
|
---|
| 79 | ggDru.WeightMu = 1;
|
---|
| 80 | ggDru.WeightSigma = 0;
|
---|
| 81 | ggDru.MultiplicativeWeightManipulatorSigma = 0;
|
---|
| 82 | ggDru.Changed += new EventHandler(ggDru_Changed);
|
---|
[5333] | 83 |
|
---|
[6284] | 84 | flamTmp = new HeuristicLab.Problems.DataAnalysis.Symbolic.Variable();
|
---|
| 85 | flamTmp.Name = "fixed Variable FlamTmp";
|
---|
| 86 | flamTmp.Fixed = true;
|
---|
| 87 | flamTmp.VariableNames = new List<string>() { "FLAMTMP" };
|
---|
| 88 | flamTmp.WeightManipulatorMu = 1;
|
---|
| 89 | flamTmp.WeightManipulatorSigma = 0;
|
---|
| 90 | flamTmp.WeightMu = 1;
|
---|
| 91 | flamTmp.WeightSigma = 0;
|
---|
| 92 | flamTmp.MultiplicativeWeightManipulatorSigma = 0;
|
---|
| 93 | flamTmp.Changed += new EventHandler(flamTmp_Changed);
|
---|
[5333] | 94 |
|
---|
[6284] | 95 | var c273 = new Constant();
|
---|
| 96 | c273.Name = "fixed Constant 273";
|
---|
| 97 | c273.Fixed = true;
|
---|
| 98 | c273.MinValue = 273;
|
---|
| 99 | c273.MaxValue = 273;
|
---|
| 100 | c273.ManipulatorMu = 0;
|
---|
| 101 | c273.ManipulatorSigma = 0;
|
---|
| 102 | c273.MultiplicativeManipulatorSigma = 0;
|
---|
| 103 |
|
---|
| 104 | var allSymbols = new List<Symbol>()
|
---|
| 105 | { add, sub, mul, div, log, exp, constant, variableSymbol,
|
---|
| 106 | fixedAdd1,fixedAdd2,fixedMul,ggDru,flamTmp,c273};
|
---|
| 107 |
|
---|
| 108 | var unaryFunctionSymbols = new List<Symbol>() { log, exp };
|
---|
| 109 | var binaryFunctionSymbols = new List<Symbol>() { add, sub, mul, div };
|
---|
| 110 |
|
---|
| 111 | var terminalSymbols = new List<Symbol>() { variableSymbol, constant };
|
---|
| 112 | var fixedTerminalSymbols = new List<Symbol>() { ggDru, flamTmp, c273 };
|
---|
| 113 | var realValuedSymbols = unaryFunctionSymbols.Concat(binaryFunctionSymbols).Concat(terminalSymbols);
|
---|
| 114 |
|
---|
[5333] | 115 | foreach (var symb in allSymbols)
|
---|
| 116 | AddSymbol(symb);
|
---|
[6284] | 117 | foreach (var terminalSymbol in terminalSymbols) {
|
---|
| 118 | SetSubtreeCount(terminalSymbol, 0, 0);
|
---|
| 119 | }
|
---|
| 120 | foreach (var terminalSymbol in fixedTerminalSymbols) {
|
---|
| 121 | SetSubtreeCount(terminalSymbol, 0, 0);
|
---|
| 122 | }
|
---|
| 123 | foreach (var unaryFun in unaryFunctionSymbols) {
|
---|
[5686] | 124 | SetSubtreeCount(unaryFun, 1, 1);
|
---|
[5333] | 125 | }
|
---|
[6284] | 126 | foreach (var binaryFun in binaryFunctionSymbols) {
|
---|
[5686] | 127 | SetSubtreeCount(binaryFun, 2, 2);
|
---|
[5333] | 128 | }
|
---|
| 129 |
|
---|
[6284] | 130 | SetSubtreeCount(fixedAdd1, 3, 3);
|
---|
| 131 | SetSubtreeCount(fixedMul, 3, 3);
|
---|
| 132 | SetSubtreeCount(fixedAdd2, 2, 2);
|
---|
[5333] | 133 |
|
---|
[6284] | 134 | AddAllowedChildSymbol(StartSymbol, fixedAdd1);
|
---|
[5333] | 135 |
|
---|
[6284] | 136 | AddAllowedChildSymbol(fixedAdd1, fixedMul, 0);
|
---|
| 137 | AddAllowedChildSymbol(fixedAdd1, ggDru, 1);
|
---|
| 138 | foreach (var symb in unaryFunctionSymbols.Concat(binaryFunctionSymbols).Concat(terminalSymbols))
|
---|
| 139 | AddAllowedChildSymbol(fixedAdd1, symb, 2);
|
---|
[5333] | 140 |
|
---|
[6284] | 141 | AddAllowedChildSymbol(fixedMul, constant, 0);
|
---|
| 142 | AddAllowedChildSymbol(fixedMul, fixedAdd2, 1);
|
---|
| 143 | foreach (var symb in realValuedSymbols)
|
---|
| 144 | AddAllowedChildSymbol(fixedMul, symb, 2);
|
---|
[5333] | 145 |
|
---|
[6284] | 146 | AddAllowedChildSymbol(fixedAdd2, c273, 0);
|
---|
| 147 | AddAllowedChildSymbol(fixedAdd2, flamTmp, 1);
|
---|
| 148 |
|
---|
[5333] | 149 | foreach (var symb in unaryFunctionSymbols) {
|
---|
| 150 | foreach (var childSymb in realValuedSymbols) {
|
---|
[5686] | 151 | AddAllowedChildSymbol(symb, childSymb);
|
---|
[5333] | 152 | }
|
---|
| 153 | }
|
---|
| 154 |
|
---|
| 155 | foreach (var symb in binaryFunctionSymbols) {
|
---|
| 156 | foreach (var childSymb in realValuedSymbols) {
|
---|
[5686] | 157 | AddAllowedChildSymbol(symb, childSymb);
|
---|
[5333] | 158 | }
|
---|
| 159 | }
|
---|
[6284] | 160 | }
|
---|
[5333] | 161 |
|
---|
[6284] | 162 | private void flamTmp_Changed(object sender, System.EventArgs e) {
|
---|
| 163 | if (flamTmp.VariableNames.Count() != 1 || flamTmp.VariableNames.ElementAt(0) != "FLAMTMP")
|
---|
| 164 | flamTmp.VariableNames = new List<string>() { "FLAMTMP" };
|
---|
| 165 | }
|
---|
[5333] | 166 |
|
---|
[6284] | 167 | private void ggDru_Changed(object sender, System.EventArgs e) {
|
---|
| 168 | if (ggDru.VariableNames.Count() != 1 || ggDru.VariableNames.ElementAt(0) != "GGDRU")
|
---|
| 169 | ggDru.VariableNames = new List<string>() { "GGDRU" };
|
---|
[5333] | 170 | }
|
---|
| 171 | }
|
---|
| 172 | }
|
---|