Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
10/27/17 18:42:04 (7 years ago)
Author:
gkronber
Message:

#2796 comments, simplifications, reviewed tests for structure enumeration (not working)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/MCTS-SymbReg-2796/HeuristicLab.Algorithms.DataAnalysis/3.4/MctsSymbolicRegression/Automaton.cs

    r15420 r15437  
    4343  //
    4444  internal class Automaton {
    45     // TODO: refactor so that State is an enumerable type
    4645
    4746    // there is a single final state (ExprEnd)
    4847    // states with lower values are closer to the final state
    4948    // (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)
    5051    public const int StateExprEnd = 1;
    5152    public const int StateTermEnd = 2;
     
    8182    public const int FirstDynamicState = 25;
    8283    // 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
    83112
    84113    private const int StartState = StateExpr;
    85114    public int CurrentState { get; private set; }
    86115
    87     public readonly List<string> stateNames;
    88116    private List<int>[] followStates;
    89117    private List<Action>[,] actions; // not every follow state is possible but this representation should be efficient
     
    99127       bool allowMultipleTerms = false) {
    100128      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" };
    102129      codeGenerator = new CodeGenerator();
    103130      this.constraintHandler = constraintHandler;
     
    369396    }
    370397
    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) {
    373399      var fs = followStates[state];
    374400      int j = 0;
     
    376402        var s = fs[i];
    377403        if (constraintHandler.IsAllowedFollowState(state, s)) {
    378           followStatesBuf[j++] = s;
     404          buf[j++] = s;
    379405        }
    380406      }
    381       buf = followStatesBuf;
    382407      nElements = j;
    383408    }
     
    446471
    447472    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]) : "";
    449474    }
    450475
     
    454479        writer.WriteLine("digraph {");
    455480        // writer.WriteLine("rankdir=LR");
    456         for (int s = StartState; s < stateNames.Count; s++) {
     481        for (int s = 1; s < stateNames.Count; s++) {
    457482          for (int i = 0; i < followStates[s].Count; i++) {
    458483            if (followStates[s][i] <= 0) continue;
Note: See TracChangeset for help on using the changeset viewer.