コード例 #1
0
        public void RecipeStepGetInitialStepTest()
        {
            RecipeStepFactory factory = new RecipeStepFactory();
            InitialStep       step    = factory.GetInitialStep("Test Drink", "Old Fashioned") as InitialStep;

            Assert.IsNotNull(step);
        }
コード例 #2
0
        public Composite PseudoClone()
        {
            var newPreconds = new List <IPredicate>();

            foreach (var precon in base.Preconditions)
            {
                newPreconds.Add(precon.Clone() as IPredicate);
            }
            var newEffects = new List <IPredicate>();

            foreach (var eff in base.Effects)
            {
                newEffects.Add(eff.Clone() as IPredicate);
            }

            var newBase = new Operator(base.Predicate.Clone() as Predicate, newPreconds, newEffects);
            var init    = InitialStep.Clone() as IPlanStep;

            init.Action = init.Action.Clone() as Operator;
            var goal = GoalStep.Clone() as IPlanStep;

            goal.Action = goal.Action.Clone() as Operator;

            return(new Composite(newBase, init, goal, SubSteps, SubOrderings, SubLinks)
            {
                Height = this.Height,
                NonEqualities = this.NonEqualities
            });
        }
コード例 #3
0
        /// <summary>
        /// This method checks whether the found counterexample is spurious or not using Liushanshan's condition.
        /// This checking only works for abstraction for parameterized systems.
        /// </summary>
        /// <returns></returns>
        protected override bool IsCounterExampleSpurious()
        {
            Stack <ConfigurationBase> working = new Stack <ConfigurationBase>(1024);
            List <ConfigurationBase>  ConcreteCounterExampleTrace = new List <ConfigurationBase>(64);

            working.Push(InitialStep);
            Stack <int> depthStack = new Stack <int>(1024);

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

            visited.Add("0-" + InitialStep.GetID());

            do
            {
                ConfigurationBase current = working.Pop();
                int depth = depthStack.Pop();

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

                ConcreteCounterExampleTrace.Add(current);
                depthList.Add(depth);

                if (ConcreteCounterExampleTrace.Count == this.VerificationOutput.CounterExampleTrace.Count)
                {
                    this.VerificationOutput.CounterExampleTrace = ConcreteCounterExampleTrace;
                    return(false);
                }
                else
                {
                    ConfigurationBase abstractStep = this.VerificationOutput.CounterExampleTrace[depth + 1];

                    IEnumerable <ConfigurationBase> steps = current.MakeOneMove(abstractStep.Event);

                    foreach (ConfigurationBase step in steps)
                    //for (int j = 0; j < steps.Length; j++)
                    {
                        string tmp = (depth + 1) + "-" + step.GetID();
                        if (!visited.ContainsKey(tmp))
                        {
                            working.Push(step);
                            depthStack.Push(depth + 1);
                            visited.Add(tmp);
                        }
                    }
                }
            } while (working.Count > 0);

            return(true);
        }
コード例 #4
0
        public new Object Clone()
        {
            var op   = base.Clone() as IOperator;
            var init = InitialStep.Clone() as IPlanStep;
            var goal = GoalStep.Clone() as IPlanStep;

            return(new Composite(op, init, goal, SubSteps, SubOrderings, SubLinks)
            {
                Height = this.Height,
                NonEqualities = this.NonEqualities
            });
        }
コード例 #5
0
        public void InitialStepCloneTest()
        {
            InitialStep originalStep = new InitialStep("Test Drink", "Old Fashioned");
            InitialStep clonedStep   = originalStep.Clone() as InitialStep;

            Assert.IsNotNull(clonedStep);
            Assert.AreEqual(originalStep.IsStepDone, clonedStep.IsStepDone);
            Assert.AreEqual(originalStep.MessageToUser, clonedStep.MessageToUser);
            Assert.AreEqual(originalStep.Name, clonedStep.Name);
            Assert.AreEqual(originalStep.NextGrammarNeeded, clonedStep.NextGrammarNeeded);
            Assert.AreEqual(originalStep.ShouldCancel, clonedStep.ShouldCancel);
        }
コード例 #6
0
        public void InitialStepDoStepInvalidUserInputTest()
        {
            InitialStep step = new InitialStep("Test Drink", "Old Fashioned");
            Mock <IBartenderController> bartender = new Mock <IBartenderController>(MockBehavior.Strict);

            bartender.Setup(s => s.IsValid).Returns(true);
            step.DoStep(new Dialog(new Dictionary <String, String>(), "Test Phrase"), bartender.Object);
            Assert.AreEqual("Place a Old Fashioned glass underneath the spout of the bartender so I can make you a Test Drink.", step.MessageToUser);
            Assert.AreEqual(false, step.IsStepDone);
            Assert.AreEqual("Initial", step.Name);
            Assert.AreEqual(BartenderApp.ConfirmationRuleName, step.NextGrammarNeeded);
            Assert.AreEqual(false, step.ShouldCancel);
        }
コード例 #7
0
        public new Object Clone()
        {
            var newSubStepContainer = new List <IPlanStep>();

            foreach (var step in SubSteps)
            {
                newSubStepContainer.Add(step.Clone() as IPlanStep);
            }

            return(new CompositePlanStep(CompositeAction, OpenConditions, InitialStep.Clone() as IPlanStep, GoalStep.Clone() as IPlanStep,
                                         newSubStepContainer, new HashSet <Tuple <IPlanStep, IPlanStep> >(SubOrderings).ToList(), new HashSet <CausalLink <IPlanStep> >(SubLinks).ToList(), ID)
            {
                Depth = base.Depth
            });
        }
