Esempio n. 1
0
        public void FailuresDivergenceInclusionCheckDFS(DeterministicAutomata spec)
        {
            StringHashTable          Visited  = new StringHashTable(Ultility.Ultility.MC_INITIAL_SIZE);
            List <ConfigurationBase> toReturn = new List <ConfigurationBase>();

            Stack <ConfigurationBase>    pendingImpl = new Stack <ConfigurationBase>(1000);
            Stack <DeterministicFAState> pendingSpec = new Stack <DeterministicFAState>(1000);

            //The following are for identifying a counterexample trace.
            Stack <int> depthStack = new Stack <int>(1000);

            depthStack.Push(0);
            List <int> depthList = new List <int>(1000);

            //The above are for identifying a counterexample trace.

            //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);

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

                ConfigurationBase    currentImpl = pendingImpl.Pop();
                DeterministicFAState currentSpec = pendingSpec.Pop();

                //The following are for identifying a counterexample trace.
                int depth = depthStack.Pop();

                if (depth > 0)
                {
                    while (depthList[depthList.Count - 1] >= depth)
                    {
                        int lastIndex = depthList.Count - 1;
                        depthList.RemoveAt(lastIndex);
                        toReturn.RemoveAt(lastIndex);
                    }
                }

                toReturn.Add(currentImpl);
                depthList.Add(depth);
                //The above are for identifying a counterexample trace.

                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.CounterExampleTrace = toReturn;
                    VerificationOutput.VerificationResult  = VerificationResultType.INVALID;
                    FailureType = RefinementCheckingResultType.DivCheckingFailure;
                    return;
                }

                IEnumerable <ConfigurationBase> nextImpl = currentImpl.MakeOneMove();
                VerificationOutput.Transitions += nextImpl.Count();
                List <string> implRefusal = 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)
                    {
                        implRefusal.Add(next.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)
                        {
                            toReturn.Add(next);
                            VerificationOutput.NoOfStates          = Visited.Count;
                            VerificationOutput.CounterExampleTrace = toReturn;
                            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);
                        depthStack.Push(depth + 1);
                    }
                }

                //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(implRefusal, currentSpec.NegatedRefusals))
                    {
                        VerificationOutput.NoOfStates          = Visited.Count;
                        VerificationOutput.CounterExampleTrace = toReturn;
                        VerificationOutput.VerificationResult  = VerificationResultType.INVALID;
                        FailureType = RefinementCheckingResultType.FailuresRefinementFailure;
                        return;
                    }
                }
            }

            VerificationOutput.NoOfStates         = Visited.Count;
            VerificationOutput.VerificationResult = VerificationResultType.VALID;
            FailureType = RefinementCheckingResultType.Valid;
        }
