/// <summary> /// To get all states which can be reached via tau-transitions only. /// </summary> /// <returns></returns> public static NormalizedState TauReachable(List <ConfigurationBase> states) { int size = states.Count * EXPENDING_FACTOR; Stack <ConfigurationBase> working = new Stack <ConfigurationBase>(size); StringHashTable visited = new StringHashTable(size); foreach (ConfigurationBase vm in states) { working.Push(vm); visited.Add(vm.GetID()); } while (working.Count > 0) { ConfigurationBase current = working.Pop(); IEnumerable <ConfigurationBase> vms = current.MakeOneMove(Constants.TAU); //for (int i = 0; i < vms.Length; i++) foreach (ConfigurationBase configuration in vms) { //ConfigurationBase configuration = vms[i]; string tmp = configuration.GetID(); if (!visited.ContainsKey(tmp)) { states.Add(configuration); visited.Add(tmp); working.Push(configuration); } } } return(new NormalizedState(states)); }
/// <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); }
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; }
public void Add( StringHashTable dictionary ) { foreach( Entry entry in m_list ) { if( !dictionary.ContainsKey( entry.key )) { dictionary.Add( entry.key, entry.translation ); } } }
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; }
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 { if (JobFinished) { return(null); } 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); }
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; }
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; }
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; }
public void TraceInclusionCheckBFS(DeterministicAutomata spec) { StringHashTable Visited = new StringHashTable(Ultility.Ultility.MC_INITIAL_SIZE); Queue <ConfigurationBase> pendingImpl = new Queue <ConfigurationBase>(1024); Queue <DeterministicFAState> pendingSpec = new Queue <DeterministicFAState>(1024); Queue <List <ConfigurationBase> > paths = new Queue <List <ConfigurationBase> >(1024); //The following are for identifying a counterexample trace. Stack <int> depthStack = new Stack <int>(1024); depthStack.Push(0); //The above are for identifying a counterexample trace. //implementation initial state pendingImpl.Enqueue(InitialStep); pendingSpec.Enqueue(spec.InitialState); string statestring = spec.InitialState.GetID() + Constants.SEPARATOR + InitialStep.GetID(); Visited.Add(statestring); List <ConfigurationBase> path = new List <ConfigurationBase>(); path.Add(InitialStep); paths.Enqueue(path); while (pendingImpl.Count > 0) { if (CancelRequested) { VerificationOutput.NoOfStates = Visited.Count; return; } ConfigurationBase currentImpl = pendingImpl.Dequeue(); DeterministicFAState currentSpec = pendingSpec.Dequeue(); List <ConfigurationBase> currentPath = paths.Dequeue(); IEnumerable <ConfigurationBase> nextImpl = currentImpl.MakeOneMove(); VerificationOutput.Transitions += nextImpl.Count();//.Length; //for (int k = 0; k < nextImpl.Length; k++) foreach (ConfigurationBase next in nextImpl) { //ConfigurationBase next = nextImpl[k]; DeterministicFAState nextSpec = currentSpec; if (next.Event != Constants.TAU) { nextSpec = currentSpec.Next(next.Event); if (nextSpec == null) { currentPath.Add(next); VerificationOutput.NoOfStates = Visited.Count; VerificationOutput.CounterExampleTrace = currentPath; VerificationOutput.VerificationResult = VerificationResultType.INVALID; return; } } statestring = nextSpec.GetID() + Constants.SEPARATOR + next.GetID(); if (!Visited.ContainsKey(statestring)) { Visited.Add(statestring); pendingImpl.Enqueue(next); pendingSpec.Enqueue(nextSpec); List <ConfigurationBase> newPath = new List <ConfigurationBase>(currentPath); newPath.Add(next); paths.Enqueue(newPath); } } } VerificationOutput.VerificationResult = VerificationResultType.VALID; VerificationOutput.NoOfStates = Visited.Count; }
public void DFSVerification() { StringHashTable Visited = new StringHashTable(1048576); Stack <ConfigurationBase> working = new Stack <ConfigurationBase>(1024); HashSet <string> componentInvokeList = new HashSet <string>(); 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.Add(current); IEnumerable <ConfigurationBase> list = current.MakeOneMove(); this.VerificationOutput.Transitions += list.Count(); Console.WriteLine("tracing event: " + current.Event + " " + current.GetID() + "||"); Console.WriteLine(toStringCounterExample(this.VerificationOutput.CounterExampleTrace)); ///////////////////////////////////////////////////////// Code specific for this smell detection if (current.Event.IndexOf("!") == -1 && current.Event.IndexOf("?") == -1 && current.Event.IndexOf("_") != -1) { // not channel event, it is component event Console.WriteLine("comp event: " + current.Event); String currentComponent = current.Event.Substring(0, current.Event.IndexOf("_")); if (!componentInvokeList.Contains(currentComponent)) { componentInvokeList.Add(currentComponent); } } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 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); // check lava flow. List <string> compList = new List <string>(this.ComponentDatabase.Keys); noInvokeCompList = compList.Except(componentInvokeList).ToList <string>(); if (noInvokeCompList.Count > 0) { // found lava flow components Console.WriteLine(" lava flow component ********* " + noInvokeCompList.Count); this.VerificationOutput.VerificationResult = VerificationResultType.INVALID; this.VerificationOutput.NoOfStates = Visited.Count; return; } this.VerificationOutput.CounterExampleTrace = null; if (MustAbstract) { this.VerificationOutput.VerificationResult = VerificationResultType.UNKNOWN; } else { this.VerificationOutput.VerificationResult = VerificationResultType.VALID; } this.VerificationOutput.NoOfStates = Visited.Count; }
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; }
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); } } 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"); if (current.Event.IndexOf("!") == -1 && current.Event.IndexOf("?") == -1 && current.Event.IndexOf("_") != -1 && current.Event.IndexOf("consumer_request") == -1) { // not channel event, it is component event Console.WriteLine("comp event: " + current.Event); String currentComponent = current.Event.Substring(0, current.Event.IndexOf("_")); if (IsSingleInterface(currentComponent)) { if (singleInterfaceInvokeSequence.Count() == 0 || singleInterfaceInvokeSequence.Last() != currentComponent) { singleInterfaceInvokeSequence.Add(currentComponent); printComponentList(singleInterfaceInvokeSequence); if (singleInterfaceInvokeSequence.Count() > MAX_SEQUENCE_SINGLE_INTERFACE_INVOKE) { // functional decomposition found Console.WriteLine(" Functional decomposition ********* "); this.VerificationOutput.VerificationResult = VerificationResultType.INVALID; this.VerificationOutput.NoOfStates = Visited.Count; return; } } } else { singleInterfaceInvokeSequence.Clear(); } } 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; }
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); }
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); }
/// <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; }
public void TraceInclusionCheckDFS(DeterministicAutomata spec) { StringHashTable Visited = new StringHashTable(Ultility.Ultility.MC_INITIAL_SIZE); List <ConfigurationBase> toReturn = new List <ConfigurationBase>(); Stack <ConfigurationBase> pendingImpl = new Stack <ConfigurationBase>(1024); Stack <DeterministicFAState> pendingSpec = new Stack <DeterministicFAState>(1024); //The following are for identifying a counterexample trace. Stack <int> depthStack = new Stack <int>(1024); depthStack.Push(0); List <int> depthList = new List <int>(1024); //The above are for identifying a counterexample trace. //implementation initial state pendingImpl.Push(InitialStep); //specification initial state pendingSpec.Push(spec.InitialState); Visited.Add(InitialStep.GetID() + Constants.SEPARATOR + spec.InitialState.GetID()); while (pendingImpl.Count > 0) { if (CancelRequested) { VerificationOutput.NoOfStates = Visited.Count; // VisitedWithID.Count; return; } ConfigurationBase currentImpl = pendingImpl.Pop(); DeterministicFAState currentSpec = pendingSpec.Pop(); //The following are for identifying a counterexample trace. int depth = depthStack.Pop(); if (depth > 0) { while (depthList[depthList.Count - 1] >= depth) { int lastIndex = depthList.Count - 1; depthList.RemoveAt(lastIndex); toReturn.RemoveAt(lastIndex); } } toReturn.Add(currentImpl); depthList.Add(depth); //If the specification has no corresponding state, then it implies that the trace is allowed by the //implementation but not the specification -- which means trace-refinement is failed. IEnumerable <ConfigurationBase> nextImpl = currentImpl.MakeOneMove(); VerificationOutput.Transitions += nextImpl.Count(); //for (int k = 0; k < nextImpl.Length; k++) foreach (ConfigurationBase next in nextImpl) { //ConfigurationBase next = nextImpl[k]; DeterministicFAState nextSpec = currentSpec; if (next.Event != Constants.TAU) { nextSpec = currentSpec.Next(next.Event); if (nextSpec == null) { toReturn.Add(next); VerificationOutput.NoOfStates = Visited.Count; VerificationOutput.CounterExampleTrace = toReturn; VerificationOutput.VerificationResult = VerificationResultType.INVALID; return; } } string ID = next.GetID() + Constants.SEPARATOR + nextSpec.GetID(); if (!Visited.ContainsKey(ID)) { pendingImpl.Push(next); pendingSpec.Push(nextSpec); depthStack.Push(depth + 1); Visited.Add(ID); } } } VerificationOutput.NoOfStates = Visited.Count; VerificationOutput.VerificationResult = VerificationResultType.VALID; }
public void DFSVerification() { StringHashTable Visited = new StringHashTable(1048576); Stack <ConfigurationBase> working = new Stack <ConfigurationBase>(1024); Dictionary <string, List <string> > componentInvokeByDict = new Dictionary <string, List <string> >(); Visited.Add(InitialStep.GetID()); working.Push(InitialStep); Stack <int> depthStack = new Stack <int>(1024); depthStack.Push(0); List <int> depthList = new List <int>(1024); string previousComponent = ""; // initialize invokeCount dictionary for counting how many time the component is called Dictionary <string, int> invokeCount = new Dictionary <string, int>(); foreach (string comp in ComponentDatabase.Keys) { invokeCount.Add(comp, 0); } 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.WriteLine("tracing event: " + current.Event + " " + current.GetID() + "||"); Console.WriteLine(toStringCounterExample(this.VerificationOutput.CounterExampleTrace)); ///////////////////////////////////////////////////////// Code specific for this smell detection if (current.Event.IndexOf("!") == -1 && current.Event.IndexOf("?") == -1 && current.Event.IndexOf("_") != -1 && current.Event.IndexOf("consumer_request") == -1) { // not channel event, it is component event Console.WriteLine("comp event: " + current.Event); String currentComponent = current.Event.Substring(0, current.Event.IndexOf("_")); // check if the previous calling component and current component are not the same, also calling component has single interface if (currentComponent != previousComponent && previousComponent != "") //&& this.IsSingleInterface(previousComponent)) { // add to dict for for component invoked if (!componentInvokeByDict.ContainsKey(currentComponent)) { List <string> componentInvokeList = new List <string>(); componentInvokeList.Add(previousComponent); invokeCount[previousComponent] = invokeCount[previousComponent] + 1; componentInvokeByDict.Add(currentComponent, componentInvokeList); } else { componentInvokeByDict.TryGetValue(currentComponent, out List <string> componentInvokeList); if (!componentInvokeList.Contains(previousComponent)) { componentInvokeList.Add(previousComponent); invokeCount[previousComponent] = invokeCount[previousComponent] + 1; componentInvokeByDict[currentComponent] = componentInvokeList; } } // perform polstergeist checking // Console.WriteLine(" ##### " + invokeCount[previousComponent] +" == "+ (ComponentDatabase.Count - 1)); /* if(invokeCount[previousComponent] >= ComponentDatabase.Count - 1) * { * Console.WriteLine(" Poltergeist Found ********* "); * poltergeist = previousComponent; * this.VerificationOutput.VerificationResult = VerificationResultType.INVALID; * this.VerificationOutput.NoOfStates = Visited.Count; * PrintComponentInvokeDict(componentInvokeByDict, invokeCount); * return; * } */ if (componentInvokeByDict[currentComponent].Count >= ComponentDatabase.Count - 1) { // poltergeist found when a component is called by all other components Console.WriteLine(" Poltergeist Found ********* "); poltergeist = currentComponent; this.VerificationOutput.VerificationResult = VerificationResultType.INVALID; this.VerificationOutput.NoOfStates = Visited.Count; PrintComponentInvokeDict(componentInvokeByDict, invokeCount); return; } } previousComponent = currentComponent; } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// PrintComponentInvokeDict(componentInvokeByDict, invokeCount); // check final result foreach (var comp in ComponentDatabase) { String compName = comp.Key; int total = 0; foreach (var compInvoke in componentInvokeByDict) { if (compInvoke.Value.Contains(compName)) { total++; } } Console.Write(" ### checking compname: " + compName + " " + total); if (total >= ComponentDatabase.Count - 1) { // poltergeist found when a component is called by all other components Console.WriteLine(" Poltergeist Found ********* "); poltergeist = compName; this.VerificationOutput.VerificationResult = VerificationResultType.INVALID; this.VerificationOutput.NoOfStates = Visited.Count; PrintComponentInvokeDict(componentInvokeByDict, invokeCount); 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 (!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; }
public static int Main() { Console.WriteLine("Lab №4, Ozierski Vital, group 052004"); IntHashTable ih = new IntHashTable(50); StringHashTable sh = new StringHashTable(16); string cmd, command, mode; bool found; while (true) { Console.WriteLine(); Console.WriteLine("Commands: add, find, print"); Console.WriteLine("Format: <command> <int|string> or exit"); Console.Write("? "); cmd = Console.ReadLine(); if (cmd == "exit") break; if (cmd.Split(' ').Length != 2) Console.WriteLine("Incorrect command format"); else { command = cmd.Split(' ')[0]; mode = cmd.Split(' ')[1]; if (mode != "string" && mode != "int") Console.WriteLine("Incorrect mode"); else { if (command == "add") { Console.Write("Value: "); cmd = Console.ReadLine(); if (mode == "string") sh.Add(cmd); else if (mode == "int") ih.Add(Int32.Parse(cmd)); } else if (command == "find") { Console.Write("Value: "); cmd = Console.ReadLine(); found = false; if (mode == "string") found = sh.Find(cmd); else if (mode == "int") found = ih.Find(Int32.Parse(cmd)); Console.WriteLine(found ? "Found" : "No found"); } else if (command == "print") { if (mode == "string") sh.Print(); else if (mode == "int") ih.Print(); } else Console.WriteLine("Incorrect Command"); } Console.WriteLine(); } } return 0; }
public void MonoDFSVerification() { 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); 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>(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; } } } 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) { 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); if (ExtremValue == null) { VerificationOutput.VerificationResult = VerificationResultType.INVALID; VerificationOutput.CounterExampleTrace = null; } else { VerificationOutput.VerificationResult = VerificationResultType.VALID; } VerificationOutput.NoOfStates = Visited.Count; return; }
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; }
private 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); ExtremValue = null; ReachableCount = 0; do { if (CancelRequested) { VerificationOutput.NoOfStates = Visited.Count; return; } ConfigurationBase current = working.Dequeue(); List <ConfigurationBase> currentPath = paths.Dequeue(); 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>(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; } } } } 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; }
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; }
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; }
/// <summary> /// Verify the LTL property using DFS algorithm /// </summary> public void DFSVerification() { #region Variables to compute Probability List <string> counterExamples = new List <string>(); // list of all possible counter examples List <double> probOnPaths = new List <double>(); // list of congestion probability corresponding to each path Dictionary <string, double> sensorsCongestionProbability = new Dictionary <string, double>(); // final congestion probability on each sensor #endregion #region Identifying a counter-example trace Stack <int> depthStack = new Stack <int>(1024); // Depth of the stack (on the fly, changed on each execution on the RG) depthStack.Push(0); List <int> depthList = new List <int>(1024); // Depth of the list (stable, indicate the real depth of the RG) #endregion List <ConfigurationBase> counterExampleTrace = new List <ConfigurationBase>(); Stack <EventBAPairSafety> TaskStack = new Stack <EventBAPairSafety>(); // stack of events (Channel1_2, Send1, Congestion3, etc.) Stack <double> probTaskStack = new Stack <double>(); // probability on the fly (constanly be pushed and popped) #region Initialization EventBAPairSafety initialstep = EventBAPairSafety.GetInitialPairs(BA, InitialStep); TaskStack.Push(initialstep); probTaskStack.Push(1d); StringHashTable Visited = new StringHashTable(Ultility.Ultility.MC_INITIAL_SIZE); #endregion while (TaskStack.Count != 0 && Visited.Count <= 500000) { // If the verification of RG is cancelled for some reason if (CancelRequested) { this.VerificationOutput.NoOfStates = Visited.Count; return; } EventBAPairSafety now = TaskStack.Pop(); double probNow = probTaskStack.Pop(); string ID = now.GetCompressedState(); #region Identifying a counter-example trace int depth = depthStack.Pop(); if (depth > 0) { while (depthList[depthList.Count - 1] >= depth) // step back from the counter-example trace { int lastIndex = depthList.Count - 1; depthList.RemoveAt(lastIndex); counterExampleTrace.RemoveAt(lastIndex); } } //this.VerificationOutput.CounterExampleTrace.Add(now.configuration); counterExampleTrace.Add(now.configuration); depthList.Add(depth); #endregion #region Congestion is detected if (now.States.Count == 0) { this.VerificationOutput.NoOfStates = Visited.Count; this.VerificationOutput.VerificationResult = VerificationResultType.INVALID; // Update the congesition probability on each Sensor string IDSensor = GetIDOfCongestion(now); if (sensorsCongestionProbability.ContainsKey(IDSensor)) { sensorsCongestionProbability[IDSensor] += probNow; } else { sensorsCongestionProbability.Add(IDSensor, probNow); } // Add probability of choosing path leading to congestion, displayed on VerificationOuput probOnPaths.Add(probNow); StringBuilder sb = new StringBuilder(); foreach (ConfigurationBase cb in counterExampleTrace) { sb.Append(cb.Event); sb.Append(" -> "); } counterExamples.Add(sb.ToString()); continue; // if found CongestionX, continue expanding the RG } #endregion #region Main execution on RG //if (!Visited.ContainsKey(ID)) //{ double probOnTheFly; Visited.Add(ID); ConfigurationBase[] steps = now.configuration.MakeOneMove().ToArray(); this.VerificationOutput.Transitions += steps.Length; EventBAPairSafety[] products = now.Next(BA, steps); #region Retrieve probability on non-congestion path if (products.Length == 0) // there is no more state to discover --> return back --> write down the path { probOnPaths.Add(probNow); StringBuilder sb = new StringBuilder(); foreach (ConfigurationBase cb in counterExampleTrace) { sb.Append(cb.Event); sb.Append(" -> "); } counterExamples.Add(sb.ToString()); } #endregion foreach (EventBAPairSafety step in products) { probOnTheFly = probNow * GetProbabilityFromChannel(step); TaskStack.Push(step); // calculate probability on the current state probTaskStack.Push(probOnTheFly); depthStack.Push(depth + 1); } //} #endregion } #region Treat the final Output (if the verification is VALID or INVALID) if (this.VerificationOutput.VerificationResult != VerificationResultType.INVALID) { this.VerificationOutput.CounterExampleTrace = null; this.VerificationOutput.NoOfStates = Visited.Count; this.VerificationOutput.VerificationResult = VerificationResultType.VALID; } else { this.VerificationOutput.CounterExampleTraces = counterExamples; this.VerificationOutput.ProbOnPaths = probOnPaths; return; } #endregion }
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; }
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; }
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; }
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; }
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; }
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; }
public void DFSVerification() { StringHashTable Visited = new StringHashTable(1048576); Stack <ConfigurationBase> working = new Stack <ConfigurationBase>(1024); Dictionary <string, List <string> > componentInvokeByDict = new Dictionary <string, List <string> >(); HashSet <string> singleInterfaceComponentInvoked = new HashSet <string>(); Visited.Add(InitialStep.GetID()); working.Push(InitialStep); Stack <int> depthStack = new Stack <int>(1024); depthStack.Push(0); List <int> depthList = new List <int>(1024); string previousComponent = ""; int dataSignature = 0; bool isOnRequest = false; 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); // removing the invoked component from hashset when the counterexample is stepped back. if (this.VerificationOutput.CounterExampleTrace[lastIndex].Event.IndexOf("!") == -1 && this.VerificationOutput.CounterExampleTrace[lastIndex].Event.IndexOf("?") == -1) { string compName = this.VerificationOutput.CounterExampleTrace[lastIndex].Event.Substring(0, this.VerificationOutput.CounterExampleTrace[lastIndex].Event.IndexOf("_")); if (singleInterfaceComponentInvoked.Contains(compName)) { Console.WriteLine(" ...removing " + compName); singleInterfaceComponentInvoked.Remove(compName); } } this.VerificationOutput.CounterExampleTrace.RemoveAt(lastIndex); // visitedStates.RemoveAt(lastIndex); } } this.VerificationOutput.CounterExampleTrace.Add(current); IEnumerable <ConfigurationBase> list = current.MakeOneMove(); this.VerificationOutput.Transitions += list.Count(); Console.WriteLine("tracing event: " + current.Event + " " + current.GetID() + "||"); Console.WriteLine(toStringCounterExample(this.VerificationOutput.CounterExampleTrace)); ///////////////////////////////////////////////////////// Code specific for this smell detection if (current.Event.IndexOf("!") == -1 && current.Event.IndexOf("?") == -1 && current.Event.IndexOf("_") != -1 && current.Event.IndexOf("consumer_request") == -1) { // not channel event, it is component event Console.WriteLine("comp event: " + current.Event); String currentComponent = null; try { currentComponent = current.Event.Substring(0, current.Event.IndexOf("_")); // check if the previous calling component and current component are not the same, also calling component has single interface Console.WriteLine("currentComponent: " + currentComponent + " previousComponent: " + previousComponent); if (currentComponent != previousComponent && previousComponent != "" && IsSingleInterface(previousComponent)) { // START add to dict for debuging if (!componentInvokeByDict.ContainsKey(currentComponent)) { List <string> componentInvokeList = new List <string>(); componentInvokeList.Add(previousComponent); componentInvokeByDict.Add(currentComponent, componentInvokeList); } else { componentInvokeByDict.TryGetValue(currentComponent, out List <string> componentInvokeList); if (!componentInvokeList.Contains(previousComponent)) { componentInvokeList.Add(previousComponent); componentInvokeByDict[currentComponent] = componentInvokeList; } } // END add to dict for debuging // actual checking for ambiguous interface if (singleInterfaceComponentInvoked.Contains(previousComponent) && isOnRequest) { // found ambiguous Console.WriteLine(" Ambiguous Interface ********* " + previousComponent + " " + currentComponent); this.VerificationOutput.VerificationResult = VerificationResultType.INVALID; this.VerificationOutput.NoOfStates = Visited.Count; ambiguousInterface = previousComponent; PrintComponentInvokeDict(componentInvokeByDict); return; } else if (isOnRequest) { singleInterfaceComponentInvoked.Add(previousComponent); } } } catch (Exception e) { Console.WriteLine(e.ToString()); } Console.Write(" compInvoked->"); PrintList(singleInterfaceComponentInvoked); previousComponent = currentComponent; } // if it is channel input, capture data signature sending through port if (current.Event.IndexOf("req") != -1) { isOnRequest = true; // dataSignature = Convert.ToInt32( current.Event.Substring(current.Event.IndexOf("?") + 1)); } else if (current.Event.IndexOf("res") != -1) { isOnRequest = false; } foreach (string str in singleInterfaceComponentInvoked) { Console.WriteLine(" scompinv " + str); } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // PrintComponentInvokeDict(componentInvokeByDict); 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); /* * // check ambiguous interface which are the components that is invoked by only the same component. * Dictionary<string, int> ambiguousInterfaceList = new Dictionary<string, int>(); * foreach (string comp in componentInvokeByDict.Keys) * { * componentInvokeByDict.TryGetValue(comp, out List<String> compSource); * if(compSource.Count == 1) * { * if (!ambiguousInterfaceList.ContainsKey(compSource[0])) * { * ambiguousInterfaceList. * } * * } * } */ this.VerificationOutput.CounterExampleTrace = null; if (MustAbstract) { this.VerificationOutput.VerificationResult = VerificationResultType.UNKNOWN; } else { this.VerificationOutput.VerificationResult = VerificationResultType.VALID; } this.VerificationOutput.NoOfStates = Visited.Count; }