Example #1
0
        public bool addTransition(U input, T fromState, T toState)
        {
            // Add from state if non existant
            if (!Transitions.ContainsKey(fromState))
            {
                Transitions.Add(fromState, new Dictionary <U, HashSet <T> >());
            }

            if (Transitions[fromState].ContainsKey(input))
            {
                // Add to state to existing input.
                return(Transitions[fromState][input].Add(toState));
            }
            else
            {
                // Add input to alphabet (except for epsilon) so the alphabet can dynamically be changed
                if (!input.Equals(Epsilon))
                {
                    Alphabet.Add(input);
                }
                // Add input with to state.
                Transitions[fromState].Add(input, new HashSet <T>()
                {
                    toState
                });
                return(true);
            }
        }
Example #2
0
 public bool addTransition(U input, T fromState, T toState)
 {
     // Check if state and input already exists
     if (!Transitions.ContainsKey(fromState))
     {
         // Add the transition to the automaton
         Transitions.Add(fromState, new Dictionary <U, T>());
     }
     // Check if input already exists
     if (Transitions[fromState].ContainsKey(input))
     {
         // if it already exists we don't need to add it, so the method returns false
         return(false);
     }
     // Add input to alphabet so the alphabet can dynamically be changed
     Alphabet.Add(input);
     Transitions[fromState].Add(input, toState);
     States.Add(fromState);
     States.Add(toState);
     return(true);
 }