예제 #1
0
        //public StringHashTable WildVars;
        //the following fields stores only default settings used for the simulation, so there is no need to change them after parsing.
        //public FairnessType FairnessType;
        //public bool CalculateParticipatingProcess;
        //public bool TimedRefinementAssertion;
        //public int TimedRefinementClockCeiling;
        //public int TimedRefinementClockFloor;
        //public CSPDataStore DataManager;
        public SharedDataObjectBase()
        {
            //DataManager = new CSPDataStore();
            //AlphaDatabase = new Dictionary<string, EventCollection>(8);
            VariableLowerBound = new StringDictionary<int>(8);
            VariableUpperLowerBound = new StringDictionary<int>(8);
            ValutionHashTable = new StringDictionary<string>(Ultility.Ultility.MC_INITIAL_SIZE);

            SyncrhonousChannelNames = new List<string>();
            HasSyncrhonousChannel = false;
            HasAtomicEvent = false;
            //TimedRefinementAssertion = false;

            CSharpMethods = new Dictionary<string, System.Reflection.MethodInfo>();
            CSharpDataType = new Dictionary<string, Type>();
            //MacroDefinition = new Dictionary<string, KeyValuePair<List<string>, Expression>>();

            //FairnessType = FairnessType.NO_FAIRNESS;
            //CalculateParticipatingProcess = false;
            //CalculateCreatedProcess = false;

            //TimedRefinementClockCeiling = Common.Classes.Ultility.Ultility.TIME_REFINEMENT_CLOCK_CEILING;
            //TimedRefinementClockFloor = Common.Classes.Ultility.Ultility.TIME_REFINEMENT_CLOCK_FLOOR;

            LocalVars = null;
            //WildVars = null;
        }
예제 #2
0
        public void BFSVerification()
        {
            //Dictionary<string, bool> Visited = new Dictionary<string, bool>();
            StringHashTable Visited = new StringHashTable(Ultility.Ultility.MC_INITIAL_SIZE);
            Queue<EventBAPairSafety> working = new Queue<EventBAPairSafety>();
            Queue<List<ConfigurationBase>> paths = new Queue<List<ConfigurationBase>>(1024);

            EventBAPairSafety initialstep = EventBAPairSafety.GetInitialPairs(BA,InitialStep);
            working.Enqueue(initialstep);

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

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

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

                if (current.States.Count == 0)
                {
                    VerificationOutput.VerificationResult = VerificationResultType.INVALID;
                    VerificationOutput.NoOfStates = Visited.Count;
                    VerificationOutput.CounterExampleTrace = currentPath;
                    return;
                }

                ConfigurationBase[] steps = current.configuration.MakeOneMove().ToArray();
                VerificationOutput.Transitions += steps.Length;
                EventBAPairSafety[] products = current.Next(BA, steps);
                foreach (EventBAPairSafety step in products)
                {
                    string stepID = step.GetCompressedState();
                    if (!Visited.ContainsKey(stepID))
                    {
                        Visited.Add(stepID);
                        working.Enqueue(step);

                        List<ConfigurationBase> newPath = new List<ConfigurationBase>(currentPath);
                        newPath.Add(step.configuration);
                        paths.Enqueue(newPath);
                    }
                }

            } while (working.Count > 0);

            VerificationOutput.NoOfStates = Visited.Count;
            VerificationOutput.VerificationResult = VerificationResultType.VALID;
        }