コード例 #8
0
        /// <summary>
        /// Initializes the optimization algorithm by performing initial function evaluation to set the initial state.
        /// </summary>
        public void Initialize(TFunction initialFunction, TData data)
        {
            Function = initialFunction;

            step       = (float[])InitialStep.Clone();
            prevIterId = -1;
            delta      = -1;
            bestValue  = initialFunction.Evaluate(data);

            updateIndex       = -1;
            updateParam       = Single.PositiveInfinity;
            maxParamIndex     = StartParamIdx;
            currentParamIndex = StartParamIdx;

            isImproved = false;
            IsDone     = false;
        }
コード例 #9
0
        /// <summary>
        /// Initializes the optimization algorithm by performing initial function evaluation to set the initial state.
        /// </summary>
        public void Initialize(Function initialFunction, Mat <Vec3b> data)
        {
            Function = initialFunction;

            m_step       = (float[])InitialStep.Clone();
            m_prevIterId = -1;
            m_delta      = -1;
            m_bestValue  = initialFunction.Evaluate(data);

            m_updateIndex       = -1;
            m_updateParam       = Single.PositiveInfinity;
            m_maxParamIndex     = StartParamIdx;
            m_currentParamIndex = StartParamIdx;

            m_isImproved = false;
            IsDone       = false;
        }
コード例 #10
0
        public void InitialStepDoStepFalseAnswerTest()
        {
            InitialStep step = new InitialStep("Test Drink", "Old Fashioned");
            Mock <IBartenderController> bartender = new Mock <IBartenderController>(MockBehavior.Strict);

            bartender.Setup(s => s.IsValid).Returns(true);
            Dictionary <String, String> input = new Dictionary <string, string>
            {
                { "answer", "false" },
            };

            step.DoStep(new Dialog(input, "Test Phrase"), bartender.Object);
            Assert.AreEqual(null, step.MessageToUser);
            Assert.AreEqual(true, step.IsStepDone);
            Assert.AreEqual("Initial", step.Name);
            Assert.AreEqual(null, step.NextGrammarNeeded);
            Assert.AreEqual(true, step.ShouldCancel);
        }
コード例 #11
0
        public new Object Clone()
        {
            var op          = base.Clone() as IOperator;
            var newSubsteps = new List <IPlanStep>();

            foreach (var substep in SubSteps)
            {
                var newsubstep = substep.Clone() as IPlanStep;
                newsubstep.Action = newsubstep.Action.Clone() as Operator;
                newSubsteps.Add(newsubstep);
            }

            //  var newinitial = InitialStep.Clone() as IPlanStep;
            //newinitial.Action = InitialStep.Action.Clone() as Operator;
            // do same for literals
            return(new Decomposition(op, Literals, InitialStep.Clone() as IPlanStep, GoalStep.Clone() as IPlanStep, newSubsteps, SubOrderings.ToList(), SubLinks.ToList()));
            // return new Decomposition(op, Literals, newSubsteps, SubOrderings, SubLinks);
        }
コード例 #12
0
        public IPlanStep Find(IPlanStep stepClonedFromOpenCondition)
        {
            if (GoalStep.Equals(stepClonedFromOpenCondition))
            {
                return(GoalStep);
            }

            // For now, this condition is impossible
            if (InitialStep.Equals(stepClonedFromOpenCondition))
            {
                return(InitialStep);
            }

            if (!Steps.Contains(stepClonedFromOpenCondition))
            {
                throw new System.Exception();
            }
            return(Steps.Single(s => s.ID == stepClonedFromOpenCondition.ID));
        }
コード例 #13
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);
        }
コード例 #14
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;
        }
コード例 #15
0
        public void TraceInclusionCheckBFSAntiChain(Automata spec)
        {
            //StringHashTable Visited = new StringHashTable(Ultility.Ultility.MC_INITIAL_SIZE);
            AntiChain antichain = new AntiChain();
            Queue <ConfigurationBase>         pendingImpl = new Queue <ConfigurationBase>(1024);
            Queue <NormalizedFAState>         pendingSpec = new Queue <NormalizedFAState>(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);
            NormalizedFAState initialSpec = (new NormalizedFAState(spec.InitialState)).TauReachable();

            pendingSpec.Enqueue(initialSpec);

            //Visited.Add(statestring);
            antichain.Add(InitialStep.GetID(), initialSpec.States);

            List <ConfigurationBase> path = new List <ConfigurationBase>();

            path.Add(InitialStep);
            paths.Enqueue(path);

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

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

                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];

                    NormalizedFAState nextSpec = currentSpec;
                    if (next.Event != Constants.TAU)
                    {
                        nextSpec = currentSpec.NextWithTauReachable(next.Event);

                        if (nextSpec.States.Count == 0)
                        {
                            currentPath.Add(next);
                            VerificationOutput.NoOfStates          = antichain.GetNoOfStates();
                            VerificationOutput.CounterExampleTrace = currentPath;
                            VerificationOutput.VerificationResult  = VerificationResultType.INVALID;
                            return;
                        }
                    }

                    if (!antichain.Add(next.GetID(), nextSpec.States))
                    {
                        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         = antichain.GetNoOfStates();
        }
