Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/OpCodes.cs @ 18071

Last change on this file since 18071 was 18071, checked in by dpiringe, 3 years ago

#3136

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