예제 #3
0
        protected Dictionary<string, LocalPair> TarjanModelChecking2(Dictionary<string, LocalPair> SCC, Dictionary<string, List<string>> OutgoingTransitionTable)
        {
            Dictionary<string, LocalPair> StronglyConnectedComponets = new Dictionary<string, LocalPair>(64);

            Dictionary<string, int> preorder = new Dictionary<string, int>(64);
            Dictionary<string, int> lowlink = new Dictionary<string, int>(64);
            Stack<string> scc_stack = new Stack<string>(64);
            StringHashTable scc_found = new StringHashTable(64);

            int i = 0; //# Preorder counter

            Stack<string> idStack = new Stack<string>(1024);

            Dictionary<string, LocalPair>.KeyCollection.Enumerator emun = SCC.Keys.GetEnumerator();
            emun.MoveNext();

            idStack.Push(emun.Current);

            do
            {
                string v = idStack.Peek();
                List<string> outgoing = OutgoingTransitionTable[v];

                if (!preorder.ContainsKey(v))
                {
                    preorder.Add(v, i);
                    i++;
                }
                bool done = true;
                for (int j = 0; j < outgoing.Count; j++)
                {
                    string w = outgoing[j];
                    if (SCC.ContainsKey(w) && !preorder.ContainsKey(w))
                    {
                        idStack.Push(w);
                        done = false;
                        break;
                    }
                }

                if (done)
                {
                    int lowlinkV = preorder[v];
                    int preorderV = lowlinkV;

                    bool selfLoop = false;

                    for (int j = 0; j < outgoing.Count; j++)
                    {
                        string w = outgoing[j];

                        if (SCC.ContainsKey(w))
                        {
                            if (w == v)
                            {
                                selfLoop = true;
                            }
                            if (!scc_found.ContainsKey(w))
                            {
                                if (preorder[w] > preorderV)
                                {
                                    lowlinkV = Math.Min(lowlinkV, lowlink[w]);
                                }
                                else
                                {
                                    lowlinkV = Math.Min(lowlinkV, preorder[w]);
                                }
                            }
                        }
                    }
                    lowlink[v] = lowlinkV;
                    idStack.Pop();

                    if (lowlinkV == preorderV)
                    {
                        scc_found.Add(v);
                        StronglyConnectedComponets.Add(v, SCC[v]);

                        //checking for buchi fair
                        bool BuchiFair = SCC[v].state.EndsWith(Constants.ACCEPT_STATE);

                        while (scc_stack.Count > 0 && preorder[scc_stack.Peek()] > preorderV)
                        {
                            string k = scc_stack.Pop();//.Dequeue();
                            StronglyConnectedComponets.Add(k, SCC[k]);
                            scc_found.Add(k);

                            if (!BuchiFair && SCC[k].state.EndsWith(Constants.ACCEPT_STATE))
                            {
                                BuchiFair = true;
                            }
                        }

                        if (BuchiFair && (outgoing.Count == 0 || StronglyConnectedComponets.Count > 1 || selfLoop))
                        {
                            Dictionary<string, LocalPair> value = IsFair(StronglyConnectedComponets, OutgoingTransitionTable);
                            if (value != null)
                            {
                                return value;
                            }
                        }

                        StronglyConnectedComponets.Clear();
                    }
                    else
                    {
                        scc_stack.Push(v);
                    }
                }

                //because the SCC can be brekon by removing bad states,
                //if there is such case, the SCC are forests. so we have to check all components
                if (idStack.Count == 0 && scc_found.Count != SCC.Count)
                {
                    foreach (string key in SCC.Keys)
                    {
                        if (!scc_found.ContainsKey(key))
                        {
                            idStack.Push(key);
                            break;
                        }
                    }
                }

            } while (idStack.Count > 0);

            return null;
        }
예제 #4
0
        public virtual 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;
        }
예제 #5
0
        public virtual 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;
        }
예제 #6
0
        public void FailuresDivergenceInclusionCheckBFS(DeterministicAutomata spec)
        {
            StringHashTable Visited = new StringHashTable(Ultility.Ultility.MC_INITIAL_SIZE);
            Stack<ConfigurationBase> pendingImpl = new Stack<ConfigurationBase>(1000);
            Stack<DeterministicFAState> pendingSpec = new Stack<DeterministicFAState>(1000);
            Queue<List<ConfigurationBase>> paths = new Queue<List<ConfigurationBase>>(1024);

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

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

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

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

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

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

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

                bool implIsDiv = currentImpl.IsDivergent();

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

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

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

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

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

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

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

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

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

            VerificationOutput.NoOfStates = Visited.Count;
            VerificationOutput.VerificationResult = VerificationResultType.VALID;
            FailureType = RefinementCheckingResultType.Valid;
        }
