Beispiel #1
0
        public static StateSet CorrectForEpsilon(StateSet inputSet)
        {
            StateSet outputSet = new StateSet();

            foreach (State state in inputSet.StoredStates)
            {
                outputSet.add(state);
                foreach (var transition in state.Neighbours)
                {
                    if (transition.InputCharacter == '_')
                    {
                        outputSet.add(transition.DestinationState);
                    }
                }
            }

            return(outputSet);
        }
        private StateSet GetInitialStates(StateSet stateSet)
        {
            StateSet output = new StateSet();
            StateSet s      = stateSet;

            output.add(s.findInitialState());
            output = output.CorrectForEpsilon();
            return(output);
        }
        public StateSet ConvertHashToStateSet(HashSet <State> stateSet)
        {
            StateSet output = new StateSet();

            foreach (State state in stateSet)
            {
                output.add(state);
            }
            return(output);
        }
        public Automaton GenerateDfa()
        {
            output = new StateSet();

            StateSet   initialStates     = GetInitialStates(automaton.AutomatonStates);
            PowerState initialPowerState = new PowerState(initialStates);

            initialPowerState.setBeginState();
            handledStates.Add(initialPowerState.StateName);
            concreteHandledStates.Add(initialPowerState);
            powerStateQueue.Enqueue(initialPowerState);
            while (powerStateQueue.Count > 0)
            {
                PowerState newPowerState = powerStateQueue.Dequeue();
                addNeighbouringPowerStates(newPowerState);
                output.add(newPowerState);
            }
            output.add(sink);

            return(new Automaton(output, automaton.Alphabet));
        }
Beispiel #5
0
        public static StateSet returnPossibleDestinationStates(char c, StateSet inputSet)
        {
            StateSet outputSet = new StateSet();

            foreach (State state in inputSet.StoredStates)
            {
                foreach (var transition in state.Neighbours)
                {
                    if (transition.InputCharacter == c && state.StateName != "Sink")
                    {
                        outputSet.add(transition.DestinationState);
                    }
                }
            }

            return(outputSet);
        }
        StateSet addNeighbouringPowerStates(PowerState powerState)
        {
            StateSet output = new StateSet();
            State    newPowerState;

            foreach (char c in automaton.Alphabet.characters)
            {
                StateSet stateSet     = new StateSet();
                StateSet iterationSet = powerState.States.CorrectForEpsilon();
                foreach (State state in iterationSet.StoredStates)
                {
                    foreach (Transition transition in state.Neighbours)
                    {
                        if (transition.InputCharacter == c)
                        {
                            stateSet.add(transition.DestinationState);
                        }
                    }
                }
                //StateSet stateSetToAdd = stateSet.CorrectForEpsilon();
                if (stateSet.StoredStates.Count > 0)
                {
                    stateSet.CorrectForEpsilon();
                    newPowerState = new PowerState(stateSet);
                    PowerState powerStateToEnqueue = new PowerState(stateSet);
                    if (!handledStates.Contains(powerStateToEnqueue.StateName))
                    {
                        powerStateQueue.Enqueue(powerStateToEnqueue);
                        handledStates.Add(powerStateToEnqueue.StateName);
                        concreteHandledStates.Add(powerStateToEnqueue);
                    }
                    else
                    {
                        newPowerState = concreteHandledStates.Find(x => x.StateName == powerStateToEnqueue.StateName);
                    }
                }
                else
                {
                    newPowerState = sink;
                }

                powerState.AddTransition(new Transition(c, newPowerState));
            }

            return(output);
        }