コード例 #1
0
        /// <summary>
        /// Returns a new automaton that accepts strings representing decimal non-negative integers in
        /// the given interval.
        /// </summary>
        /// <param name="min">The minimum value of interval.</param>
        /// <param name="max">The maximum value of inverval (both end points are included in the
        /// interval).</param>
        /// <param name="digits">If f >0, use fixed number of digits (strings must be prefixed by 0's
        /// to obtain the right length) otherwise, the number of digits is not fixed.</param>
        /// <returns>A new automaton that accepts strings representing decimal non-negative integers
        /// in the given interval.</returns>
        public static Automaton MakeInterval(int min, int max, int digits)
        {
            if (min > max)
            {
                throw new ArgumentException("min must not be greater than max.");
            }

            var    a = new Automaton();
            string x = Convert.ToString(min, CultureInfo.CurrentCulture);
            string y = Convert.ToString(max, CultureInfo.CurrentCulture);

            if ((digits > 0 && y.Length > digits))
            {
                throw new ArgumentException($"Fixed length output specified ({digits}), but will not fit max ({y.Length}).");
            }

            int d  = digits > 0 ? digits : y.Length;
            var bx = new StringBuilder();

            for (int i = x.Length; i < d; i++)
            {
                bx.Append('0');
            }

            bx.Append(x);
            x = bx.ToString();
            var by = new StringBuilder();

            for (int i = y.Length; i < d; i++)
            {
                by.Append('0');
            }

            by.Append(y);
            y = by.ToString();
            ICollection <State> initials = new List <State>();

            a.Initial = BasicAutomata.Between(x, y, 0, initials, digits <= 0);
            if (digits <= 0)
            {
                List <StatePair> pairs = (from p in initials
                                          where a.Initial != p
                                          select new StatePair(a.Initial, p)).ToList();
                a.AddEpsilons(pairs);
                a.Initial.AddTransition(new Transition('0', a.Initial));
                a.IsDeterministic = false;
            }
            else
            {
                a.IsDeterministic = true;
            }

            a.CheckMinimizeAlways();
            return(a);
        }
コード例 #2
0
        /// <summary>
        /// Returns a new automaton that accepts strings representing decimal non-negative integers in
        /// the given interval.
        /// </summary>
        /// <param name="min">The minimum value of interval.</param>
        /// <param name="max">The maximum value of inverval (both end points are included in the
        /// interval).</param>
        /// <param name="digits">If f >0, use fixed number of digits (strings must be prefixed by 0's
        /// to obtain the right length) otherwise, the number of digits is not fixed.</param>
        /// <returns>A new automaton that accepts strings representing decimal non-negative integers
        /// in the given interval.</returns>
        public static Automaton MakeInterval(int min, int max, int digits)
        {
            var    a = new Automaton();
            string x = Convert.ToString(min);
            string y = Convert.ToString(max);

            if (min > max || (digits > 0 && y.Length > digits))
            {
                throw new ArgumentException();
            }

            int d  = digits > 0 ? digits : y.Length;
            var bx = new StringBuilder();

            for (int i = x.Length; i < d; i++)
            {
                bx.Append('0');
            }

            bx.Append(x);
            x = bx.ToString();
            var by = new StringBuilder();

            for (int i = y.Length; i < d; i++)
            {
                by.Append('0');
            }

            by.Append(y);
            y = by.ToString();
            ICollection <State> initials = new List <State>();

            a.Initial = BasicAutomata.Between(x, y, 0, initials, digits <= 0);
            if (digits <= 0)
            {
                List <StatePair> pairs = (from p in initials
                                          where a.Initial != p
                                          select new StatePair(a.Initial, p)).ToList();
                a.AddEpsilons(pairs);
                a.Initial.AddTransition(new Transition('0', a.Initial));
                a.IsDeterministic = false;
            }
            else
            {
                a.IsDeterministic = true;
            }

            a.CheckMinimizeAlways();
            return(a);
        }