Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/OpCodes.cs @ 14576

Last change on this file since 14576 was 14312, checked in by bburlacu, 8 years ago

#1772: Merge trunk changes. Delete unnecessary files (sliding window).

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