예제 #7
0
        private void MonoBFSVerification()
        {
            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);

            ExtremValue = null;
            ReachableCount = 0;

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

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

                Expression v = current.EvaluateExpression(ConstraintCondition);
                if (v is IntConstant)
                {
                    int value = (v as IntConstant).Value;

                    if (current.ImplyCondition(conditionExpression))
                    {
                        ReachableCount++;

                        if (ExtremValue == null)
                        {
                            ExtremValue = value;
                            VerificationOutput.CounterExampleTrace = new List<ConfigurationBase>(currentPath);
                        }
                        else
                        {
                            switch (Contraint)
                            {
                                case QueryConstraintType.MAX:
                                    if (value > ExtremValue.Value)
                                    {
                                        ExtremValue = value;
                                        VerificationOutput.CounterExampleTrace = new List<ConfigurationBase>(currentPath);
                                    }
                                    break;
                                case QueryConstraintType.MIN:
                                    if (value < ExtremValue.Value)
                                    {
                                        ExtremValue = value;
                                        VerificationOutput.CounterExampleTrace = new List<ConfigurationBase>(currentPath);
                                    }
                                    break;
                            }
                        }
                    }
                    else
                    {
                        bool Skip = false;
                        if (ExtremValue != null)
                        {
                            switch (Contraint)
                            {
                                case QueryConstraintType.MAX:
                                    if (value < ExtremValue.Value)
                                    {
                                        Skip = true;
                                    }
                                    break;
                                case QueryConstraintType.MIN:
                                    if (value > ExtremValue.Value)
                                    {
                                        Skip = true;
                                    }
                                    break;
                            }
                        }

                        if (!Skip)
                        {
                            ConfigurationBase[] list = current.MakeOneMove().ToArray();
                            VerificationOutput.Transitions += list.Length;

                            for (int i = list.Length - 1; i >= 0; i--)
                            {
                                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);

            if (ExtremValue == null)
            {
                VerificationOutput.VerificationResult = VerificationResultType.INVALID;
                VerificationOutput.CounterExampleTrace = null;
            }
            else
            {
                VerificationOutput.VerificationResult = VerificationResultType.VALID;
            }

            VerificationOutput.NoOfStates = Visited.Count;
        }
예제 #8
0
        public void DFSVerification()
        {
            StringHashTable Visited = new StringHashTable(Ultility.Ultility.MC_INITIAL_SIZE);
            Stack<ConfigurationBase> working = new Stack<ConfigurationBase>(1024);
            Dictionary<string, List<string>> Transitions = new Dictionary<string, List<string>>();
            Dictionary<string, ConfigurationBase> IDs = new Dictionary<string, ConfigurationBase>();

            Visited.Add(InitialStep.GetID());
            working.Push(InitialStep);

            const int VISITED_NOPREORDER = -1;
            const int SCC_FOUND = -2;
            //const int DL_FOUND = -3;
            //DFS data, which mapping each state to an int[] of size 3, first is the pre-order, second is the lowlink, last one is DRAState
            bool reachDL = true;
            bool reachTL = true;

            Dictionary<string, int[]> DFSData = new Dictionary<string, int[]>(Ultility.Ultility.MC_INITIAL_SIZE);
            DFSData.Add(InitialStep.GetID(), new int[] { VISITED_NOPREORDER, 0 });
            HashSet<string> ReachDLStates = new HashSet<string>();
            HashSet<string> ReachTLStates = new HashSet<string>();
            int preordercounter = 0;
            Dictionary<string, List<ConfigurationBase>> ExpendedNode = new Dictionary<string, List<ConfigurationBase>>();
            Stack<ConfigurationBase> stepStack = new Stack<ConfigurationBase>(1024);
            do
            {

                ConfigurationBase currentState = working.Peek();
                string currentID = currentState.GetID();

                int[] nodeData = DFSData[currentID];

                if (nodeData[0] == VISITED_NOPREORDER)
                {
                    nodeData[0] = preordercounter;
                    preordercounter++;
                }

                bool done = true;

                if (ExpendedNode.ContainsKey(currentID))
                {
                    if (reachDL)
                    {
                        ReachDLStates.Add(currentID);
                    }
                    else
                    {
                        reachDL = ReachDLStates.Contains(currentID);
                    }

                    if (reachTL)
                    {
                        ReachTLStates.Add(currentID);
                    }
                    else
                    {
                        reachTL = ReachTLStates.Contains(currentID);
                    }

                    List<ConfigurationBase> list = ExpendedNode[currentID];
                    if (list.Count > 0)
                    {
                        for (int k = list.Count - 1; k >= 0; k--)
                        {
                            ConfigurationBase step = list[k];
                            string stepID = step.GetID();
                            //if (!preorder.ContainsKey(stepID))
                            if (DFSData[stepID][0] == VISITED_NOPREORDER)
                            {
                                if (done)
                                {
                                    working.Push(step);
                                    done = false;
                                    list.RemoveAt(k);
                                }
                            }
                            else
                            {
                                if (ReachDLStates.Contains(stepID))
                                {
                                    reachDL = true;
                                    ReachDLStates.Add(stepID);
                                }
                                if (ReachTLStates.Contains(stepID))
                                {
                                    reachTL = true;
                                    ReachTLStates.Add(stepID);
                                }
                                list.RemoveAt(k);
                            }
                        }
                    }
                }
                else
                {
                    reachTL = false;
                    reachDL = false;
                    //if(currentState.IsDeadLock)
                    //{
                    //    DeadlockStates.Add(currentID);
                    //    DFSData[currentID][0] = SCC_FOUND;
                    //    continue;
                    //}
                    List<ConfigurationBase> stepsList = new List<ConfigurationBase>(currentState.MakeOneMove());//List<ConfigurationBase>();
                    if (stepsList.Count == 0)
                    {
                        deadlockStates.Add(currentState);
                        //DFSData[currentID][0] = SCC_FOUND;
                        DFSData[currentID][0] = SCC_FOUND;
                        ReachDLStates.Add(currentID);
                        reachDL = true;
                        working.Pop();
                        continue;
                    }
                    this.VerificationOutput.Transitions += stepsList.Count();
                    //List<ConfigurationBase> backupSteps = new List<ConfigurationBase>(currentState.MakeOneMove());
                    List<string> ids = new List<string>();
                    foreach(var conf in stepsList)
                    {
                        ids.Add(conf.GetID());
                    }
                    Transitions.Add(currentID, ids);
                    //foreach (var distr in currentState.Distributions)
                    //{
                    //    if (distr.inMatrix) continue;
                    //    foreach (var kvPair in distr.States)
                    //    {
                    //        stepsList.Add(kvPair.Value);
                    //    }
                    //}));

                    for (int k = stepsList.Count - 1; k >= 0; k--)
                    {
                        ConfigurationBase nextState = stepsList[k];
                        //nextState.DisplayName
                        //string tmp = step.ID;
                        int[] data;
                        string NextID = nextState.GetID();

                        if (Visited.ContainsKey(NextID))
                        {
                            DFSData.TryGetValue(NextID, out data);
                            if (data[0] == VISITED_NOPREORDER)
                            {
                                if (done)
                                {
                                    working.Push(nextState);
                                    done = false;
                                    stepsList.RemoveAt(k);
                                }
                                else
                                {
                                    stepsList[k] = nextState;
                                }
                            }
                            else
                            {
                                if(ReachDLStates.Contains(NextID))
                                {
                                    reachDL = true;
                                    ReachDLStates.Add(currentID);
                                }
                                if (ReachTLStates.Contains(NextID))
                                {
                                    reachTL = true;
                                    ReachTLStates.Add(currentID);
                                }
                                stepsList.RemoveAt(k);
                            }
                        }
                        else
                        {

                            DFSData.Add(NextID, new int[] { VISITED_NOPREORDER, 0 });
                            Visited.Add(NextID);
                            IDs.Add(NextID, nextState);
                            if (done)
                            {
                                working.Push(nextState);
                                done = false;
                                stepsList.RemoveAt(k);
                            }
                            else
                            {
                                stepsList[k] = nextState;

                            }
                        }
                    }

                    ExpendedNode.Add(currentID, stepsList);
                }

                if (done)
                {
                    int lowlinkV = nodeData[0];
                    int preorderV = lowlinkV;

                    bool selfLoop = false;
                    foreach (var tran in Transitions[currentID])
                    {
                        //if (list.inMatrix) continue;
                        //foreach (KeyValuePair<double, MDPState> state in list.States)
                        //{
                        string w = tran;

                        if (w == currentID)
                        {
                            selfLoop = true;
                        }
                        int[] wdata = DFSData[w];
                        if (wdata[0] != SCC_FOUND)
                        {
                            if (wdata[0] > preorderV)
                            {
                                lowlinkV = Math.Min(lowlinkV, wdata[1]);
                            }
                            else
                            {
                                lowlinkV = Math.Min(lowlinkV, wdata[0]);
                            }
                        }
                    }

                    nodeData[1] = lowlinkV;
                    working.Pop();

                    if (lowlinkV == preorderV)
                    {
                        List<string> scc = new List<string>();
                        scc.Add(currentID);

                        nodeData[0] = SCC_FOUND;
                        while (stepStack.Count > 0 && DFSData[stepStack.Peek().GetID()][0] > preorderV)
                        {
                            ConfigurationBase s = stepStack.Pop();
                            string sID = s.GetID();
                            scc.Add(sID);
                            DFSData[sID][0] = SCC_FOUND;
                        }

                        if (scc.Count > 1 || selfLoop)
                        {
                            bool terminal = true;
                            foreach (var state in scc)
                            {
                                foreach (var nextState in Transitions[state])
                                {
                                    if (!scc.Contains(nextState))
                                    {
                                        terminal = false;
                                        break;
                                    }
                                }
                                if (!terminal)
                                {
                                    break;
                                }
                            }
                            if (terminal)
                            {
                                List<ConfigurationBase> SCC = new List<ConfigurationBase>();
                                foreach(string state in scc)
                                {
                                    SCC.Add(IDs[state]);
                                    ReachTLStates.Add(state);
                                }
                                reachTL = true;
                                reachDL = false;
                                TLoops.Add(SCC);
                            }

                        }

                    }
                    else
                    {
                        stepStack.Push(currentState);
                    }
                }

            } while (working.Count > 0);

            if (deadlockStates.Count == 0)
            {
                VerificationOutput.VerificationResult = VerificationResultType.VALID;
            }
            else
            {
                VerificationOutput.VerificationResult = VerificationResultType.INVALID;
                //int i = 0;
                //for (; i < DeadlockStates.Count - 1; i++)
                //{
                //    deadlockstates += DeadlockStates[i] + ", ";
                //}
                //deadlockstates += DeadlockStates[i];
                //for (int j = 0; j < TerminalSCC.Count; j++)
                //{
                //    TLoops += "Loop" + j + "is: <";
                //    int k = 0;
                //    for (; k < TerminalSCC[j].Count - 1; k++)
                //    {
                //        TLoops += TerminalSCC[j][k] + ", ";
                //    }
                //    TLoops += TerminalSCC[j][k] + ">\n\t";
                //}
            }
            reachDLCounter = ReachDLStates.Count;
            reachTLCounter = ReachTLStates.Count;
            VerificationOutput.NoOfStates = Visited.Count;
        }
예제 #9
0
        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)
                {
                    IEnumerable<ConfigurationBase> steps = current.MakeOneMove(Event);
                    if (steps.Count() > 1)
                    //if (steps.Length > 1)
                    {
                        this.VerificationOutput.CounterExampleTrace = ConcreteCounterExampleTrace;
                        return false;
                    }
                }
                else
                {
                    ConfigurationBase abstractStep = this.VerificationOutput.CounterExampleTrace[depth + 1];
                    IEnumerable<ConfigurationBase> steps = current.MakeOneMove(abstractStep.Event);
                    //for (int j = 0; j < steps.Length; j++)
                    foreach (ConfigurationBase step in steps)
                    {
                        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;
        }
예제 #10
0
        public void BFSVerification()
        {
            StringHashTable Visited = new StringHashTable(Ultility.Ultility.MC_INITIAL_SIZE);
            VisitedNonDivStates = new HashSet<string>();
            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)
                {
                    this.VerificationOutput.NoOfStates = Visited.Count;
                    return;
                }

                ConfigurationBase current = working.Dequeue();
                List<ConfigurationBase> currentPath = paths.Dequeue();
                ConfigurationBase[] list = current.MakeOneMove().ToArray();

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

                VerificationOutput.Transitions += list.Length;

                //if (current.IsDivergent())
                if (!VisitedNonDivStates.Contains(current.GetID()) && IsDivergent(current))
                {
                    VerificationOutput.VerificationResult = VerificationResultType.INVALID;
                    VerificationOutput.NoOfStates = Visited.Count;
                    VerificationOutput.CounterExampleTrace = currentPath;
                    //VerificationOutput.CounterExampleTrace.RemoveAt(VerificationOutput.CounterExampleTrace.Count - 1);
                    LoopIndex = VerificationOutput.CounterExampleTrace.Count;
                    return;
                }

                for (int i = list.Length - 1; i >= 0; i--)
                {
                    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.CounterExampleTrace = null;
            VerificationOutput.VerificationResult = VerificationResultType.VALID;
            VerificationOutput.NoOfStates = Visited.Count;
            return;
        }
예제 #11
0
        public bool IsDivergent()
        {
            Stack<ConfigurationBase> working = new Stack<ConfigurationBase>();
            List<string> path = new List<string>(100);
            StringHashTable visited = new StringHashTable(100);

            //The following are for identifying the current path.
            Stack<int> depthStack = new Stack<int>(1024);
            depthStack.Push(0);
            List<int> depthList = new List<int>(1024);
            //The above are for identifying the current path.

            working.Push(this);
            visited.Add(GetID());

            while (working.Count > 0)
            {
                ConfigurationBase current = working.Pop();
                IEnumerable<ConfigurationBase> nextStates = current.MakeOneMove(Constants.TAU);

                //The following are for identifying the current path.
                int depth = depthStack.Pop();

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

                path.Add(current.GetID());
                depthList.Add(depth);

                if (nextStates != null)
                {
                    //for (int i = 0; i < nextStates.Length; i++)
                    foreach (ConfigurationBase next in nextStates)
                    {
                        //ConfigurationBase next = nextStates[i];
                        string ID = next.GetID();
                        if (path.Contains(ID))
                        {
                            return true;
                        }
                        else
                        {
                            if (!visited.ContainsKey(ID))
                            {
                                visited.Add(ID);
                                working.Push(next);
                                depthStack.Push(depth + 1);
                            }
                        }
                    }
                }
            }

            return false;
        }
예제 #12
0
        public void DFSVerification()
        {
            //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.

            Stack<EventBAPairSafety> TaskStack = new Stack<EventBAPairSafety>();

            EventBAPairSafety initialstep = EventBAPairSafety.GetInitialPairs(BA, InitialStep);
            TaskStack.Push(initialstep);

            //Dictionary<string, bool> Visited = new Dictionary<string, bool>();
            StringHashTable Visited = new StringHashTable(Ultility.Ultility.MC_INITIAL_SIZE);

            while (TaskStack.Count != 0)
            {
                if (CancelRequested)
                {
                    this.VerificationOutput.NoOfStates = Visited.Count;
                    return;
                }

                EventBAPairSafety now = TaskStack.Pop();
                string ID = now.GetCompressedState();

                //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);
                        this.VerificationOutput.CounterExampleTrace.RemoveAt(lastIndex);
                    }
                }

                this.VerificationOutput.CounterExampleTrace.Add(now.configuration);
                depthList.Add(depth);
                //The above are for identifying a counterexample trace.

                if (now.States.Count == 0)
                {
                    this.VerificationOutput.NoOfStates = Visited.Count;
                    this.VerificationOutput.VerificationResult = VerificationResultType.INVALID;
                    return;
                }

                if (!Visited.ContainsKey(ID))
                {
                    Visited.Add(ID);

                    ConfigurationBase[] steps = now.configuration.MakeOneMove().ToArray();
                    this.VerificationOutput.Transitions += steps.Length;
                    EventBAPairSafety[] products = now.Next(BA,steps);
                    foreach (EventBAPairSafety step in products)
                    {
                        TaskStack.Push(step);
                        depthStack.Push(depth + 1);
                    }
                }
            }

            this.VerificationOutput.CounterExampleTrace = null;
            this.VerificationOutput.NoOfStates = Visited.Count;
            this.VerificationOutput.VerificationResult = VerificationResultType.VALID;
        }
