public void addTransition(Transition transition) { KeyValuePair<State, char> key = new KeyValuePair<State, char> (transition.From, transition.Read); if (this.transitionTable.ContainsKey (key) == true) throw new Exception ("It's a nondeterministic turing machine"); this.transitionTable.Add (key, transition); }
public void parse() { bool isStates = false; while (!this.reader.EndOfStream) { string line = reader.ReadLine (); if (line == "states") { isStates = true; continue; } else if (line == "transitions") { isStates = false; continue; } if (isStates) { string[] tokens = line.Split (new char[]{' '}); State state = new State (tokens [0], tokens [1] == "1"); this.states.Add (state.StateID, state); } else { string[] tokens = line.Split (new char[]{' '}); TapeMoves move = TapeMoves.Down; switch (tokens [4][0]) { case 'l': move = TapeMoves.Left; break; case 'r': move = TapeMoves.Right; break; case 'u': move = TapeMoves.Up; break; case 'd': move = TapeMoves.Down; break; case 's': move = TapeMoves.Stable; break; } Transition transition = new Transition (this.states [tokens [0]], this.states [tokens [1]], tokens [2] [0], tokens [3] [0], move); this.transitions.Add (transition); } } }
public void parse() { bool isStates = false; while (!this.reader.EndOfStream) { string line = reader.ReadLine (); if (line == "states") { isStates = true; continue; } else if (line == "transitions") { isStates = false; continue; } if (isStates) { string[] tokens = line.Split (new char[]{' '}); State state = new State (tokens [0], tokens [1] == "1"); Point point = new Point(int.Parse(tokens[2]), int.Parse(tokens[3])); GUIState guiState = new GUIState (state, point); this.stateGUITable.Add(guiState.getState().StateID, guiState); } else { string[] tokens = line.Split (new char[]{' '}); TapeMoves move = TapeMoves.Down; switch (tokens [4][0]) { case 'l': move = TapeMoves.Left; break; case 'r': move = TapeMoves.Right; break; case 'u': move = TapeMoves.Up; break; case 'd': move = TapeMoves.Down; break; case 's': move = TapeMoves.Stable; break; } Transition transition = new Transition (this.stateGUITable [tokens [0]].getState(), this.stateGUITable [tokens [1]].getState(), tokens [2] [0], tokens [3] [0], move); GUITransition guiTransition; if (tokens.Length == 6) guiTransition = new GUITransition (transition, double.Parse (tokens [5]), transition.From == transition.To); else guiTransition = new GUITransition (transition, 0, false); KeyValuePair<State, char> key = new KeyValuePair<State, char> (guiTransition.getTransition ().From, guiTransition.getTransition ().Read); this.edgeGUITable.Add (key, guiTransition); } } }
private string getTransitionString(Transition transition) { string transString; switch (transition.Movement) { case TapeMoves.Left: transString = string.Format("{0}|{1},{2}", transition.Read, transition.Write, "L"); break; case TapeMoves.Right: transString = string.Format("{0}|{1},{2}", transition.Read, transition.Write, "R"); break; case TapeMoves.Stable: transString = string.Format("{0}|{1},{2}", transition.Read, transition.Write, "S"); break; default: throw new Exception("Not Implemented Yet"); } return transString; }
public GUITransition(Transition transition, double angle, bool isSelf) { this.transition = transition; this.angle = angle; this.isSelfLoop = isSelf; }