コード例 #16
0
        private MDP BuildMDP()
        {
            Stack <KeyValuePair <MDPConfiguration, MDPState> > working = new Stack <KeyValuePair <MDPConfiguration, MDPState> >(1024);

            string   initID = InitialStep.GetID();
            MDPState init   = new MDPState(initID);

            working.Push(new KeyValuePair <MDPConfiguration, MDPState>(InitialStep as MDPConfiguration, 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 <MDPConfiguration, MDPState> current = working.Pop();
                IEnumerable <MDPConfiguration>            list    = current.Key.MakeOneMoveLocal();
                VerificationOutput.Transitions += list.Count();

                //check if it is one of the target state
                //if (list.Length == 0)
                if (current.Key.IsDeadLock)
                {
                    if (isNotTerminationTesting || current.Key.Event != Constants.TERMINATION)
                    {
                        mdp.AddTargetStates(current.Value);
                    }
                }
                else
                {
                    int          currentDistriIndex = -1;
                    Distribution newDis             = new Distribution(Constants.TAU);

                    //for (int i = 0; i < list.Length; i++)
                    foreach (var step in list)
                    {
                        //MDPConfiguration step = list[i];
                        string   stepID = step.GetID();
                        MDPState nextState;

                        if (!mdp.States.TryGetValue(stepID, out nextState))
                        {
                            nextState = new MDPState(stepID);
                            mdp.AddState(nextState);
                            working.Push(new KeyValuePair <MDPConfiguration, MDPState>(step, nextState));
                        }

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

                            Distribution newTrivialDis = new Distribution(step.Event);
                            newTrivialDis.AddProbStatePair(1, nextState);
                            current.Value.AddDistribution(newTrivialDis);
                        }
                        else if (currentDistriIndex != -1 && step.DisIndex != currentDistriIndex)
                        {
                            current.Value.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.Value.AddDistribution(newDis);
                    }
                }
            } while (working.Count > 0);

            VerificationOutput.NoOfStates = mdp.States.Count;
            //mdp.BackUpTargetStates();
            return(mdp);
        }
コード例 #17
0
        private void FailuresDivergenceInclusionCheckBFSAntichain(Automata spec)
        {
            Stack <ConfigurationBase>         pendingImpl = new Stack <ConfigurationBase>(1000);
            Stack <NormalizedFAState>         pendingSpec = new Stack <NormalizedFAState>(1000);
            Queue <List <ConfigurationBase> > paths       = new Queue <List <ConfigurationBase> >(1024);

            NormalizedFAState initialSpec = (new NormalizedFAState(spec.InitialState)).TauReachable();

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

            //specification initial state
            pendingSpec.Push(initialSpec);

            List <ConfigurationBase> path = new List <ConfigurationBase>();

            path.Add(InitialStep);
            paths.Enqueue(path);

            AntiChain antichain = new AntiChain();

            antichain.Add(InitialStep.GetID(), initialSpec.States);

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

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

                if (currentSpec.IsDiv())
                {
                    VerificationOutput.NoOfStates         = antichain.GetNoOfStates();
                    VerificationOutput.VerificationResult = VerificationResultType.VALID;
                    FailureType = RefinementCheckingResultType.Valid;
                    return;
                }

                bool implIsDiv = currentImpl.IsDivergent();

                if (implIsDiv)
                {
                    VerificationOutput.NoOfStates          = antichain.GetNoOfStates();
                    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)
                {
                    NormalizedFAState nextSpec = currentSpec;

                    if (next.Event != Constants.TAU)
                    {
                        negatedRefusal.Add(next.Event);
                        //nextSpec = currentSpec.Post[nextImpl[i].Event];
                        nextSpec = currentSpec.NextWithTauReachable(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.States.Count == 0)
                        {
                            VerificationOutput.NoOfStates          = antichain.GetNoOfStates();
                            VerificationOutput.CounterExampleTrace = currentPath;
                            VerificationOutput.VerificationResult  = VerificationResultType.INVALID;
                            FailureType = RefinementCheckingResultType.TraceRefinementFailure;
                            return;
                        }
                    }
                    else
                    {
                        hasTau = true;
                    }

                    if (!antichain.Add(next.GetID(), nextSpec.States))
                    {
                        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.GetFailuresNegate()))
                    {
                        VerificationOutput.NoOfStates          = antichain.GetNoOfStates();
                        VerificationOutput.CounterExampleTrace = currentPath;
                        VerificationOutput.VerificationResult  = VerificationResultType.INVALID;
                        FailureType = RefinementCheckingResultType.FailuresRefinementFailure;
                        return;
                    }
                }
            }

            VerificationOutput.NoOfStates         = antichain.GetNoOfStates();
            VerificationOutput.VerificationResult = VerificationResultType.VALID;
            FailureType = RefinementCheckingResultType.Valid;
        }
コード例 #18
0
 public Task Visit(InitialStep step)
 {
     return(step.GetNextStep().Accept(this));
 }
