Changeset 15437 for branches/MCTS-SymbReg-2796/HeuristicLab.Algorithms.DataAnalysis/3.4/MctsSymbolicRegression/Automaton.cs
- Timestamp:
- 10/27/17 18:42:04 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/MCTS-SymbReg-2796/HeuristicLab.Algorithms.DataAnalysis/3.4/MctsSymbolicRegression/Automaton.cs
r15420 r15437 43 43 // 44 44 internal class Automaton { 45 // TODO: refactor so that State is an enumerable type46 45 47 46 // there is a single final state (ExprEnd) 48 47 // states with lower values are closer to the final state 49 48 // (this is helpful when we try to navigate to the final state) 49 50 // we cannot use an enum type here because the set of states is dynamic (including states for variables) 50 51 public const int StateExprEnd = 1; 51 52 public const int StateTermEnd = 2; … … 81 82 public const int FirstDynamicState = 25; 82 83 // more states for individual variables are created dynamically 84 public readonly List<string> stateNames = new List<string>() { 85 string.Empty, 86 "ExprEnd", 87 "TermEnd", 88 "FactorEnd", 89 "VariableFactorEnd", 90 "ExpFactorEnd", 91 "LogFactorEnd", 92 "InvFactorEnd", 93 "ExpFEnd", 94 "LogTEnd", 95 "InvTEnd", 96 "LogTFEnd", 97 "InfTFEnd", 98 "LogTFStart", 99 "InvTFStart", 100 "ExpFStart", 101 "LogTStart", 102 "InvTStart", 103 "VariableFactorStart", 104 "ExpFactorStart", 105 "LogFactorStart", 106 "InvFactorStart", 107 "FactorStart", 108 "TermStart", 109 "Expr", 110 }; 111 83 112 84 113 private const int StartState = StateExpr; 85 114 public int CurrentState { get; private set; } 86 115 87 public readonly List<string> stateNames;88 116 private List<int>[] followStates; 89 117 private List<Action>[,] actions; // not every follow state is possible but this representation should be efficient … … 99 127 bool allowMultipleTerms = false) { 100 128 int nVars = vars.Length; 101 stateNames = new List<string>() { string.Empty, "Expr", "ExprEnd", "TermStart", "TermEnd", "FactorStart", "FactorEnd", "VarFactorStart", "VarFactorEnd", "ExpFactorStart", "ExpFactorEnd", "LogFactorStart", "LogFactorEnd", "InvFactorStart", "InvFactorEnd", "ExpFStart", "ExpFEnd", "LogTStart", "LogTEnd", "LogTFStart", "LogTFEnd", "InvTStart", "InvTEnd", "InvTFStart", "InvTFEnd" };102 129 codeGenerator = new CodeGenerator(); 103 130 this.constraintHandler = constraintHandler; … … 369 396 } 370 397 371 private readonly int[] followStatesBuf = new int[1000]; 372 public void FollowStates(int state, out int[] buf, out int nElements) { 398 public void FollowStates(int state, ref int[] buf, out int nElements) { 373 399 var fs = followStates[state]; 374 400 int j = 0; … … 376 402 var s = fs[i]; 377 403 if (constraintHandler.IsAllowedFollowState(state, s)) { 378 followStatesBuf[j++] = s;404 buf[j++] = s; 379 405 } 380 406 } 381 buf = followStatesBuf;382 407 nElements = j; 383 408 } … … 446 471 447 472 internal string GetActionString(int fromState, int toState) { 448 return actionStrings[fromState, toState] != null ? string.Join(" , ", actionStrings[fromState, toState]) : "";473 return actionStrings[fromState, toState] != null ? string.Join(" , ", actionStrings[fromState, toState]) : ""; 449 474 } 450 475 … … 454 479 writer.WriteLine("digraph {"); 455 480 // writer.WriteLine("rankdir=LR"); 456 for (int s = StartState; s < stateNames.Count; s++) {481 for (int s = 1; s < stateNames.Count; s++) { 457 482 for (int i = 0; i < followStates[s].Count; i++) { 458 483 if (followStates[s][i] <= 0) continue;
Note: See TracChangeset
for help on using the changeset viewer.