예제 #13
0
        protected override bool IsCounterExampleSpurious()
        {
            //here we perform a DFS using a stack working.
            Stack<ConfigurationBase> working = new Stack<ConfigurationBase>(1024);
            working.Push(InitialStep);

            //a stack to store corresponding depth of the elements in the working stack
            Stack<int> depthStack = new Stack<int>(1024);
            depthStack.Push(0);

            //a concrete counter example trace to store the current expended concrete counter example
            List<ConfigurationBase> ConcreteCounterExampleTrace = new List<ConfigurationBase>(64);
            List<List<string>> CounterExampleTraceEnabled = new List<List<string>>(64);

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

            //a hashtable to stored the visited states
            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);
                        CounterExampleTraceEnabled.RemoveAt(lastIndex);
                    }
                }

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

                //get the next steps of concrete state
                IEnumerable<ConfigurationBase> next = current.MakeOneMove();

                List<string> Enabled = new List<string>();
                switch (FairnessType)
                {
                    case FairnessType.EVENT_LEVEL_STRONG_FAIRNESS:
                    case FairnessType.EVENT_LEVEL_WEAK_FAIRNESS:
                        //for (int i = 0; i < next.Length; i++)
                        foreach (ConfigurationBase state in next)
                        {
                            Enabled.Add(state.Event);
                        }
                        break;
                    case FairnessType.PROCESS_LEVEL_STRONG_FAIRNESS:
                    case FairnessType.PROCESS_LEVEL_WEAK_FAIRNESS:
                        foreach (ConfigurationBase state in next)
                        {
                            foreach (string proc in state.ParticipatingProcesses)
                            {
                                if (!Enabled.Contains(proc))
                                {
                                    Enabled.Add(proc);
                                }
                            }
                        }
                        break;
                    case FairnessType.GLOBAL_FAIRNESS:
                        foreach (ConfigurationBase state in next)
                        {
                            Enabled.Add(state.GetIDWithEvent());
                        }
                        break;
                }
                CounterExampleTraceEnabled.Add(Enabled);

                //if the concreate counter example is completed.
                if (ConcreteCounterExampleTrace.Count == VerificationOutput.CounterExampleTrace.Count)
                {
                    foreach (var vm in next)
                    {
                        //check if the loop is established,
                        if (vm.GetIDWithEvent() == ConcreteCounterExampleTrace[VerificationOutput.LoopIndex].GetIDWithEvent())
                        {
                            if (!hasFairness)
                            {
                                VerificationOutput.CounterExampleTrace = ConcreteCounterExampleTrace;
                                return false;
                            }

                            //if there is fairness requirement, check whether the concrete counter example is fairness
                            if (CheckConcreteExampleFairness(ConcreteCounterExampleTrace, CounterExampleTraceEnabled))
                            {
                                VerificationOutput.CounterExampleTrace = ConcreteCounterExampleTrace;
                                return false;
                            }
                        }
                    }
                }
                else
                {
                    ConfigurationBase abstractStep = VerificationOutput.CounterExampleTrace[depth + 1];

                    //for (int j = 0; j < next.Length; j++)
                    foreach (ConfigurationBase state in next)
                    {
                        if (abstractStep.Event == state.Event && abstractStep.EqualsV(state))
                        {
                            string tmp = (depth + 1) + "-" + state.GetID();
                            if (!visited.ContainsKey(tmp))
                            {
                                working.Push(state);
                                depthStack.Push(depth + 1);
                                visited.Add(tmp);
                            }
                        }
                    }
                }

            } while (working.Count > 0);

            return true;
        }