コード例 #19
0
        private MDPStat BuildMDP()
        {
            Stack <KeyValuePair <MDPConfiguration, MDPStateStat> > working = new Stack <KeyValuePair <MDPConfiguration, MDPStateStat> >(1024);

            string       initID = InitialStep.GetID();
            MDPStateStat init   = new MDPStateStat(initID);

            working.Push(new KeyValuePair <MDPConfiguration, MDPStateStat>(InitialStep as MDPConfiguration, init));
            MDPStat mdp = new MDPStat(init, Ultility.Ultility.DEFAULT_PRECISION, Ultility.Ultility.MAX_DIFFERENCE);

            do
            {
                if (CancelRequested)
                {
                    VerificationOutput.NoOfStates = mdp.States.Count;
                    return(mdp);
                }

                KeyValuePair <MDPConfiguration, MDPStateStat> current = working.Pop();
                IEnumerable <MDPConfiguration> list = current.Key.MakeOneMoveLocal();
                VerificationOutput.Transitions += list.Count();

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

                //for (int i = 0; i < list.Length; i++)
                foreach (MDPConfiguration step in list)
                {
                    //MDPConfiguration step = list[i];
                    string       stepID = step.GetID();
                    MDPStateStat nextState;

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

                        ExpressionValue v = EvaluatorDenotational.Evaluate(ReachableStateCondition, step.GlobalEnv);

                        if ((v as BoolConstant).Value)
                        {
                            mdp.AddTargetStates(nextState);
                        }
                        else
                        {
                            working.Push(new KeyValuePair <MDPConfiguration, MDPStateStat>(step, nextState));
                        }
                    }

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

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

                    currentDistriIndex = step.DisIndex;
                }

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

            VerificationOutput.NoOfStates = mdp.States.Count;
            return(mdp);
        }
コード例 #20
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;
        }
コード例 #21
0
        public void BFSVerification()
        {
            StringHashTable Visited = new StringHashTable(1048576);

            Queue <ConfigurationBase>         working = new Queue <ConfigurationBase>(1024);
            Queue <List <ConfigurationBase> > paths   = new Queue <List <ConfigurationBase> >(1024);

            Visited.Add(InitialStep.GetID());

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

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

            do
            {
                if (CancelRequested)
                {
                    VerificationOutput.NoOfStates = Visited.Count;
                    return;
                }

                ConfigurationBase               current     = working.Dequeue();
                List <ConfigurationBase>        currentPath = paths.Dequeue();
                IEnumerable <ConfigurationBase> list        = current.MakeOneMove();
                this.VerificationOutput.Transitions += list.Count();

                Debug.Assert(currentPath[currentPath.Count - 1].GetID() == current.GetID());

                // track channel input for circular dependency
                if (current.Event.IndexOf("!") != -1 && visitedStates.Contains(current.Event) && !isProcessEventExist(visitedStates, current.Event.Substring(current.Event.LastIndexOf("_") + 1, (current.Event.IndexOf("!") - current.Event.LastIndexOf("_") - 1))))
                {
                    Console.WriteLine("              circular happen *********");
                    this.VerificationOutput.VerificationResult = VerificationResultType.INVALID;
                    this.VerificationOutput.LoopIndex          = visitedStates.IndexOf(current.Event);
                    this.VerificationOutput.NoOfStates         = Visited.Count;

                    return;
                }
                visitedStates.Add(current.Event);

                //for (int i = list.Length - 1; i >= 0; i--)
                foreach (ConfigurationBase step in list)
                {
                    //ConfigurationBase step = list[i];
                    string stepID = step.GetID();


                    if (!Visited.ContainsKey(stepID))
                    {
                        Visited.Add(stepID);
                        working.Enqueue(step);

                        List <ConfigurationBase> newPath = new List <ConfigurationBase>(currentPath);
                        newPath.Add(step);
                        paths.Enqueue(newPath);
                    }
                }
            } while (working.Count > 0);

            this.VerificationOutput.CounterExampleTrace = null;
            if (MustAbstract)
            {
                VerificationOutput.VerificationResult = VerificationResultType.UNKNOWN;
            }
            else
            {
                VerificationOutput.VerificationResult = VerificationResultType.VALID;
            }

            VerificationOutput.NoOfStates = Visited.Count;
        }
コード例 #22
0
        private void FailuresInclusionCheckDFSAntiChain(Automata spec)
        {
            Stack <ConfigurationBase> pendingImpl = new Stack <ConfigurationBase>(1024);
            Stack <NormalizedFAState> pendingSpec = new Stack <NormalizedFAState>(1024);
            List <ConfigurationBase>  toReturn    = new List <ConfigurationBase>();

            //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.

            NormalizedFAState initialSpec = (new NormalizedFAState(spec.InitialState)).TauReachable();

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

            //specification initial state
            pendingSpec.Push(initialSpec);

            AntiChain antichain = new AntiChain();

            antichain.Add(InitialStep.GetID(), initialSpec.States);

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

                ConfigurationBase currentImpl = pendingImpl.Pop();
                NormalizedFAState 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 the implememtation state is stable, then check for failures inclusion
                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];

                    NormalizedFAState nextSpec = currentSpec;

                    if (next.Event != Constants.TAU)
                    {
                        negatedRefusal.Add(next.Event);
                        nextSpec = currentSpec.NextWithTauReachable(next.Event);
                        //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.
                        if (nextSpec.States.Count == 0)
                        {
                            toReturn.Add(next);
                            VerificationOutput.NoOfStates          = antichain.GetNoOfStates();
                            VerificationOutput.CounterExampleTrace = toReturn;
                            VerificationOutput.VerificationResult  = VerificationResultType.INVALID;
                            FailureType = RefinementCheckingResultType.TraceRefinementFailure;
                            return;
                        }
                    }
                    else
                    {
                        hasTau = true;
                    }

                    if (!antichain.Add(next.GetID(), nextSpec.States))
                    {
                        pendingImpl.Push(next);
                        pendingSpec.Push(nextSpec);
                        depthStack.Push(depth + 1);
                    }
                }

                if (!hasTau)
                {
                    if (!RefusalContainment(negatedRefusal, currentSpec.GetFailuresNegate()))
                    {
                        VerificationOutput.NoOfStates          = antichain.GetNoOfStates();
                        VerificationOutput.CounterExampleTrace = toReturn;
                        VerificationOutput.VerificationResult  = VerificationResultType.INVALID;
                        FailureType = RefinementCheckingResultType.FailuresRefinementFailure;
                        return;
                    }
                }
            }

            VerificationOutput.NoOfStates         = antichain.GetNoOfStates();
            VerificationOutput.VerificationResult = VerificationResultType.VALID;
            FailureType = RefinementCheckingResultType.Valid;
        }
