#region License Information /* HeuristicLab * Copyright (C) 2002-2019 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 HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; using System; using System.Collections.Generic; namespace HeuristicLab.Problems.DataAnalysis.Symbolic { public static class OpCode { public const byte Add = 1; public const byte Sub = 2; public const byte Mul = 3; public const byte Div = 4; public const byte Sin = 5; public const byte Cos = 6; public const byte Tan = 7; public const byte Log = 8; public const byte Exp = 9; public const byte IfThenElse = 10; public const byte GT = 11; public const byte LT = 12; public const byte AND = 13; public const byte OR = 14; public const byte NOT = 15; public const byte Average = 16; public const byte Call = 17; public const byte Variable = 18; public const byte LagVariable = 19; public const byte Constant = 20; public const byte Arg = 21; public const byte Power = 22; public const byte Root = 23; public const byte TimeLag = 24; public const byte Integral = 25; public const byte Derivative = 26; public const byte VariableCondition = 27; public const byte Square = 28; public const byte SquareRoot = 29; public const byte Gamma = 30; public const byte Psi = 31; public const byte Dawson = 32; public const byte ExponentialIntegralEi = 33; public const byte CosineIntegral = 34; public const byte SineIntegral = 35; public const byte HyperbolicCosineIntegral = 36; public const byte HyperbolicSineIntegral = 37; public const byte FresnelCosineIntegral = 38; public const byte FresnelSineIntegral = 39; public const byte AiryA = 40; public const byte AiryB = 41; public const byte Norm = 42; public const byte Erf = 43; public const byte Bessel = 44; public const byte XOR = 45; public const byte FactorVariable = 46; public const byte BinaryFactorVariable = 47; public const byte Absolute = 48; public const byte AnalyticQuotient = 49; public const byte Cube = 50; public const byte CubeRoot = 51; public const byte Tanh = 52; public const byte TreeModel = 53; private static Dictionary symbolToOpcode = new Dictionary() { { typeof(Addition), OpCode.Add }, { typeof(Subtraction), OpCode.Sub }, { typeof(Multiplication), OpCode.Mul }, { typeof(Division), OpCode.Div }, { typeof(Sine), OpCode.Sin }, { typeof(Cosine), OpCode.Cos }, { typeof(Tangent), OpCode.Tan }, { typeof (HyperbolicTangent), OpCode.Tanh}, { typeof(Logarithm), OpCode.Log }, { typeof(Exponential), OpCode.Exp }, { typeof(IfThenElse), OpCode.IfThenElse }, { typeof(GreaterThan), OpCode.GT }, { typeof(LessThan), OpCode.LT }, { typeof(And), OpCode.AND }, { typeof(Or), OpCode.OR }, { typeof(Not), OpCode.NOT}, { typeof(Xor),OpCode.XOR}, { typeof(Average), OpCode.Average}, { typeof(InvokeFunction), OpCode.Call }, { typeof(Variable), OpCode.Variable }, { typeof(LaggedVariable), OpCode.LagVariable }, { typeof(AutoregressiveTargetVariable),OpCode.LagVariable}, { typeof(Constant), OpCode.Constant }, { typeof(TreeModel), OpCode.TreeModel }, { typeof(Argument), OpCode.Arg }, { typeof(Power),OpCode.Power}, { typeof(Root),OpCode.Root}, { typeof(TimeLag), OpCode.TimeLag}, { typeof(Integral), OpCode.Integral}, { typeof(Derivative), OpCode.Derivative}, { typeof(VariableCondition),OpCode.VariableCondition}, { typeof(Square),OpCode.Square}, { typeof(SquareRoot),OpCode.SquareRoot}, { typeof(Gamma), OpCode.Gamma }, { typeof(Psi), OpCode.Psi }, { typeof(Dawson), OpCode.Dawson}, { typeof(ExponentialIntegralEi), OpCode.ExponentialIntegralEi }, { typeof(CosineIntegral), OpCode.CosineIntegral }, { typeof(SineIntegral), OpCode.SineIntegral }, { typeof(HyperbolicCosineIntegral), OpCode.HyperbolicCosineIntegral }, { typeof(HyperbolicSineIntegral), OpCode.HyperbolicSineIntegral }, { typeof(FresnelCosineIntegral), OpCode.FresnelCosineIntegral }, { typeof(FresnelSineIntegral), OpCode.FresnelSineIntegral }, { typeof(AiryA), OpCode.AiryA }, { typeof(AiryB), OpCode.AiryB }, { typeof(Norm), OpCode.Norm}, { typeof(Erf), OpCode.Erf}, { typeof(Bessel), OpCode.Bessel}, { typeof(FactorVariable), OpCode.FactorVariable }, { typeof(BinaryFactorVariable), OpCode.BinaryFactorVariable }, { typeof(Absolute), OpCode.Absolute }, { typeof(AnalyticQuotient), OpCode.AnalyticQuotient }, { typeof(Cube), OpCode.Cube }, { typeof(CubeRoot), OpCode.CubeRoot } }; public static byte MapSymbolToOpCode(ISymbolicExpressionTreeNode treeNode) { byte opCode; if (symbolToOpcode.TryGetValue(treeNode.Symbol.GetType(), out opCode)) return opCode; else throw new NotSupportedException("Symbol: " + treeNode.Symbol); } } }