Пример #1
0
        public DeterministicAutomata DeterminizeWithRefusalsAndDiv()
        {
            Dictionary <string, DeterministicFAState> Visited = new Dictionary <string, DeterministicFAState>(Ultility.Ultility.MC_INITIAL_SIZE);
            Stack <NormalizedFAState> pending = new Stack <NormalizedFAState>(1024);

            NormalizedFAState current = (new NormalizedFAState(InitialState)).TauReachable();

            pending.Push(current);

            DeterministicAutomata toReturn = new DeterministicAutomata();

            Visited.Add(current.GetID(), toReturn.AddInitialState());

            while (pending.Count > 0)
            {
                current = pending.Pop();
                DeterministicFAState currentState = Visited[current.GetID()];

                if (current.IsDiv())
                {
                    toReturn.InitialState.IsDivergent = true;
                }
                else
                {
                    currentState.SetNegatedRefusals(current.GetFailuresNegate());

                    Dictionary <string, HashSet <FAState> > nexts = new Dictionary <string, HashSet <FAState> >();

                    foreach (FAState state in current.States)
                    {
                        foreach (KeyValuePair <string, HashSet <FAState> > pair in state.Post)
                        {
                            if (pair.Key != Constants.TAU)
                            {
                                HashSet <FAState> states;
                                if (!nexts.TryGetValue(pair.Key, out states))
                                {
                                    states = new HashSet <FAState>();
                                    nexts.Add(pair.Key, states);
                                }

                                foreach (FAState faState in pair.Value)
                                {
                                    states.Add(faState);
                                }
                            }
                        }
                    }

                    foreach (KeyValuePair <string, HashSet <FAState> > keyValuePair in nexts)
                    {
                        NormalizedFAState next     = new NormalizedFAState(keyValuePair.Value);
                        NormalizedFAState newState = next.TauReachable();

                        DeterministicFAState target;
                        if (!Visited.TryGetValue(newState.GetID(), out target))
                        {
                            target = toReturn.AddState();
                            Visited.Add(newState.GetID(), target);
                            pending.Push(newState);
                        }

                        toReturn.AddTransition(currentState, keyValuePair.Key, target);
                    }
                }
            }

            return(toReturn);
        }