Esempio n. 2
0
        public void FailuresInclusionCheckBFS(DeterministicAutomata spec)
        {
            StringHashTable                   Visited     = new StringHashTable(Ultility.Ultility.MC_INITIAL_SIZE);
            Queue <ConfigurationBase>         pendingImpl = new Queue <ConfigurationBase>(1000);
            Queue <DeterministicFAState>      pendingSpec = new Queue <DeterministicFAState>(1000);
            Queue <List <ConfigurationBase> > paths       = new Queue <List <ConfigurationBase> >(1024);

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

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

            string statestring = InitialStep.GetID() + Constants.SEPARATOR + 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.Dequeue();
                DeterministicFAState     currentSpec = pendingSpec.Dequeue();
                List <ConfigurationBase> currentPath = paths.Dequeue();

                IEnumerable <ConfigurationBase> nextImpl = currentImpl.MakeOneMove();
                VerificationOutput.Transitions += nextImpl.Count();
                List <string> negatedRefusal = new List <string>();
                bool          hasTau         = false;

                //for (int k = 0; k < nextImpl.Length; k++)
                foreach (ConfigurationBase next in nextImpl)
                {
                    //ConfigurationBase next = nextImpl[k];

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

                        if (nextSpec == null)
                        {
                            currentPath.Add(next);
                            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.Enqueue(next);
                        pendingSpec.Enqueue(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))
                    {
                        //return toReturn;
                        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;
        }
Esempio n. 3
0
 public Tuple(MDPConfiguration imp, DeterministicFAState spec, MDPState mdp)
 {
     ImplState = imp;
     SpecState = spec;
     MDPState  = mdp;
 }
Esempio n. 4
0
        private MDP BuildMDP()
        {
            DeterministicAutomata specAutomaton = BuildDeterministicAutomata(InitSpecStep);

            Stack <Tuple>        working     = new Stack <Tuple>(1024);
            DeterministicFAState currentSpec = specAutomaton.InitialState;

            MDPState init = new MDPState(InitialStep.GetID() + Constants.SEPARATOR + currentSpec.GetID());

            working.Push(new Tuple(InitialStep as MDPConfiguration, currentSpec, init));

            MDP mdp = new MDP(init, Ultility.Ultility.DEFAULT_PRECISION, Ultility.Ultility.MAX_DIFFERENCE);

            do
            {
                if (CancelRequested)
                {
                    VerificationOutput.NoOfStates = mdp.States.Count;
                    return(mdp);
                }
                // KeyValuePair<KeyValuePair<MDPConfiguration, DeterministicFAState>, MDPState>
                Tuple current = working.Pop();
                if (current.SpecState == null)
                {
                    mdp.AddTargetStates(current.MDPState);
                }
                else
                {
                    IEnumerable <MDPConfiguration> list = current.ImplState.MakeOneMoveLocal();
                    VerificationOutput.Transitions += list.Count();

                    int          currentDistriIndex = -1;
                    Distribution newDis             = new Distribution(Constants.TAU);

                    //for (int i = 0; i < list.Count; i++)
                    foreach (var step in list)
                    {
                        //MDPConfiguration step = list[i];
                        DeterministicFAState nextSpec = current.SpecState;

                        if (step.Event != Constants.TAU)
                        {
                            nextSpec = current.SpecState.Next(step.Event);
                        }

                        //System.Diagnostics.Debug.Assert(nextSpec != null, "NextSpec is null!!");

                        //string stepID = step.GetID() + Constants.SEPARATOR + nextSpec.GetID().ToString();
                        string stepID = step.GetID() + Constants.SEPARATOR + (nextSpec == null ? "" : nextSpec.GetID().ToString());

                        MDPState nextState;

                        if (!mdp.States.TryGetValue(stepID, out nextState))
                        {
                            nextState = new MDPState(stepID);
                            mdp.AddState(nextState);

                            working.Push(new Tuple(step, nextSpec, nextState));
                        }

                        if (step.DisIndex == -1)
                        {
                            if (currentDistriIndex >= 0)
                            {
                                current.MDPState.AddDistribution(newDis);
                                newDis = new Distribution(Constants.TAU);
                            }

                            Distribution newTrivialDis = new Distribution(step.Event, nextState);
                            current.MDPState.AddDistribution(newTrivialDis);
                        }
                        else if (currentDistriIndex != -1 && step.DisIndex != currentDistriIndex)
                        {
                            current.MDPState.AddDistribution(newDis);
                            newDis = new Distribution(Constants.TAU);
                            newDis.AddProbStatePair(step.Probability, nextState);
                        }
                        else
                        {
                            newDis.AddProbStatePair(step.Probability, nextState);
                        }

                        currentDistriIndex = step.DisIndex;
                    }

                    if (currentDistriIndex >= 0)
                    {
                        current.MDPState.AddDistribution(newDis);
                    }
                }
            } while (working.Count > 0);

            VerificationOutput.NoOfStates = mdp.States.Count;
            //mdp.BackUpTargetStates();
            return(mdp);
        }
Esempio n. 5
0
        public void TraceInclusionCheckBFS(DeterministicAutomata spec)
        {
            StringHashTable Visited = new StringHashTable(Ultility.Ultility.MC_INITIAL_SIZE);

            Queue <ConfigurationBase>         pendingImpl = new Queue <ConfigurationBase>(1024);
            Queue <DeterministicFAState>      pendingSpec = new Queue <DeterministicFAState>(1024);
            Queue <List <ConfigurationBase> > paths       = new Queue <List <ConfigurationBase> >(1024);

            //The following are for identifying a counterexample trace.
            Stack <int> depthStack = new Stack <int>(1024);

            depthStack.Push(0);
            //The above are for identifying a counterexample trace.

            //implementation initial state
            pendingImpl.Enqueue(InitialStep);
            pendingSpec.Enqueue(spec.InitialState);

            string statestring = spec.InitialState.GetID() + Constants.SEPARATOR + InitialStep.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.Dequeue();
                DeterministicFAState     currentSpec = pendingSpec.Dequeue();
                List <ConfigurationBase> currentPath = paths.Dequeue();

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

                //for (int k = 0; k < nextImpl.Length; k++)
                foreach (ConfigurationBase next in nextImpl)
                {
                    //ConfigurationBase next = nextImpl[k];
                    DeterministicFAState nextSpec = currentSpec;
                    if (next.Event != Constants.TAU)
                    {
                        nextSpec = currentSpec.Next(next.Event);

                        if (nextSpec == null)
                        {
                            currentPath.Add(next);
                            VerificationOutput.NoOfStates          = Visited.Count;
                            VerificationOutput.CounterExampleTrace = currentPath;
                            VerificationOutput.VerificationResult  = VerificationResultType.INVALID;
                            return;
                        }
                    }

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

            VerificationOutput.VerificationResult = VerificationResultType.VALID;
            VerificationOutput.NoOfStates         = Visited.Count;
        }
Esempio n. 6
0
        public void TraceInclusionCheckDFS(DeterministicAutomata spec)
        {
            StringHashTable          Visited  = new StringHashTable(Ultility.Ultility.MC_INITIAL_SIZE);
            List <ConfigurationBase> toReturn = new List <ConfigurationBase>();

            Stack <ConfigurationBase>    pendingImpl = new Stack <ConfigurationBase>(1024);
            Stack <DeterministicFAState> pendingSpec = new Stack <DeterministicFAState>(1024);

            //The following are for identifying a counterexample trace.
            Stack <int> depthStack = new Stack <int>(1024);

            depthStack.Push(0);
            List <int> depthList = new List <int>(1024);

            //The above are for identifying a counterexample trace.

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

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

            Visited.Add(InitialStep.GetID() + Constants.SEPARATOR + spec.InitialState.GetID());

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

                ConfigurationBase    currentImpl = pendingImpl.Pop();
                DeterministicFAState currentSpec = pendingSpec.Pop();

                //The following are for identifying a counterexample trace.
                int depth = depthStack.Pop();

                if (depth > 0)
                {
                    while (depthList[depthList.Count - 1] >= depth)
                    {
                        int lastIndex = depthList.Count - 1;
                        depthList.RemoveAt(lastIndex);
                        toReturn.RemoveAt(lastIndex);
                    }
                }

                toReturn.Add(currentImpl);
                depthList.Add(depth);

                //If the specification has no corresponding state, then it implies that the trace is allowed by the
                //implementation but not the specification -- which means trace-refinement is failed.

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

                //for (int k = 0; k < nextImpl.Length; k++)
                foreach (ConfigurationBase next in nextImpl)
                {
                    //ConfigurationBase next = nextImpl[k];
                    DeterministicFAState nextSpec = currentSpec;
                    if (next.Event != Constants.TAU)
                    {
                        nextSpec = currentSpec.Next(next.Event);

                        if (nextSpec == null)
                        {
                            toReturn.Add(next);
                            VerificationOutput.NoOfStates          = Visited.Count;
                            VerificationOutput.CounterExampleTrace = toReturn;
                            VerificationOutput.VerificationResult  = VerificationResultType.INVALID;
                            return;
                        }
                    }

                    string ID = next.GetID() + Constants.SEPARATOR + nextSpec.GetID();
                    if (!Visited.ContainsKey(ID))
                    {
                        pendingImpl.Push(next);
                        pendingSpec.Push(nextSpec);
                        depthStack.Push(depth + 1);
                        Visited.Add(ID);
                    }
                }
            }

            VerificationOutput.NoOfStates         = Visited.Count;
            VerificationOutput.VerificationResult = VerificationResultType.VALID;
        }