예제 #14
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;
        }
예제 #15
0
        public void DFSVerification()
        {
            StringHashTable Visited = new StringHashTable(Common.Classes.Ultility.Ultility.MC_INITIAL_SIZE);
            Stack<ConfigurationBase> pendingImpl = new Stack<ConfigurationBase>(1000);
            VisitedNonDivStates = new HashSet<string>();

            //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
            ConfigurationBase currentImpl = InitialStep;
            pendingImpl.Push(currentImpl);

            Visited.Add(currentImpl.GetID());

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

                currentImpl = pendingImpl.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);
                        VerificationOutput.CounterExampleTrace.RemoveAt(lastIndex);
                    }
                }

                this.VerificationOutput.CounterExampleTrace.Add(currentImpl);
                depthList.Add(depth);

                //if (currentImpl.IsDivergent())
                if (!VisitedNonDivStates.Contains(currentImpl.GetID()) && IsDivergent(currentImpl))
                {
                    VerificationOutput.VerificationResult = VerificationResultType.INVALID;
                    VerificationOutput.NoOfStates = Visited.Count;
                    //VerificationOutput.CounterExampleTrace.RemoveAt(VerificationOutput.CounterExampleTrace.Count - 1);
                    LoopIndex = VerificationOutput.CounterExampleTrace.Count;
                    return;
                }

                ConfigurationBase[] list = currentImpl.MakeOneMove().ToArray();

                this.VerificationOutput.Transitions += list.Length;

                for (int i = list.Length - 1; i >= 0; i--)
                {
                    ConfigurationBase step = list[i];
                    string stepID = step.GetID();
                    if (!Visited.ContainsKey(stepID))
                    {
                        Visited.Add(stepID);
                        pendingImpl.Push(step);
                        depthStack.Push(depth + 1);
                    }
                }
            }

            VerificationOutput.CounterExampleTrace = null;
            VerificationOutput.VerificationResult = VerificationResultType.VALID;
            VerificationOutput.NoOfStates = Visited.Count;
        }
