#region License Information /* HeuristicLab * Copyright (C) 2002-2011 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using System; using System.Collections.Generic; using System.Linq; using HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; namespace HeuristicLab.Problems.DataAnalysis.Symbolic { [StorableClass] [Item("MwDruGrammar", "Represents a grammar for modeling with fixed structures for the voest B1 MwDru target variable.")] public class MwDruGrammar : SymbolicExpressionGrammar, ISymbolicDataAnalysisGrammar { [StorableConstructor] protected MwDruGrammar(bool deserializing) : base(deserializing) { } protected MwDruGrammar(MwDruGrammar original, Cloner cloner) : base(original, cloner) { } public MwDruGrammar() : base(ItemAttribute.GetName(typeof(MwDruGrammar)), ItemAttribute.GetDescription(typeof(TypeCoherentExpressionGrammar))) { Initialize(); } public override IDeepCloneable Clone(Cloner cloner) { return new MwDruGrammar(this, cloner); } private HeuristicLab.Problems.DataAnalysis.Symbolic.Variable ggDru; private HeuristicLab.Problems.DataAnalysis.Symbolic.Variable flamTmp; private void Initialize() { var add = new Addition(); var sub = new Subtraction(); var mul = new Multiplication(); var div = new Division(); var log = new Logarithm(); var exp = new Exponential(); var constant = new Constant(); constant.MinValue = -20; constant.MaxValue = 20; var variableSymbol = new HeuristicLab.Problems.DataAnalysis.Symbolic.Variable(); var fixedAdd1 = new Addition(); fixedAdd1.Name = "fixed Addition 1"; fixedAdd1.Fixed = true; var fixedAdd2 = new Addition(); fixedAdd2.Name = "fixed Addition 2"; fixedAdd2.Fixed = true; var fixedMul = new Multiplication(); fixedMul.Name = "fixed Multiplication"; fixedMul.Fixed = true; ggDru = new HeuristicLab.Problems.DataAnalysis.Symbolic.Variable(); ggDru.Name = "fixed Variable GGDru"; ggDru.Fixed = true; ggDru.VariableNames = new List() { "GGDRU" }; ggDru.WeightManipulatorMu = 1; ggDru.WeightManipulatorSigma = 0; ggDru.WeightMu = 1; ggDru.WeightSigma = 0; ggDru.MultiplicativeWeightManipulatorSigma = 0; ggDru.Changed += new EventHandler(ggDru_Changed); flamTmp = new HeuristicLab.Problems.DataAnalysis.Symbolic.Variable(); flamTmp.Name = "fixed Variable FlamTmp"; flamTmp.Fixed = true; flamTmp.VariableNames = new List() { "FLAMTMP" }; flamTmp.WeightManipulatorMu = 1; flamTmp.WeightManipulatorSigma = 0; flamTmp.WeightMu = 1; flamTmp.WeightSigma = 0; flamTmp.MultiplicativeWeightManipulatorSigma = 0; flamTmp.Changed += new EventHandler(flamTmp_Changed); var c273 = new Constant(); c273.Name = "fixed Constant 273"; c273.Fixed = true; c273.MinValue = 273; c273.MaxValue = 273; c273.ManipulatorMu = 0; c273.ManipulatorSigma = 0; c273.MultiplicativeManipulatorSigma = 0; var allSymbols = new List() { add, sub, mul, div, log, exp, constant, variableSymbol, fixedAdd1,fixedAdd2,fixedMul,ggDru,flamTmp,c273}; var unaryFunctionSymbols = new List() { log, exp }; var binaryFunctionSymbols = new List() { add, sub, mul, div }; var terminalSymbols = new List() { variableSymbol, constant }; var fixedTerminalSymbols = new List() { ggDru, flamTmp, c273 }; var realValuedSymbols = unaryFunctionSymbols.Concat(binaryFunctionSymbols).Concat(terminalSymbols); foreach (var symb in allSymbols) AddSymbol(symb); foreach (var terminalSymbol in terminalSymbols) { SetSubtreeCount(terminalSymbol, 0, 0); } foreach (var terminalSymbol in fixedTerminalSymbols) { SetSubtreeCount(terminalSymbol, 0, 0); } foreach (var unaryFun in unaryFunctionSymbols) { SetSubtreeCount(unaryFun, 1, 1); } foreach (var binaryFun in binaryFunctionSymbols) { SetSubtreeCount(binaryFun, 2, 2); } SetSubtreeCount(fixedAdd1, 3, 3); SetSubtreeCount(fixedMul, 3, 3); SetSubtreeCount(fixedAdd2, 2, 2); AddAllowedChildSymbol(StartSymbol, fixedAdd1); AddAllowedChildSymbol(fixedAdd1, fixedMul, 0); AddAllowedChildSymbol(fixedAdd1, ggDru, 1); foreach (var symb in unaryFunctionSymbols.Concat(binaryFunctionSymbols).Concat(terminalSymbols)) AddAllowedChildSymbol(fixedAdd1, symb, 2); AddAllowedChildSymbol(fixedMul, constant, 0); AddAllowedChildSymbol(fixedMul, fixedAdd2, 1); foreach (var symb in realValuedSymbols) AddAllowedChildSymbol(fixedMul, symb, 2); AddAllowedChildSymbol(fixedAdd2, c273, 0); AddAllowedChildSymbol(fixedAdd2, flamTmp, 1); foreach (var symb in unaryFunctionSymbols) { foreach (var childSymb in realValuedSymbols) { AddAllowedChildSymbol(symb, childSymb); } } foreach (var symb in binaryFunctionSymbols) { foreach (var childSymb in realValuedSymbols) { AddAllowedChildSymbol(symb, childSymb); } } } private void flamTmp_Changed(object sender, System.EventArgs e) { if (flamTmp.VariableNames.Count() != 1 || flamTmp.VariableNames.ElementAt(0) != "FLAMTMP") flamTmp.VariableNames = new List() { "FLAMTMP" }; } private void ggDru_Changed(object sender, System.EventArgs e) { if (ggDru.VariableNames.Count() != 1 || ggDru.VariableNames.ElementAt(0) != "GGDRU") ggDru.VariableNames = new List() { "GGDRU" }; } } }