Ejemplo n.º 1
0
        public FiniteAutomaton(int statesCount, char[] alphabet, Transition[] transitions,
                               int initialIndex, int[] acceptingIndexes)
        {
            ValidateAlphabet(alphabet);
            this.alphabet = new Alphabet(alphabet);

            this.states = new State[statesCount];
            for (int i = 0; i < statesCount; i++)
            {
                this.states[i] = new State();
            }

            if (ArrayHasDuplicates(acceptingIndexes))
            {
                throw new ArgumentException("Accepting indexes cannot contain duplicates.");
            }
            int acceptingsCount = acceptingIndexes.Length;

            this.acceptings = new State[acceptingsCount];
            for (int i = 0; i < acceptingsCount; i++)
            {
                this.acceptings[i] = StateFromIndex(acceptingIndexes[i]);
            }

            this.initial = StateFromIndex(initialIndex);

            if (ArrayHasDuplicates(transitions))
            {
                throw new ArgumentException("Transitions cannot contain duplicates.");
            }
            this.table = new TransitionTable();

            foreach (var info in transitions)
            {
                AddTransition(info);
            }
            this.table.WrapUp();
        }