예제 #16
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();
                int size = list.Count();
                this.VerificationOutput.Transitions += size;

                //check if it is nondeterministic, it is nondeterministic if and only if there exists two different configuration with the same event.
                bool deterministic = true;
                Dictionary<string, string> mapping = new Dictionary<string, string>(size);
                foreach (ConfigurationBase configuration in list)
                {
                    string ID = configuration.GetID();
                    string mappedID;

                    if (mapping.TryGetValue(configuration.Event, out mappedID))
                    {
                        if (mappedID != ID)
                        {
                            deterministic = false;
                            Event = configuration.Event;
                            break;
                        }
                    }
                    else
                    {
                        mapping.Add(configuration.Event, ID);
                    }
                }

                if (!deterministic)
                {
                    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 (!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;
            return;
        }
예제 #17
0
        public static void TraceInclusionCheck(ConfigurationBase currentImpl, Automata spec, VerificationOutput VerificationOutput)
        {
            FAState[] states = spec.States.Values.ToArray();
            //bool[] isFinal = new bool[states.Length];
            bool[,] fsim = new bool[states.Length, states.Length];

            // sim[u][v]=true iff v in sim(u) iff v simulates u

            //for (int i = 0; i < states.Length; i++)
            //{
            //    isFinal[i] = spec.F.Contains(states[i]);
            //}

            for (int i = 0; i < states.Length; i++)
            {
                for (int j = i; j < states.Length; j++)
                {
                    fsim[i, j] = states[j].covers(states[i]); //(!isFinal[i] || isFinal[j]) &&
                    fsim[j, i] = states[i].covers(states[j]); //(isFinal[i] || !isFinal[j]) &&
                }
            }

            Dictionary <string, HashSet <FAState> > rel_spec = FastFSimRelNBW(spec, fsim);


            StringHashTable          Visited  = new StringHashTable(Ultility.Ultility.MC_INITIAL_SIZE);
            List <ConfigurationBase> toReturn = new List <ConfigurationBase>();

            Stack <ConfigurationBase> pendingImpl = new Stack <ConfigurationBase>(1024);
            Stack <NormalizedFAState> pendingSpec = new Stack <NormalizedFAState>(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(currentImpl);

            //specification initial state
            NormalizedFAState currentSpec = new NormalizedFAState(spec.InitialState, rel_spec);


#if TEST
            pendingSpec.Push(currentSpec.TauReachable());
#else
            pendingSpec.Push(currentSpec);
#endif

            while (pendingImpl.Count > 0)
            {
                currentImpl = pendingImpl.Pop();
                currentSpec = pendingSpec.Pop();

                string ID = currentImpl.GetID() + Constants.SEPARATOR + currentSpec.GetID();
                if (Visited.ContainsKey(ID))
                {
                    continue;
                }

                Visited.Add(ID);

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

                while (depth > 0 && 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.
                if (currentSpec.States.Count == 0)
                {
                    VerificationOutput.NoOfStates          = Visited.Count;
                    VerificationOutput.CounterExampleTrace = toReturn;
                    VerificationOutput.VerificationResult  = VerificationResultType.INVALID;
                    return;
                }

                ConfigurationBase[] nextImpl = currentImpl.MakeOneMove();
                VerificationOutput.Transitions += nextImpl.Length;

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

                    if (next.Event != Constants.TAU)
                    {
                        NormalizedFAState nextSpec = currentSpec.Next(next.Event, rel_spec);

                        pendingImpl.Push(next);
                        pendingSpec.Push(nextSpec);
                        depthStack.Push(depth + 1);
                    }
                    else
                    {
                        pendingImpl.Push(next);
                        pendingSpec.Push(currentSpec);
                        depthStack.Push(depth + 1);
                    }
                }
            }

            VerificationOutput.NoOfStates         = Visited.Count;
            VerificationOutput.VerificationResult = VerificationResultType.VALID;
            //return null;
        }
예제 #18
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)
                {
                    this.VerificationOutput.NoOfStates = Visited.Count;
                    return;
                }

                ConfigurationBase current = working.Dequeue();
                List<ConfigurationBase> currentPath = paths.Dequeue();
                //ConfigurationBase[] list = current.MakeOneMove().ToArray();
                //this.VerificationOutput.Transitions += list.Length;

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

                bool deterministic = true;
                Dictionary<string, string> mapping = new Dictionary<string, string>(size);
                foreach (ConfigurationBase configuration in list)
                {
                    string ID = configuration.GetID();

                    //if (mapping.ContainsKey(configuration.Event))
                    //{
                    //    if (mapping[configuration.Event] != ID)
                    //    {
                    string mappedID;
                    if (mapping.TryGetValue(configuration.Event, out mappedID))
                    {
                        if (mappedID != ID)
                        {
                            deterministic = false;
                            Event = configuration.Event;
                            break;
                        }
                    }
                    else
                    {
                        mapping.Add(configuration.Event, ID);
                    }
                }

                if (!deterministic)
                {
                    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 (!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);

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

            this.VerificationOutput.NoOfStates = Visited.Count;
            return;
        }
예제 #19
0
        /// <summary>
        /// This method verifies an LTL whose negation is safety through refinement checking.
        /// </summary>
        /// <returns></returns>
        public virtual void RunVerificationNegate()
        {
            //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.

            Stack<EventBAPairSafety> TaskStackNegate = new Stack<EventBAPairSafety>();

            EventBAPairSafety initialstep = EventBAPairSafety.GetInitialPairs(BA, InitialStep);
            TaskStackNegate.Push(initialstep);

            StringHashTable visited = new StringHashTable(Ultility.Ultility.MC_INITIAL_SIZE);

            List<string> Path = new List<string>();
            while (TaskStackNegate.Count != 0)
            {
                if (CancelRequested)
                {
                    VerificationOutput.NoOfStates = visited.Count;
                    return;
                }

                EventBAPairSafety now = TaskStackNegate.Pop();
                string ID = now.GetCompressedState();

                //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);
                        VerificationOutput.CounterExampleTrace.RemoveAt(lastIndex);
                        Path.RemoveAt(lastIndex);
                    }
                }

                VerificationOutput.CounterExampleTrace.Add(now.configuration);
                depthList.Add(depth);
                Path.Add(ID);
                //The above are for identifying a counterexample trace.

                if (now.States.Count != 0)
                {
                    if (!visited.ContainsKey(ID))
                    {
                        visited.Add(ID);

                        ConfigurationBase[] steps = now.configuration.MakeOneMove().ToArray();

                        //the special case of deadlock
                        //if (steps.Length == 0)
                        if(now.configuration.IsDeadLock)
                        {
                            VerificationOutput.NoOfStates = visited.Count;
                            VerificationOutput.VerificationResult = VerificationResultType.INVALID;
                            return;
                        }

                        VerificationOutput.Transitions += steps.Length;

                        EventBAPairSafety[] products = now.Next(BA, steps);
                        foreach (EventBAPairSafety step in products)
                        {
                            string newID = step.GetCompressedState();
                            if (Path.Contains(newID))
                            {
                                VerificationOutput.NoOfStates = visited.Count;
                                VerificationOutput.VerificationResult = VerificationResultType.INVALID;
                                VerificationOutput.LoopIndex = Path.IndexOf(newID);
                                return;
                            }

                            TaskStackNegate.Push(step);
                            depthStack.Push(depth + 1);
                        }
                    }
                }
            }

            VerificationOutput.CounterExampleTrace = null;
            VerificationOutput.NoOfStates = visited.Count;
            VerificationOutput.VerificationResult = VerificationResultType.VALID;
        }
