示例#1
0
        public DeterministicAutomata Determinize()
        {
            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()];

                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);
        }
示例#2
0
        public void FailuresDivergenceInclusionCheckBFS(DeterministicAutomata spec)
        {
            StringHashTable Visited = new StringHashTable(Ultility.Ultility.MC_INITIAL_SIZE);
            Stack<ConfigurationBase> pendingImpl = new Stack<ConfigurationBase>(1000);
            Stack<DeterministicFAState> pendingSpec = new Stack<DeterministicFAState>(1000);
            Queue<List<ConfigurationBase>> paths = new Queue<List<ConfigurationBase>>(1024);

            //implementation initial state
            pendingImpl.Push(InitialStep);

            //specification initial state
            pendingSpec.Push(spec.InitialState);

            string statestring = InitialStep.GetID() + Constants.TAU + spec.InitialState.GetID();
            Visited.Add(statestring);

            List<ConfigurationBase> path = new List<ConfigurationBase>();
            path.Add(InitialStep);
            paths.Enqueue(path);

            while (pendingImpl.Count > 0)
            {
                if (CancelRequested)
                {
                    VerificationOutput.NoOfStates = Visited.Count;
                    return;
                }

                ConfigurationBase currentImpl = pendingImpl.Pop();
                DeterministicFAState currentSpec = pendingSpec.Pop();
                List<ConfigurationBase> currentPath = paths.Dequeue();

                if (currentSpec.IsDivergent)
                {
                    VerificationOutput.NoOfStates = Visited.Count;
                    VerificationOutput.VerificationResult = VerificationResultType.VALID;
                    FailureType = RefinementCheckingResultType.Valid;
                    return;
                }

                bool implIsDiv = currentImpl.IsDivergent();

                if (implIsDiv)
                {
                    VerificationOutput.NoOfStates = Visited.Count;
                    VerificationOutput.VerificationResult = VerificationResultType.INVALID;
                    VerificationOutput.CounterExampleTrace = currentPath;
                    FailureType = RefinementCheckingResultType.DivCheckingFailure;
                    return;
                }

                IEnumerable<ConfigurationBase> nextImpl = currentImpl.MakeOneMove();
                VerificationOutput.Transitions += nextImpl.Count();

                List<string> negatedRefusal = new List<string>();
                bool hasTau = false;

                //for (int i = 0; i < nextImpl.Length; i++)
                foreach (ConfigurationBase next in nextImpl)
                {
                    DeterministicFAState nextSpec = currentSpec;

                    if (next.Event != Constants.TAU)
                    {
                        negatedRefusal.Add(next.Event);
                        //nextSpec = currentSpec.Post[nextImpl[i].Event];
                        nextSpec = currentSpec.Next(next.Event);

                        //The following checks if a violation is found.
                        //First, check for trace refinement, which is necessary for all other refinement as well.
                        if (nextSpec == null)
                        {
                            VerificationOutput.NoOfStates = Visited.Count;
                            VerificationOutput.CounterExampleTrace = currentPath;
                            VerificationOutput.VerificationResult = VerificationResultType.INVALID;
                            FailureType = RefinementCheckingResultType.TraceRefinementFailure;
                            return;
                        }
                    }
                    else
                    {
                        hasTau = true;
                    }

                    statestring = next.GetID() + Constants.SEPARATOR + nextSpec.GetID();

                    if (!Visited.ContainsKey(statestring))
                    {
                        Visited.Add(statestring);
                        pendingImpl.Push(next);
                        pendingSpec.Push(nextSpec);
                        List<ConfigurationBase> newPath = new List<ConfigurationBase>(currentPath);
                        newPath.Add(next);
                        paths.Enqueue(newPath);
                    }
                }

                //if the implememtation state is stable, then check for failures inclusion
                if (!hasTau)
                {
                    //enabledS is empty if and only if the spec state is divergent.
                    if (!RefusalContainment(negatedRefusal, currentSpec.NegatedRefusals))
                    {
                        VerificationOutput.NoOfStates = Visited.Count;
                        VerificationOutput.CounterExampleTrace = currentPath;
                        VerificationOutput.VerificationResult = VerificationResultType.INVALID;
                        FailureType = RefinementCheckingResultType.FailuresRefinementFailure;
                        return;
                    }
                }
            }

            VerificationOutput.NoOfStates = Visited.Count;
            VerificationOutput.VerificationResult = VerificationResultType.VALID;
            FailureType = RefinementCheckingResultType.Valid;
        }