source: trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/MctsSymbolicRegression/Disassembler.cs @ 13645

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

#2581: added an MCTS for symbolic regression models

File size: 2.1 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 * and the BEACON Center for the Study of Evolution in Action.
5 *
6 * This file is part of HeuristicLab.
7 *
8 * HeuristicLab is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * HeuristicLab is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
20 */
21#endregion
22
23using System.Text;
24
25namespace HeuristicLab.Algorithms.DataAnalysis.MctsSymbolicRegression {
26#if DEBUG
27  internal class Disassembler {
28    public static string CodeToString(byte[] code, double[] consts) {
29      var sb = new StringBuilder();
30      int pc = 0;
31      int nextParamIdx = -1;
32      while (code[pc] != (byte)OpCodes.Exit) {
33        var op = code[pc++];
34        switch (op) {
35          case (byte)OpCodes.Add: sb.Append(" + "); break;
36          case (byte)OpCodes.Mul: sb.Append(" * "); break;
37          case (byte)OpCodes.LoadConst1: sb.Append(" 1 "); break;
38          case (byte)OpCodes.LoadConst0: sb.Append(" 0 "); break;
39          case (byte)OpCodes.LoadParamN: sb.AppendFormat(" {0:N3} ", consts[++nextParamIdx]); break;
40          case (byte)OpCodes.LoadVar:
41          {
42              short arg = (short)(((short)code[pc] << 8) | (short)code[pc + 1]);
43              pc += 2;
44            sb.AppendFormat(" var{0} ", arg); break;
45          }
46          case (byte)OpCodes.Exp: sb.Append(" exp "); break;
47          case (byte)OpCodes.Log: sb.Append(" log "); break;
48          case (byte)OpCodes.Inv: sb.Append(" inv "); break;         
49        }
50      }
51      return sb.ToString();
52    }
53  }
54#endif
55}
Note: See TracBrowser for help on using the repository browser.