コード例 #23
0
        private void FailuresInclusionCheckBFSAntiChain(Automata spec)
        {
            Queue <ConfigurationBase>         pendingImpl = new Queue <ConfigurationBase>(1000);
            Queue <NormalizedFAState>         pendingSpec = new Queue <NormalizedFAState>(1000);
            Queue <List <ConfigurationBase> > paths       = new Queue <List <ConfigurationBase> >(1024);

            NormalizedFAState initialSpec = (new NormalizedFAState(spec.InitialState)).TauReachable();

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

            //specification initial state
            pendingSpec.Enqueue(initialSpec);

            List <ConfigurationBase> path = new List <ConfigurationBase>();

            path.Add(InitialStep);
            paths.Enqueue(path);

            AntiChain antichain = new AntiChain();

            antichain.Add(InitialStep.GetID(), initialSpec.States);

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

                ConfigurationBase        currentImpl = pendingImpl.Dequeue();
                NormalizedFAState        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];

                    NormalizedFAState nextSpec = currentSpec;
                    if (next.Event != Constants.TAU)
                    {
                        negatedRefusal.Add(next.Event);
                        nextSpec = currentSpec.NextWithTauReachable(next.Event);

                        if (nextSpec.States.Count == 0)
                        {
                            currentPath.Add(next);
                            VerificationOutput.NoOfStates          = antichain.GetNoOfStates();
                            VerificationOutput.CounterExampleTrace = currentPath;
                            VerificationOutput.VerificationResult  = VerificationResultType.INVALID;
                            FailureType = RefinementCheckingResultType.TraceRefinementFailure;
                            return;
                        }
                    }
                    else
                    {
                        hasTau = true;
                    }


                    if (!antichain.Add(next.GetID(), nextSpec.States))
                    {
                        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.GetFailuresNegate()))
                    {
                        //return toReturn;
                        VerificationOutput.NoOfStates          = antichain.GetNoOfStates();
                        VerificationOutput.CounterExampleTrace = currentPath;
                        VerificationOutput.VerificationResult  = VerificationResultType.INVALID;
                        FailureType = RefinementCheckingResultType.FailuresRefinementFailure;
                        return;
                    }
                }
            }

            VerificationOutput.NoOfStates         = antichain.GetNoOfStates();
            VerificationOutput.VerificationResult = VerificationResultType.VALID;
            FailureType = RefinementCheckingResultType.Valid;
        }
