예제 #1
0
        /// <summary>
        /// Fills a collection with the result of moving each of the specified <paramref name="states"/> on the specified input.
        /// </summary>
        /// <param name="states">The states to examine</param>
        /// <param name="input">The input to use</param>
        /// <param name="result">The states that are now entered as a result of the move</param>
        /// <returns><paramref name="result"/> or a new collection if it wasn't specified.</returns>
        public static ICollection <FA> FillMove(IEnumerable <FA> states, int input, ICollection <FA> result = null)
        {
            var inputs = new KeyValuePair <int, int>(input, input);

            if (null == result)
            {
                result = new List <FA>();
            }
            foreach (var fa in states)
            {
                // examine each of the states reachable from this state on no input
                foreach (var efa in fa.FillEpsilonClosure())
                {
                    // see if this state has this input in its transitions
                    foreach (var trns in efa.InputTransitions)
                    {
                        if (RangeUtility.Intersects(trns.Key, inputs))
                        {
                            if (!result.Contains(trns.Value))
                            {
                                foreach (var ofa in trns.Value.FillEpsilonClosure())
                                {
                                    if (!result.Contains(ofa))                                     // if it does, add it if it's not already there
                                    {
                                        result.Add(ofa);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(result);
        }
예제 #2
0
 public void AddInputTransition(KeyValuePair <int, int> range, FA dst)
 {
     foreach (var trns in InputTransitions)
     {
         if (RangeUtility.Intersects(trns.Key, range))
         {
             throw new ArgumentException("There already is a transition to a different state on at least part of the specified input range");
         }
     }
     InputTransitions.Add(range, dst);
 }