[8431] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[16565] | 3 | * Copyright (C) 2002-2019 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[8431] | 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 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.Collections.Generic;
|
---|
| 24 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
|
---|
| 25 |
|
---|
| 26 | namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
|
---|
| 27 | public static class OpCodes {
|
---|
| 28 | public const byte Add = 1;
|
---|
| 29 | public const byte Sub = 2;
|
---|
| 30 | public const byte Mul = 3;
|
---|
| 31 | public const byte Div = 4;
|
---|
| 32 |
|
---|
| 33 | public const byte Sin = 5;
|
---|
| 34 | public const byte Cos = 6;
|
---|
| 35 | public const byte Tan = 7;
|
---|
| 36 |
|
---|
| 37 | public const byte Log = 8;
|
---|
| 38 | public const byte Exp = 9;
|
---|
| 39 |
|
---|
| 40 | public const byte IfThenElse = 10;
|
---|
| 41 |
|
---|
| 42 | public const byte GT = 11;
|
---|
| 43 | public const byte LT = 12;
|
---|
| 44 |
|
---|
| 45 | public const byte AND = 13;
|
---|
| 46 | public const byte OR = 14;
|
---|
| 47 | public const byte NOT = 15;
|
---|
| 48 |
|
---|
| 49 |
|
---|
| 50 | public const byte Average = 16;
|
---|
| 51 |
|
---|
| 52 | public const byte Call = 17;
|
---|
| 53 |
|
---|
| 54 | public const byte Variable = 18;
|
---|
| 55 | public const byte LagVariable = 19;
|
---|
| 56 | public const byte Constant = 20;
|
---|
| 57 | public const byte Arg = 21;
|
---|
| 58 |
|
---|
| 59 | public const byte Power = 22;
|
---|
| 60 | public const byte Root = 23;
|
---|
| 61 | public const byte TimeLag = 24;
|
---|
| 62 | public const byte Integral = 25;
|
---|
| 63 | public const byte Derivative = 26;
|
---|
| 64 |
|
---|
| 65 | public const byte VariableCondition = 27;
|
---|
| 66 |
|
---|
| 67 | public const byte Square = 28;
|
---|
| 68 | public const byte SquareRoot = 29;
|
---|
| 69 | public const byte Gamma = 30;
|
---|
| 70 | public const byte Psi = 31;
|
---|
| 71 | public const byte Dawson = 32;
|
---|
| 72 | public const byte ExponentialIntegralEi = 33;
|
---|
| 73 | public const byte CosineIntegral = 34;
|
---|
| 74 | public const byte SineIntegral = 35;
|
---|
| 75 | public const byte HyperbolicCosineIntegral = 36;
|
---|
| 76 | public const byte HyperbolicSineIntegral = 37;
|
---|
| 77 | public const byte FresnelCosineIntegral = 38;
|
---|
| 78 | public const byte FresnelSineIntegral = 39;
|
---|
| 79 | public const byte AiryA = 40;
|
---|
| 80 | public const byte AiryB = 41;
|
---|
| 81 | public const byte Norm = 42;
|
---|
| 82 | public const byte Erf = 43;
|
---|
| 83 | public const byte Bessel = 44;
|
---|
[16356] | 84 | public const byte XOR = 45;
|
---|
[14826] | 85 | public const byte FactorVariable = 46;
|
---|
| 86 | public const byte BinaryFactorVariable = 47;
|
---|
[16356] | 87 | public const byte Absolute = 48;
|
---|
[16360] | 88 | public const byte AnalyticQuotient = 49;
|
---|
[16356] | 89 | public const byte Cube = 50;
|
---|
| 90 | public const byte CubeRoot = 51;
|
---|
[8431] | 91 |
|
---|
[16656] | 92 | public const byte Tanh = 52;
|
---|
[14826] | 93 |
|
---|
[16656] | 94 |
|
---|
[8431] | 95 | private static Dictionary<Type, byte> symbolToOpcode = new Dictionary<Type, byte>() {
|
---|
[8436] | 96 | { typeof(Addition), OpCodes.Add },
|
---|
[8431] | 97 | { typeof(Subtraction), OpCodes.Sub },
|
---|
| 98 | { typeof(Multiplication), OpCodes.Mul },
|
---|
| 99 | { typeof(Division), OpCodes.Div },
|
---|
| 100 | { typeof(Sine), OpCodes.Sin },
|
---|
| 101 | { typeof(Cosine), OpCodes.Cos },
|
---|
| 102 | { typeof(Tangent), OpCodes.Tan },
|
---|
[16656] | 103 | { typeof (HyperbolicTangent), OpCodes.Tanh},
|
---|
[8431] | 104 | { typeof(Logarithm), OpCodes.Log },
|
---|
| 105 | { typeof(Exponential), OpCodes.Exp },
|
---|
| 106 | { typeof(IfThenElse), OpCodes.IfThenElse },
|
---|
| 107 | { typeof(GreaterThan), OpCodes.GT },
|
---|
| 108 | { typeof(LessThan), OpCodes.LT },
|
---|
| 109 | { typeof(And), OpCodes.AND },
|
---|
| 110 | { typeof(Or), OpCodes.OR },
|
---|
| 111 | { typeof(Not), OpCodes.NOT},
|
---|
[10774] | 112 | { typeof(Xor),OpCodes.XOR},
|
---|
[8431] | 113 | { typeof(Average), OpCodes.Average},
|
---|
| 114 | { typeof(InvokeFunction), OpCodes.Call },
|
---|
| 115 | { typeof(Variable), OpCodes.Variable },
|
---|
| 116 | { typeof(LaggedVariable), OpCodes.LagVariable },
|
---|
[8477] | 117 | { typeof(AutoregressiveTargetVariable),OpCodes.LagVariable},
|
---|
[8431] | 118 | { typeof(Constant), OpCodes.Constant },
|
---|
| 119 | { typeof(Argument), OpCodes.Arg },
|
---|
| 120 | { typeof(Power),OpCodes.Power},
|
---|
| 121 | { typeof(Root),OpCodes.Root},
|
---|
[16356] | 122 | { typeof(TimeLag), OpCodes.TimeLag},
|
---|
[8431] | 123 | { typeof(Integral), OpCodes.Integral},
|
---|
| 124 | { typeof(Derivative), OpCodes.Derivative},
|
---|
| 125 | { typeof(VariableCondition),OpCodes.VariableCondition},
|
---|
| 126 | { typeof(Square),OpCodes.Square},
|
---|
| 127 | { typeof(SquareRoot),OpCodes.SquareRoot},
|
---|
| 128 | { typeof(Gamma), OpCodes.Gamma },
|
---|
| 129 | { typeof(Psi), OpCodes.Psi },
|
---|
| 130 | { typeof(Dawson), OpCodes.Dawson},
|
---|
| 131 | { typeof(ExponentialIntegralEi), OpCodes.ExponentialIntegralEi },
|
---|
| 132 | { typeof(CosineIntegral), OpCodes.CosineIntegral },
|
---|
| 133 | { typeof(SineIntegral), OpCodes.SineIntegral },
|
---|
| 134 | { typeof(HyperbolicCosineIntegral), OpCodes.HyperbolicCosineIntegral },
|
---|
| 135 | { typeof(HyperbolicSineIntegral), OpCodes.HyperbolicSineIntegral },
|
---|
| 136 | { typeof(FresnelCosineIntegral), OpCodes.FresnelCosineIntegral },
|
---|
| 137 | { typeof(FresnelSineIntegral), OpCodes.FresnelSineIntegral },
|
---|
| 138 | { typeof(AiryA), OpCodes.AiryA },
|
---|
| 139 | { typeof(AiryB), OpCodes.AiryB },
|
---|
| 140 | { typeof(Norm), OpCodes.Norm},
|
---|
| 141 | { typeof(Erf), OpCodes.Erf},
|
---|
[14826] | 142 | { typeof(Bessel), OpCodes.Bessel},
|
---|
| 143 | { typeof(FactorVariable), OpCodes.FactorVariable },
|
---|
[16356] | 144 | { typeof(BinaryFactorVariable), OpCodes.BinaryFactorVariable },
|
---|
| 145 | { typeof(Absolute), OpCodes.Absolute },
|
---|
[16360] | 146 | { typeof(AnalyticQuotient), OpCodes.AnalyticQuotient },
|
---|
[16356] | 147 | { typeof(Cube), OpCodes.Cube },
|
---|
| 148 | { typeof(CubeRoot), OpCodes.CubeRoot }
|
---|
[8431] | 149 | };
|
---|
| 150 |
|
---|
| 151 | public static byte MapSymbolToOpCode(ISymbolicExpressionTreeNode treeNode) {
|
---|
| 152 | byte opCode;
|
---|
| 153 | if (symbolToOpcode.TryGetValue(treeNode.Symbol.GetType(), out opCode)) return opCode;
|
---|
| 154 | else throw new NotSupportedException("Symbol: " + treeNode.Symbol);
|
---|
| 155 | }
|
---|
| 156 | }
|
---|
| 157 | }
|
---|