コード例 #24
0
        private MDP BuildMDPAntiChain_S()
        {
            DeterministicAutomata_Subset specAutomaton = BuildDeterministicAutomata_Subset(InitSpecStep);

            Stack <TupleSub> working = new Stack <TupleSub>(1024);

            DeterministicFAState_Subset InitialSpec = specAutomaton.InitialState;
            Dictionary <string, HashSet <DeterministicFAState_Subset> > antichain = new Dictionary <string, HashSet <DeterministicFAState_Subset> >();

            string   impID  = InitialStep.GetID();
            int      specID = InitialSpec.GetID();
            MDPState init   = new MDPState(impID + Constants.SEPARATOR + specID);

            working.Push(new TupleSub(InitialStep as MDPConfiguration, InitialSpec, init));


            MDP mdp = new MDP(init, Ultility.Ultility.DEFAULT_PRECISION, Ultility.Ultility.MAX_DIFFERENCE);
            HashSet <DeterministicFAState_Subset> Specs = new HashSet <DeterministicFAState_Subset>();

            Specs.Add(InitialSpec);
            antichain.Add(impID, Specs);

            do
            {
                if (CancelRequested)
                {
                    VerificationOutput.NoOfStates = mdp.States.Count;
                    return(mdp);
                }

                TupleSub 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 (MDPConfiguration step in list)
                    {
                        //MDPConfiguration step = list[i];
                        DeterministicFAState_Subset 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();
                        impID = step.GetID();

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

                        MDPState nextState;

                        if (!mdp.States.TryGetValue(stepID, out nextState))
                        {
                            nextState = new MDPState(stepID);
                            //mdp.AddState(nextState);
                            //KeyValuePair<MDPConfiguration, DeterministicFAState_Subset> newPair =
                            //    new KeyValuePair<MDPConfiguration, DeterministicFAState_Subset>(step, nextSpec);

                            //working.Push(new TupleSub(step, nextSpec, nextState));
                            bool addstate = true;
                            if (nextSpec != null)
                            {
                                //specID = nextSpec.GetID();

                                //DeterministicFAState_Subset DFAstate = nextSpec;
                                HashSet <DeterministicFAState_Subset> specStates;
                                //Dictionary<int, MDPState> mapping = null;
                                if (antichain.TryGetValue(impID, out specStates))
                                {
                                    HashSet <DeterministicFAState_Subset> toRemove =
                                        new HashSet <DeterministicFAState_Subset>();
                                    //int Spec = nextSpec.GetID();
                                    bool chainIncrease = true;
                                    foreach (DeterministicFAState_Subset specState in specStates)
                                    {
                                        //DeterministicFAState_Subset specState = specStates[j];
                                        if (specState.Sub.Contains(nextSpec))
                                        {
                                            toRemove.Add(specState);
                                            nextSpec.Sub.Add(specState);
                                            chainIncrease = false;
                                        }
                                        if (nextSpec.Sub.Contains(specState))
                                        {
                                            nextSpec      = specState;
                                            addstate      = false;
                                            chainIncrease = false;
                                            break;
                                        }
                                    }
                                    if (toRemove.Count > 0)
                                    {
                                        foreach (var specState in toRemove)
                                        {
                                            specStates.Remove(specState);
                                        }
                                        specStates.Add(nextSpec); // toRemove;
                                    }
                                    else if (chainIncrease)
                                    {
                                        specStates.Add(nextSpec);
                                    }
                                }
                                else
                                {
                                    HashSet <DeterministicFAState_Subset> newSpecs = new HashSet <DeterministicFAState_Subset>();
                                    newSpecs.Add(nextSpec);
                                    antichain.Add(impID, newSpecs);
                                }
                            }
                            if (addstate)
                            {
                                mdp.AddState(nextState);
                                working.Push(new TupleSub(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);
        }
コード例 #25
0
        public void DFSVerification()
        {
            StringHashTable Visited = new StringHashTable(1048576);

            Stack <ConfigurationBase> working = new Stack <ConfigurationBase>(1024);

            Visited.Add(InitialStep.GetID());

            working.Push(InitialStep);
            Stack <int> depthStack = new Stack <int>(1024);

            depthStack.Push(0);

            List <int>    depthList     = new List <int>(1024);
            List <String> visitedStates = new List <String>();

            do
            {
                if (CancelRequested)
                {
                    this.VerificationOutput.NoOfStates = Visited.Count;
                    return;
                }

                ConfigurationBase current = working.Pop();

                int depth = depthStack.Pop();

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

                        depthList.RemoveAt(lastIndex);
                        this.VerificationOutput.CounterExampleTrace.RemoveAt(lastIndex);
                        visitedStates.RemoveAt(lastIndex);
                    }
                }

                this.VerificationOutput.CounterExampleTrace.Add(current);

                IEnumerable <ConfigurationBase> list = current.MakeOneMove();
                this.VerificationOutput.Transitions += list.Count();
                Console.Write("tracing event: " + current.Event + " " + current.GetID());
                Console.WriteLine(toStringCounterExample(this.VerificationOutput.CounterExampleTrace) + "\n");

                // track dpulicate channel input
                if (current.Event.IndexOf("!") != -1 && visitedStates.Contains(current.Event.Substring(0, current.Event.IndexOf("!"))))
                {
                    Console.WriteLine("              bootleneck happen *********");
                    this.VerificationOutput.VerificationResult = VerificationResultType.INVALID;
                    this.VerificationOutput.LoopIndex          = visitedStates.IndexOf(current.Event.Substring(0, current.Event.IndexOf("!")));
                    this.VerificationOutput.NoOfStates         = Visited.Count;
                    return;
                }
                if (current.Event.IndexOf("!") != -1)
                {
                    visitedStates.Add(current.Event.Substring(0, current.Event.IndexOf("!")));
                }
                else if (current.Event.IndexOf("?") != -1)
                {
                    visitedStates.Add(current.Event.Substring(0, current.Event.IndexOf("?")));
                }
                else
                {
                    visitedStates.Add(current.Event);
                }

                depthList.Add(depth);

                //for (int i = list.Length - 1; i >= 0; i--)
                foreach (ConfigurationBase step in list)
                {
                    //ConfigurationBase step = list[i];
                    string stepID = step.GetID();


                    if (step.Event != Constants.TERMINATION)
                    {
                        if (!Visited.ContainsKey(stepID))
                        {
                            Visited.Add(stepID);
                            working.Push(step);
                            depthStack.Push(depth + 1);
                        }
                    }
                }
            } while (working.Count > 0);


            this.VerificationOutput.CounterExampleTrace = null;

            if (MustAbstract)
            {
                this.VerificationOutput.VerificationResult = VerificationResultType.UNKNOWN;
            }
            else
            {
                this.VerificationOutput.VerificationResult = VerificationResultType.VALID;
            }

            this.VerificationOutput.NoOfStates = Visited.Count;
        }
コード例 #26
0
        virtual public void BFSVerification()
        {
            StringHashTable Visited = new StringHashTable(Ultility.Ultility.MC_INITIAL_SIZE);

            Expression conditionExpression = this.ReachableStateCondition;

            Queue <ConfigurationBase>         working = new Queue <ConfigurationBase>(1024);
            Queue <List <ConfigurationBase> > paths   = new Queue <List <ConfigurationBase> >(1024);

            Visited.Add(InitialStep.GetID());

            working.Enqueue(InitialStep);

            List <ConfigurationBase> path = new List <ConfigurationBase>();

            path.Add(InitialStep);
            paths.Enqueue(path);

            do
            {
                if (CancelRequested)
                {
                    VerificationOutput.NoOfStates = Visited.Count;
                    return;
                }

                ConfigurationBase        current     = working.Dequeue();
                List <ConfigurationBase> currentPath = paths.Dequeue();

                if (current.ImplyCondition(conditionExpression))
                {
                    VerificationOutput.VerificationResult  = VerificationResultType.VALID;
                    VerificationOutput.NoOfStates          = Visited.Count;
                    VerificationOutput.CounterExampleTrace = currentPath;
                    return;
                }

                //ConfigurationBase[] list = current.MakeOneMove().ToArray();
                //VerificationOutput.Transitions += list.Length;
                IEnumerable <ConfigurationBase> list = current.MakeOneMove();
                VerificationOutput.Transitions += list.Count();

                //for (int i = list.Length - 1; i >= 0; i--)
                foreach (ConfigurationBase step in list)
                {
                    //ConfigurationBase step = list[i];
                    string stepID = step.GetID();
                    if (!Visited.ContainsKey(stepID))
                    {
                        Visited.Add(stepID);
                        working.Enqueue(step);

                        List <ConfigurationBase> newPath = new List <ConfigurationBase>(currentPath);
                        newPath.Add(step);
                        paths.Enqueue(newPath);
                    }
                }
            } while (working.Count > 0);


            VerificationOutput.VerificationResult = VerificationResultType.INVALID;

            VerificationOutput.NoOfStates = Visited.Count;
        }
コード例 #27
0
        public void BFSVerification()
        {
            StringHashTable Visited = new StringHashTable(Ultility.Ultility.MC_INITIAL_SIZE);

            Queue <ConfigurationBase>         working = new Queue <ConfigurationBase>(1024);
            Queue <List <ConfigurationBase> > paths   = new Queue <List <ConfigurationBase> >(1024);

            Visited.Add(InitialStep.GetID());

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

            path.Add(InitialStep);
            paths.Enqueue(path);

            do
            {
                if (CancelRequested)
                {
                    VerificationOutput.NoOfStates = Visited.Count;
                    return;
                }

                ConfigurationBase               current     = working.Dequeue();
                List <ConfigurationBase>        currentPath = paths.Dequeue();
                IEnumerable <ConfigurationBase> list        = current.MakeOneMove();
                this.VerificationOutput.Transitions += list.Count();

                Debug.Assert(currentPath[currentPath.Count - 1].GetID() == current.GetID());

                //If the current process is deadlocked, return true if the current BA state is accepting. Otherwise, return false;
                if (current.IsDeadLock)
                {
                    //if (this.isNotTerminationTesting || current.Event != Constants.TERMINATION)
                    //{
                    this.VerificationOutput.VerificationResult  = VerificationResultType.INVALID;
                    this.VerificationOutput.NoOfStates          = Visited.Count;
                    this.VerificationOutput.CounterExampleTrace = currentPath;
                    return;
                    //}
                }

                //for (int i = list.Length - 1; i >= 0; i--)
                foreach (ConfigurationBase step in list)
                {
                    //ConfigurationBase step = list[i];
                    string stepID = step.GetID();

                    if (step.Event == Constants.TERMINATION)
                    {
                        if (isNotTerminationTesting)
                        {
                            this.VerificationOutput.CounterExampleTrace.Add(step);
                            this.VerificationOutput.VerificationResult = VerificationResultType.INVALID;
                            this.VerificationOutput.NoOfStates         = Visited.Count;
                            return;
                        }
                    }
                    else
                    {
                        if (!Visited.ContainsKey(stepID))
                        {
                            Visited.Add(stepID);
                            working.Enqueue(step);

                            List <ConfigurationBase> newPath = new List <ConfigurationBase>(currentPath);
                            newPath.Add(step);
                            paths.Enqueue(newPath);
                        }
                    }
                }
            } while (working.Count > 0);

            this.VerificationOutput.CounterExampleTrace = null;
            if (MustAbstract)
            {
                VerificationOutput.VerificationResult = VerificationResultType.UNKNOWN;
            }
            else
            {
                VerificationOutput.VerificationResult = VerificationResultType.VALID;
            }

            VerificationOutput.NoOfStates = Visited.Count;
        }
コード例 #28
0
        public void DFSVerification()
        {
            StringHashTable Visited = new StringHashTable(Ultility.Ultility.MC_INITIAL_SIZE);

            Stack <ConfigurationBase> working = new Stack <ConfigurationBase>(1024);

            Visited.Add(InitialStep.GetID());

            working.Push(InitialStep);
            Stack <int> depthStack = new Stack <int>(1024);

            depthStack.Push(0);

            List <int> depthList = new List <int>(1024);

            do
            {
                if (CancelRequested)
                {
                    this.VerificationOutput.NoOfStates = Visited.Count;
                    return;
                }

                ConfigurationBase current = working.Pop();
                int depth = depthStack.Pop();

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

                this.VerificationOutput.CounterExampleTrace.Add(current);
                IEnumerable <ConfigurationBase> list = current.MakeOneMove();
                this.VerificationOutput.Transitions += list.Count();

                if (current.IsDeadLock)
                {
                    //if (isNotTerminationTesting || current.Event != Constants.TERMINATION)
                    //{
                    this.VerificationOutput.VerificationResult = VerificationResultType.INVALID;
                    this.VerificationOutput.NoOfStates         = Visited.Count;
                    return;
                    //}
                }

                depthList.Add(depth);

                //for (int i = list.Length - 1; i >= 0; i--)
                foreach (ConfigurationBase step in list)
                {
                    //ConfigurationBase step = list[i];
                    string stepID = step.GetID();

                    if (step.Event == Constants.TERMINATION)
                    {
                        if (isNotTerminationTesting)
                        {
                            this.VerificationOutput.CounterExampleTrace.Add(step);
                            this.VerificationOutput.VerificationResult = VerificationResultType.INVALID;
                            this.VerificationOutput.NoOfStates         = Visited.Count;
                            return;
                        }
                    }
                    else
                    {
                        if (!Visited.ContainsKey(stepID))
                        {
                            Visited.Add(stepID);
                            working.Push(step);
                            depthStack.Push(depth + 1);
                        }
                    }
                }
            } while (working.Count > 0);

            this.VerificationOutput.CounterExampleTrace = null;

            if (MustAbstract)
            {
                this.VerificationOutput.VerificationResult = VerificationResultType.UNKNOWN;
            }
            else
            {
                this.VerificationOutput.VerificationResult = VerificationResultType.VALID;
            }

            this.VerificationOutput.NoOfStates = Visited.Count;
        }
コード例 #29
0
        virtual public void DFSVerification()
        {
            StringHashTable Visited = new StringHashTable(Ultility.Ultility.MC_INITIAL_SIZE);

            Expression conditionExpression = ReachableStateCondition;

            Stack <ConfigurationBase> working = new Stack <ConfigurationBase>(1024);

            Visited.Add(InitialStep.GetID());

            working.Push(InitialStep);
            Stack <int> depthStack = new Stack <int>(1024);

            depthStack.Push(0);

            List <int> depthList = new List <int>(1024);

            do
            {
                if (CancelRequested)
                {
                    VerificationOutput.NoOfStates = Visited.Count;
                    return;
                }

                ConfigurationBase current = working.Pop();
                int depth = depthStack.Pop();

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

                VerificationOutput.CounterExampleTrace.Add(current);

                if (current.ImplyCondition(conditionExpression))
                {
                    VerificationOutput.VerificationResult = VerificationResultType.VALID;
                    VerificationOutput.NoOfStates         = Visited.Count;
                    return;
                }

                depthList.Add(depth);
                IEnumerable <ConfigurationBase> list = current.MakeOneMove();
                VerificationOutput.Transitions += list.Count();

                //for (int i = list.Length - 1; i >= 0; i--)
                foreach (ConfigurationBase step in list)
                {
                    //ConfigurationBase step = list[i];

                    string stepID = step.GetID();
                    if (!Visited.ContainsKey(stepID))
                    {
                        Visited.Add(stepID);
                        working.Push(step);
                        depthStack.Push(depth + 1);
                    }
                }
            } while (working.Count > 0);

            VerificationOutput.CounterExampleTrace = null;
            VerificationOutput.VerificationResult  = VerificationResultType.INVALID;
            VerificationOutput.NoOfStates          = Visited.Count;
        }
コード例 #30
0
        private MDP BuildMDPSubset()
        {
            DeterministicAutomata_Subset specAutomaton = BuildDeterministicAutomata_Subset(InitSpecStep);

            Stack <TupleSub> working = new Stack <TupleSub>(1024);

            DeterministicFAState_Subset InitialSpec = specAutomaton.InitialState;


            Dictionary <string, Dictionary <int, MDPState> > visited = new Dictionary <string, Dictionary <int, MDPState> >();

            int    specID = InitialSpec.GetID();
            string impID  = InitialStep.GetID();

            MDPState init = new MDPState(impID + Constants.SEPARATOR + specID);

            working.Push(new TupleSub(InitialStep as MDPConfiguration, InitialSpec, init));

            Dictionary <int, MDPState> initialDic = new Dictionary <int, MDPState>();

            initialDic.Add(specID, init);
            visited.Add(impID, initialDic);

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

            do
            {
                if (CancelRequested)
                {
                    VerificationOutput.NoOfStates = mdp.States.Count;
                    return(mdp);
                }

                TupleSub 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_Subset 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();
                        impID = step.GetID();

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

                        MDPState nextState;

                        if (!mdp.States.TryGetValue(stepID, out nextState))
                        {
                            nextState = new MDPState(stepID);
                            //mdp.AddState(nextState);
                            //KeyValuePair<MDPConfiguration, DeterministicFAState_Subset> newPair =
                            //    new KeyValuePair<MDPConfiguration, DeterministicFAState_Subset>(step, nextSpec);

                            working.Push(new TupleSub(step, nextSpec, nextState));

                            if (nextSpec != null)
                            {
                                specID = nextSpec.GetID();

                                //DeterministicFAState_Subset DFAstate = nextSpec;

                                Dictionary <int, MDPState> mapping = null;
                                if (visited.TryGetValue(impID, out mapping))
                                {
                                    //int Spec = nextSpec.GetID();
                                    mapping.Add(specID, nextState);

                                    foreach (int spec in mapping.Keys)
                                    {
                                        if (specAutomaton.States[spec].Sub.Contains(nextSpec))
                                        {
                                            mapping[spec].Sub.Add(nextState);
                                        }

                                        else if (nextSpec.Sub.Contains(specAutomaton.States[spec]))
                                        {
                                            nextState.Sub.Add(mapping[spec]);
                                        }
                                    }

                                    //foreach (var x in visited)
                                    //{

                                    //    if (x.Key.Key.GetID() == newPair.Key.GetID() &&
                                    //        x.SpecState.Sub.Contains(newPair.Value))
                                    //    {
                                    //        x.Value.Sub.Add(nextState);
                                    //    }
                                    //    else if (x.Key.Key.GetID() == newPair.Key.GetID() &&
                                    //             newPair.Value.Sub.Contains(x.SpecState))
                                    //    {
                                    //        nextState.Sub.Add(x.Value);
                                    //    }
                                    //}

                                    //visited.Add(newPair, nextState);
                                }
                                else
                                {
                                    Dictionary <int, MDPState> newDicDic = new Dictionary <int, MDPState>();
                                    newDicDic.Add(specID, nextState);
                                    visited.Add(impID, newDicDic);
                                }
                            }

                            mdp.AddState(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);
        }