1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2019 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 |
|
---|
22 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
|
---|
23 | using System;
|
---|
24 | using System.Collections.Generic;
|
---|
25 |
|
---|
26 | namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
|
---|
27 | public static class OpCode {
|
---|
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;
|
---|
84 | public const byte XOR = 45;
|
---|
85 | public const byte FactorVariable = 46;
|
---|
86 | public const byte BinaryFactorVariable = 47;
|
---|
87 | public const byte Absolute = 48;
|
---|
88 | public const byte AnalyticQuotient = 49;
|
---|
89 | public const byte Cube = 50;
|
---|
90 | public const byte CubeRoot = 51;
|
---|
91 |
|
---|
92 | public const byte Tanh = 52;
|
---|
93 | public const byte TreeModel = 53;
|
---|
94 |
|
---|
95 |
|
---|
96 | private static Dictionary<Type, byte> symbolToOpcode = new Dictionary<Type, byte>() {
|
---|
97 | { typeof(Addition), OpCode.Add },
|
---|
98 | { typeof(Subtraction), OpCode.Sub },
|
---|
99 | { typeof(Multiplication), OpCode.Mul },
|
---|
100 | { typeof(Division), OpCode.Div },
|
---|
101 | { typeof(Sine), OpCode.Sin },
|
---|
102 | { typeof(Cosine), OpCode.Cos },
|
---|
103 | { typeof(Tangent), OpCode.Tan },
|
---|
104 | { typeof (HyperbolicTangent), OpCode.Tanh},
|
---|
105 | { typeof(Logarithm), OpCode.Log },
|
---|
106 | { typeof(Exponential), OpCode.Exp },
|
---|
107 | { typeof(IfThenElse), OpCode.IfThenElse },
|
---|
108 | { typeof(GreaterThan), OpCode.GT },
|
---|
109 | { typeof(LessThan), OpCode.LT },
|
---|
110 | { typeof(And), OpCode.AND },
|
---|
111 | { typeof(Or), OpCode.OR },
|
---|
112 | { typeof(Not), OpCode.NOT},
|
---|
113 | { typeof(Xor),OpCode.XOR},
|
---|
114 | { typeof(Average), OpCode.Average},
|
---|
115 | { typeof(InvokeFunction), OpCode.Call },
|
---|
116 | { typeof(Variable), OpCode.Variable },
|
---|
117 | { typeof(LaggedVariable), OpCode.LagVariable },
|
---|
118 | { typeof(AutoregressiveTargetVariable),OpCode.LagVariable},
|
---|
119 | { typeof(Constant), OpCode.Constant },
|
---|
120 | { typeof(TreeModel), OpCode.TreeModel },
|
---|
121 | { typeof(Argument), OpCode.Arg },
|
---|
122 | { typeof(Power),OpCode.Power},
|
---|
123 | { typeof(Root),OpCode.Root},
|
---|
124 | { typeof(TimeLag), OpCode.TimeLag},
|
---|
125 | { typeof(Integral), OpCode.Integral},
|
---|
126 | { typeof(Derivative), OpCode.Derivative},
|
---|
127 | { typeof(VariableCondition),OpCode.VariableCondition},
|
---|
128 | { typeof(Square),OpCode.Square},
|
---|
129 | { typeof(SquareRoot),OpCode.SquareRoot},
|
---|
130 | { typeof(Gamma), OpCode.Gamma },
|
---|
131 | { typeof(Psi), OpCode.Psi },
|
---|
132 | { typeof(Dawson), OpCode.Dawson},
|
---|
133 | { typeof(ExponentialIntegralEi), OpCode.ExponentialIntegralEi },
|
---|
134 | { typeof(CosineIntegral), OpCode.CosineIntegral },
|
---|
135 | { typeof(SineIntegral), OpCode.SineIntegral },
|
---|
136 | { typeof(HyperbolicCosineIntegral), OpCode.HyperbolicCosineIntegral },
|
---|
137 | { typeof(HyperbolicSineIntegral), OpCode.HyperbolicSineIntegral },
|
---|
138 | { typeof(FresnelCosineIntegral), OpCode.FresnelCosineIntegral },
|
---|
139 | { typeof(FresnelSineIntegral), OpCode.FresnelSineIntegral },
|
---|
140 | { typeof(AiryA), OpCode.AiryA },
|
---|
141 | { typeof(AiryB), OpCode.AiryB },
|
---|
142 | { typeof(Norm), OpCode.Norm},
|
---|
143 | { typeof(Erf), OpCode.Erf},
|
---|
144 | { typeof(Bessel), OpCode.Bessel},
|
---|
145 | { typeof(FactorVariable), OpCode.FactorVariable },
|
---|
146 | { typeof(BinaryFactorVariable), OpCode.BinaryFactorVariable },
|
---|
147 | { typeof(Absolute), OpCode.Absolute },
|
---|
148 | { typeof(AnalyticQuotient), OpCode.AnalyticQuotient },
|
---|
149 | { typeof(Cube), OpCode.Cube },
|
---|
150 | { typeof(CubeRoot), OpCode.CubeRoot }
|
---|
151 | };
|
---|
152 |
|
---|
153 | public static byte MapSymbolToOpCode(ISymbolicExpressionTreeNode treeNode) {
|
---|
154 | byte opCode;
|
---|
155 | if (symbolToOpcode.TryGetValue(treeNode.Symbol.GetType(), out opCode)) return opCode;
|
---|
156 | else throw new NotSupportedException("Symbol: " + treeNode.Symbol);
|
---|
157 | }
|
---|
158 | }
|
---|
159 | }
|
---|