예제 #20
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;
        }
예제 #21
0
        public void DFSVerification()
        {
            StringHashTable Visited = new StringHashTable(Ultility.Ultility.MC_INITIAL_SIZE);
            Expression conditionExpression = this.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);

            ExtremValue = null;
            ReachableCount = 0;

            List<ConfigurationBase> CounterExampleTraceLocal = new List<ConfigurationBase>();
            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);
                        CounterExampleTraceLocal.RemoveAt(lastIndex);
                    }
                }

                CounterExampleTraceLocal.Add(current);

                if (current.ImplyCondition(conditionExpression))
                {
                    ReachableCount++;
                    Expression v = current.EvaluateExpression(ConstraintCondition);
                    if(v is IntConstant)
                    {
                        int value = (v as IntConstant).Value;
                        if(ExtremValue == null)
                        {
                            ExtremValue = value;
                            VerificationOutput.CounterExampleTrace = new List<ConfigurationBase>(CounterExampleTraceLocal);
                        }
                        else
                        {
                            switch (Contraint)
                            {
                                case QueryConstraintType.MAX:
                                    if(value > ExtremValue.Value)
                                    {
                                        ExtremValue = value;
                                        VerificationOutput.CounterExampleTrace = new List<ConfigurationBase>(CounterExampleTraceLocal);
                                    }
                                    break;
                                case QueryConstraintType.MIN:
                                    if(value < ExtremValue.Value)
                                    {
                                        ExtremValue = value;
                                        VerificationOutput.CounterExampleTrace = new List<ConfigurationBase>(CounterExampleTraceLocal);
                                    }
                                    break;
                            }
                        }
                    }
                }

                depthList.Add(depth);
                ConfigurationBase[] list = current.MakeOneMove().ToArray();
                VerificationOutput.Transitions += list.Length;

                for (int i = list.Length - 1; i >= 0; i--)
                {
                    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);

            if (ExtremValue == null)
            {
                VerificationOutput.VerificationResult = VerificationResultType.INVALID;
                VerificationOutput.CounterExampleTrace = null;
            }
            else
            {
                VerificationOutput.VerificationResult = VerificationResultType.VALID;
            }

            VerificationOutput.NoOfStates = Visited.Count;
            return;
        }