Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.LinqExpressionTreeInterpreter/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/OpCodes.cs @ 12807

Last change on this file since 12807 was 12807, checked in by bburlacu, 9 years ago

#2442: Added new interpreter as described above. The new function symbol accepts lambdas in the constructor and gets intitialized with a fixed arity. The MethodInfo of the provided lambda is stored internally and used by the interpreter. The MethodInfo field should be [Storable] but this would require a small change to the serializer (relatively trivial I think). Currently it works with the programmable problem and the SymbolicExpressionTreeEncoding (see attached example).

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