Esempio n. 1
0
        protected override void CheckConstraints()
        {
            base.CheckConstraints();
            if (base.Alphabet.Intersect(BandAlphabet).Count() != base.Alphabet.Length)
            {
                throw new AlphabetException("Inputalphabet not in Bandalphabet", this);
            }
            if (!BandAlphabet.Contains(BlankSymbol))
            {
                throw new AlphabetException(BlankSymbol, this);
            }

            foreach (var item in Transforms)
            {
                if (item.Key.q >= StatesCount)
                {
                    throw new StateException(item.Key.q, this);
                }
                foreach (char c in item.Key.c)
                {
                    if (!BandAlphabet.Contains(c))
                    {
                        throw new AlphabetException(c, this);
                    }
                }
            }
        }
Esempio n. 2
0
        public string ToBinString()
        {
            var sb = new System.Text.StringBuilder();

            const char S = '0'; // Separator
            const char C = '1'; // Counter

            var stateTranslate = new System.Collections.Generic.Dictionary <uint, uint>();

            for (uint i = 0; i < StatesCount; i++)
            {
                stateTranslate.Add(i, i);
            }

            if (stateTranslate[0] != StartState)
            {
                (
                    stateTranslate[0],
                    stateTranslate[StartState]
                ) = (StartState, 0);
            }

            if (stateTranslate[1] != AcceptedState)
            {
                (
                    stateTranslate[1],
                    stateTranslate[AcceptedState]
                ) = (AcceptedState, 1);
            }

            if (stateTranslate[2] != DiscardState)
            {
                (
                    stateTranslate[2],
                    stateTranslate[DiscardState]
                ) = (DiscardState, 2);
            }

            foreach (var t in Transforms)
            {
                sb.Append(
                    new string(C, (int)stateTranslate[t.Key.q] + 1) + S +
                    new string(C, (int)BandAlphabet.ArrayIndex(t.Key.c) + 1) + S +
                    new string(C, (int)stateTranslate[t.Value.qNext] + 1) + S +
                    new string(C, (int)BandAlphabet.ArrayIndex(t.Value.c2) + 1) + S +
                    new string(C, (int)t.Value.Direction - 1) +
                    S + S
                    );
            }

            sb.Remove(sb.Length - 2, 2);

            return(sb.ToString());
        }
Esempio n. 3
0
 protected override void CheckConstraints()
 {
     base.CheckConstraints();
     foreach (var ti in Transforms)
     {
         if (ti.Value.qNext >= StatesCount)
         {
             throw new StateException(ti.Value.qNext, this);
         }
         if (!BandAlphabet.Contains(ti.Value.c2))
         {
             throw new AlphabetException(ti.Value.c2, this);
         }
     }
 }
Esempio n. 4
0
        protected override void CheckConstraints()
        {
            base.CheckConstraints();
            foreach (var ti in Transforms)
            {
                foreach (char c in ti.Key.c)
                {
                    if (!BandAlphabet.Contains(c))
                    {
                        throw new Automat.AlphabetException(c, this);
                    }
                }

                foreach (char c in ti.Value.c2)
                {
                    if (!BandAlphabet.Contains(c))
                    {
                        throw new Automat.AlphabetException(c, this);
                    }
                }

                if (Alphabet.Contains(BlankSymbol))
                {
                    throw new Automat.AlphabetException(BlankSymbol, this);
                }

                if (ti.Key.q >= StatesCount)
                {
                    throw new Automat.StateException(ti.Key.q, this);
                }

                if (ti.Value.qNext >= StatesCount)
                {
                    throw new Automat.StateException(ti.Value.qNext, this);
                }
            }
        }