Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/OpCodes.cs @ 18242

Last change on this file since 18242 was 18220, checked in by gkronber, 3 years ago

#3136: reintegrated structure-template GP branch into trunk

File size: 8.1 KB
RevLine 
[8431]1#region License Information
2/* HeuristicLab
[17180]3 * Copyright (C) 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
22using System;
23using System.Collections.Generic;
24using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
25
26namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
[16762]27  public enum OpCode : byte {
28    Add = 1,
29    Sub = 2,
30    Mul = 3,
31    Div = 4,
32    Sin = 5,
33    Cos = 6,
34    Tan = 7,
35    Log = 8,
36    Exp = 9,
37    IfThenElse = 10,
38    GT = 11,
39    LT = 12,
40    AND = 13,
41    OR = 14,
42    NOT = 15,
43    Average = 16,
44    Call = 17,
45    Variable = 18,
46    LagVariable = 19,
[18132]47    Number = 20,
[16762]48    Arg = 21,
49    Power = 22,
50    Root = 23,
51    TimeLag = 24,
52    Integral = 25,
53    Derivative = 26,
54    VariableCondition = 27,
55    Square = 28,
56    SquareRoot = 29,
57    Gamma = 30,
58    Psi = 31,
59    Dawson = 32,
60    ExponentialIntegralEi = 33,
61    CosineIntegral = 34,
62    SineIntegral = 35,
63    HyperbolicCosineIntegral = 36,
64    HyperbolicSineIntegral = 37,
65    FresnelCosineIntegral = 38,
66    FresnelSineIntegral = 39,
67    AiryA = 40,
68    AiryB = 41,
69    Norm = 42,
70    Erf = 43,
71    Bessel = 44,
72    XOR = 45,
73    FactorVariable = 46,
74    BinaryFactorVariable = 47,
75    Absolute = 48,
76    AnalyticQuotient = 49,
77    Cube = 50,
78    CubeRoot = 51,
79    Tanh = 52,
[18220]80    SubFunction = 53,
[18160]81    Constant = 54
[16762]82  };
[8431]83  public static class OpCodes {
[16762]84    // constants for API compatibility only
85    public const byte Add = (byte)OpCode.Add;
[18220]86    public const byte Sub = (byte)OpCode.Sub;
87    public const byte Mul = (byte)OpCode.Mul;
88    public const byte Div = (byte)OpCode.Div;
89    public const byte Sin = (byte)OpCode.Sin;
90    public const byte Cos = (byte)OpCode.Cos;
91    public const byte Tan = (byte)OpCode.Tan;
92    public const byte Log = (byte)OpCode.Log;
[16762]93    public const byte Exp = (byte)OpCode.Exp;
94    public const byte IfThenElse = (byte)OpCode.IfThenElse;
95    public const byte GT = (byte)OpCode.GT;
96    public const byte LT = (byte)OpCode.LT;
97    public const byte AND = (byte)OpCode.AND;
98    public const byte OR = (byte)OpCode.OR;
99    public const byte NOT = (byte)OpCode.NOT;
100    public const byte Average = (byte)OpCode.Average;
101    public const byte Call = (byte)OpCode.Call;
102    public const byte Variable = (byte)OpCode.Variable;
103    public const byte LagVariable = (byte)OpCode.LagVariable;
[18132]104    public const byte Number = (byte)OpCode.Number;
[18220]105    public const byte Constant = (byte)OpCode.Constant;
[16762]106    public const byte Arg = (byte)OpCode.Arg;
107    public const byte Power = (byte)OpCode.Power;
108    public const byte Root = (byte)OpCode.Root;
109    public const byte TimeLag = (byte)OpCode.TimeLag;
110    public const byte Integral = (byte)OpCode.Integral;
111    public const byte Derivative = (byte)OpCode.Derivative;
112    public const byte VariableCondition = (byte)OpCode.VariableCondition;
113    public const byte Square = (byte)OpCode.Square;
114    public const byte SquareRoot = (byte)OpCode.SquareRoot;
115    public const byte Gamma = (byte)OpCode.Gamma;
116    public const byte Psi = (byte)OpCode.Psi;
117    public const byte Dawson = (byte)OpCode.Dawson;
118    public const byte ExponentialIntegralEi = (byte)OpCode.ExponentialIntegralEi;
119    public const byte CosineIntegral = (byte)OpCode.CosineIntegral;
120    public const byte SineIntegral = (byte)OpCode.SineIntegral;
121    public const byte HyperbolicCosineIntegral = (byte)OpCode.HyperbolicCosineIntegral;
122    public const byte HyperbolicSineIntegral = (byte)OpCode.HyperbolicSineIntegral;
123    public const byte FresnelCosineIntegral = (byte)OpCode.FresnelCosineIntegral;
124    public const byte FresnelSineIntegral = (byte)OpCode.FresnelSineIntegral;
125    public const byte AiryA = (byte)OpCode.AiryA;
126    public const byte AiryB = (byte)OpCode.AiryB;
127    public const byte Norm = (byte)OpCode.Norm;
128    public const byte Erf = (byte)OpCode.Erf;
129    public const byte Bessel = (byte)OpCode.Bessel;
130    public const byte XOR = (byte)OpCode.XOR;
131    public const byte FactorVariable = (byte)OpCode.FactorVariable;
132    public const byte BinaryFactorVariable = (byte)OpCode.BinaryFactorVariable;
133    public const byte Absolute = (byte)OpCode.Absolute;
134    public const byte AnalyticQuotient = (byte)OpCode.AnalyticQuotient;
135    public const byte Cube = (byte)OpCode.Cube;
136    public const byte CubeRoot = (byte)OpCode.CubeRoot;
137    public const byte Tanh = (byte)OpCode.Tanh;
[18220]138    public const byte SubFunction = (byte)OpCode.SubFunction;
[8431]139
140    private static Dictionary<Type, byte> symbolToOpcode = new Dictionary<Type, byte>() {
[18220]141      { typeof(Addition), OpCodes.Add },
[8431]142      { typeof(Subtraction), OpCodes.Sub },
143      { typeof(Multiplication), OpCodes.Mul },
144      { typeof(Division), OpCodes.Div },
145      { typeof(Sine), OpCodes.Sin },
146      { typeof(Cosine), OpCodes.Cos },
147      { typeof(Tangent), OpCodes.Tan },
[17963]148      { typeof(HyperbolicTangent), OpCodes.Tanh},
[8431]149      { typeof(Logarithm), OpCodes.Log },
150      { typeof(Exponential), OpCodes.Exp },
151      { typeof(IfThenElse), OpCodes.IfThenElse },
152      { typeof(GreaterThan), OpCodes.GT },
153      { typeof(LessThan), OpCodes.LT },
154      { typeof(And), OpCodes.AND },
155      { typeof(Or), OpCodes.OR },
156      { typeof(Not), OpCodes.NOT},
[10774]157      { typeof(Xor),OpCodes.XOR},
[8431]158      { typeof(Average), OpCodes.Average},
159      { typeof(InvokeFunction), OpCodes.Call },
160      { typeof(Variable), OpCodes.Variable },
161      { typeof(LaggedVariable), OpCodes.LagVariable },
[8477]162      { typeof(AutoregressiveTargetVariable),OpCodes.LagVariable},
[18132]163      { typeof(Number), OpCodes.Number },
[8431]164      { typeof(Constant), OpCodes.Constant },
165      { typeof(Argument), OpCodes.Arg },
166      { typeof(Power),OpCodes.Power},
167      { typeof(Root),OpCodes.Root},
[16356]168      { typeof(TimeLag), OpCodes.TimeLag},
[8431]169      { typeof(Integral), OpCodes.Integral},
170      { typeof(Derivative), OpCodes.Derivative},
171      { typeof(VariableCondition),OpCodes.VariableCondition},
172      { typeof(Square),OpCodes.Square},
173      { typeof(SquareRoot),OpCodes.SquareRoot},
174      { typeof(Gamma), OpCodes.Gamma },
175      { typeof(Psi), OpCodes.Psi },
176      { typeof(Dawson), OpCodes.Dawson},
177      { typeof(ExponentialIntegralEi), OpCodes.ExponentialIntegralEi },
178      { typeof(CosineIntegral), OpCodes.CosineIntegral },
179      { typeof(SineIntegral), OpCodes.SineIntegral },
180      { typeof(HyperbolicCosineIntegral), OpCodes.HyperbolicCosineIntegral },
181      { typeof(HyperbolicSineIntegral), OpCodes.HyperbolicSineIntegral },
182      { typeof(FresnelCosineIntegral), OpCodes.FresnelCosineIntegral },
183      { typeof(FresnelSineIntegral), OpCodes.FresnelSineIntegral },
184      { typeof(AiryA), OpCodes.AiryA },
185      { typeof(AiryB), OpCodes.AiryB },
186      { typeof(Norm), OpCodes.Norm},
187      { typeof(Erf), OpCodes.Erf},
[14826]188      { typeof(Bessel), OpCodes.Bessel},
189      { typeof(FactorVariable), OpCodes.FactorVariable },
[16356]190      { typeof(BinaryFactorVariable), OpCodes.BinaryFactorVariable },
191      { typeof(Absolute), OpCodes.Absolute },
[16360]192      { typeof(AnalyticQuotient), OpCodes.AnalyticQuotient },
[16356]193      { typeof(Cube), OpCodes.Cube },
[18220]194      { typeof(CubeRoot), OpCodes.CubeRoot },
195      { typeof(SubFunctionSymbol), OpCodes.SubFunction }
[8431]196    };
197
198    public static byte MapSymbolToOpCode(ISymbolicExpressionTreeNode treeNode) {
[16762]199      if (symbolToOpcode.TryGetValue(treeNode.Symbol.GetType(), out byte opCode)) return opCode;
[8431]200      else throw new NotSupportedException("Symbol: " + treeNode.Symbol);
201    }
202  }
203}
Note: See TracBrowser for help on using the repository browser.