public TarjanThread(ConfigurationBase initialStep, BuchiAutomata ba, PATThreadPool threadPool, FairnessType FairnessType) { this.initialStep = initialStep; this.VerificationResult = VerificationResultType.UNKNOWN; this.BA = ba; this.ThreadPool = threadPool; this.FairnessType = FairnessType; this.FairSCC = null; this.JobFinished = false; }
public void onResult(VerificationResultType type) { if (type == VerificationResultType.UNKNOWN) { ListView_Assertions.SelectedItems[VerificationIndex].ImageIndex = UNKNOWN_ICON; } else if (type == VerificationResultType.VALID) { ListView_Assertions.SelectedItems[VerificationIndex].ImageIndex = CORRECT_ICON; } else if (type == VerificationResultType.WITHPROBABILITY) { ListView_Assertions.SelectedItems[VerificationIndex].ImageIndex = CORRECT_ICON_PRPB; } else { ListView_Assertions.SelectedItems[VerificationIndex].ImageIndex = WRONG_ICON; } }
//private Dictionary<string, double> congestionProbs = new Dictionary<string,double>(); #endregion //public void addCongestionProbs(string congestionString, double probPathCongestion) //{ // congestionProbs.Add(congestionString, probPathCongestion); //} public VerificationOutput(string engine) { VerificationResult = VerificationResultType.UNKNOWN; CounterExampleTrace = new List <ConfigurationBase>(64); Transitions = 0; NoOfStates = 0; LoopIndex = -1; ReducedMDPTransitions = 0; ReducedMDPStates = 0; Timer = new Stopwatch(); switch (engine) { case Constants.ENGINE_BDD_SEARCH: case Constants.ENGINE_BACKWARD_SEARCH_BDD: case Constants.ENGINE_FORWARD_BACKWARD_SEARCH_BDD: case Constants.ENGINE_FORWARD_SEARCH_BDD: VerificationOutputType = VerificationOutputType.LTS_BDD; break; case Constants.ENGINE_MDP_SEARCH: case Constants.ENGINE_SMT_MDP: case Constants.ENGINE_SMT_DTMC: VerificationOutputType = VerificationOutputType.MDP_EXPLICIT; break; case Constants.ENGINE_SCC_BASED_SEARCH_MULTICORE: VerificationOutputType = VerificationOutputType.LTS_EXPLICIT_MULTI_CORE; break; default: VerificationOutputType = VerificationOutputType.LTS_EXPLICIT; break; } }
public void TarjanModelChecking() { OutgoingTransitionTable = new Dictionary <string, List <string> >(Ultility.Ultility.MC_INITIAL_SIZE); TaskStack = new Stack <LocalPair>(Ultility.Ultility.MC_INITIAL_SIZE); DFSData = new StringDictionary <int[]>(Ultility.Ultility.MC_INITIAL_SIZE); List <LocalPair> initials = LocalPair.GetInitialPairsLocal(BA, initialStep); if (initials.Count == 0 || !BA.HasAcceptState) { VerificationResult = VerificationResultType.VALID; return; } for (int z = 0; z < initials.Count; z++) { LocalPair initState = initials[z]; TaskStack.Push(initState); string ID = initState.GetCompressedState(); DFSData.Add(ID, new int[] { VISITED_NOPREORDER, 0 }); OutgoingTransitionTable.Add(ID, new List <string>(8)); } Dictionary <string, LocalPair> SCCPairs = new Dictionary <string, LocalPair>(1024); Stack <LocalPair> stepStack = new Stack <LocalPair>(1024); //# Preorder counter int i = 0; //store the expended event step of a node to avoid multiple invocation of the make one move. Dictionary <string, List <LocalPair> > ExpendedNode = new Dictionary <string, List <LocalPair> >(1024); //PrintMessage("Start to find the Strongly Connected Component of graph."); do { if (SearchedDepth < TaskStack.Count) { SearchedDepth = TaskStack.Count; } if (JobFinished) { return; } LocalPair pair = TaskStack.Peek(); ConfigurationBase evt = pair.configuration; string BAState = pair.state; string v = pair.GetCompressedState(); List <string> outgoing = OutgoingTransitionTable[v]; int[] nodeData = DFSData.GetContainsKey(v); if (nodeData[0] == VISITED_NOPREORDER) { nodeData[0] = i; i++; } bool done = true; if (ExpendedNode.ContainsKey(v)) { List <LocalPair> list = ExpendedNode[v]; if (list.Count > 0) { //transverse all steps for (int k = list.Count - 1; k >= 0; k--) { LocalPair step = list[k]; string tmp = step.GetCompressedState(); //if the step is a unvisited step if (DFSData.GetContainsKey(tmp)[0] == VISITED_NOPREORDER) { //only add the first unvisited step //for the second or more unvisited steps, ignore at the monent if (done) { TaskStack.Push(step); done = false; list.RemoveAt(k); } } else { list.RemoveAt(k); } } } } else { //ConfigurationBase[] list = evt.MakeOneMove().ToArray(); IEnumerable <ConfigurationBase> list = evt.MakeOneMove(); pair.SetEnabled(list, FairnessType); List <LocalPair> product = LocalPair.NextLocal(BA, list, BAState); //count the transitions visited Transitions += product.Count; for (int k = product.Count - 1; k >= 0; k--) { LocalPair step = product[k]; string tmp = step.GetCompressedState(); //if (VisitedWithID.ContainsKey(tmp)) int[] data = DFSData.GetContainsKey(tmp); if (data != null) { //update the incoming and outgoing edges //int t = VisitedWithID.GetContainsKey(tmp); //DataStore.DataManager.GetID(tmp); outgoing.Add(tmp); //if this node is still not visited if (data[0] == VISITED_NOPREORDER) { //step.ID = t; //only put the first one to the work list stack. //if there are more than one node to be visited, //simply ignore them and keep its event step in the list. if (done) { TaskStack.Push(step); done = false; product.RemoveAt(k); } else { product[k] = step; } } //this node is truly visited. can be removed else { product.RemoveAt(k); } } else { //int stateID = VisitedWithID.Count; //VisitedWithID.Add(tmp,false); DFSData.Add(tmp, new int[] { VISITED_NOPREORDER, 0 }); OutgoingTransitionTable.Add(tmp, new List <string>(8)); //step.ID = stateID; outgoing.Add(tmp); //only put the first one into the stack. if (done) { TaskStack.Push(step); done = false; product.RemoveAt(k); } else { product[k] = step; } } } //create the remaining steps as the expending list for v ExpendedNode.Add(v, product); } if (done) { int lowlinkV = nodeData[0]; int preorderV = lowlinkV; bool selfLoop = false; // Calculate the low link of an explored state for (int j = 0; j < outgoing.Count; j++) { string w = outgoing[j]; if (w == v) { selfLoop = true; } int[] wdata = DFSData.GetContainsKey(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; TaskStack.Pop(); // Check whether the current state is the root of the SCC if (lowlinkV == preorderV) { SCCPairs.Add(v, pair); nodeData[0] = SCC_FOUND; bool BuchiFair = pair.state.EndsWith(Constants.ACCEPT_STATE); //for buchi-fair // Get the elements of the SCC from the step stack while (stepStack.Count > 0 && DFSData.GetContainsKey(stepStack.Peek().GetCompressedState())[0] > preorderV) { LocalPair s = stepStack.Pop(); string k = s.GetCompressedState(); SCCPairs.Add(k, s); DFSData.GetContainsKey(k)[0] = SCC_FOUND; if (!BuchiFair && s.state.EndsWith(Constants.ACCEPT_STATE)) { BuchiFair = true; } } //outgoing.Count == 0 --> deadlock, we need to check //outgoing.Count == 0 //StronglyConnectedComponets.Count > 1 || selfLoop -> non-trivial case, we need to check int SCCSize = SCCPairs.Count; if (BuchiFair && (evt.IsDeadLock || SCCSize > 1 || selfLoop)) { //SCCCount++; SCCTotalSize += SCCSize; //System.Diagnostics.Debug.WriteLine(size); // If forking condition is met, create new thread to process the SCC if (SCCSize >= SCC_MINIMUM_SIZE_BOUND_FOR_THREAD_FORKING && ThreadPool.ThreadNumber < Ultility.Ultility.PARALLEL_MODEL_CHECKIMG_BOUND) { //System.Diagnostics.Debug.WriteLine("fork"); //BigSCCCount++; Dictionary <string, LocalPair> SCC = new Dictionary <string, LocalPair>(SCCPairs); StartFairThread(SCC); //System.Diagnostics.Debug.WriteLine("(" + ThreadPool.ThreadNumber + ")"); } // If the size of scc is small or the thread pool is full, // process the SCC locally is more efficient else { //System.Diagnostics.Debug.WriteLine("self"); Dictionary <string, LocalPair> value = IsFair(SCCPairs, OutgoingTransitionTable); if (value != null) { JobFinished = true; VerificationResult = VerificationResultType.INVALID; FairSCC = value; ThreadPool.StopAllThreads(); return; } } } foreach (string componet in SCCPairs.Keys) { ExpendedNode.Remove(componet); //BuchiFairTable.Remove(componet.ToString()); //OutgoingTransitionTable.Remove(componet); } SCCPairs = new Dictionary <string, LocalPair>(1024); } else { stepStack.Push(pair); } } } while (TaskStack.Count > 0); JobFinished = true; return; }
public void TarjanModelChecking() { OutgoingTransitionTable = new Dictionary<string, List<string>>(Ultility.Ultility.MC_INITIAL_SIZE); TaskStack = new Stack<LocalPair>(Ultility.Ultility.MC_INITIAL_SIZE); DFSData = new StringDictionary<int[]>(Ultility.Ultility.MC_INITIAL_SIZE); List<LocalPair> initials = LocalPair.GetInitialPairsLocal(BA, initialStep); if (initials.Count == 0 || !BA.HasAcceptState) { VerificationResult = VerificationResultType.VALID; return; } for (int z = 0; z < initials.Count; z++) { LocalPair initState = initials[z]; TaskStack.Push(initState); string ID = initState.GetCompressedState(); DFSData.Add(ID, new int[] { VISITED_NOPREORDER, 0 }); OutgoingTransitionTable.Add(ID, new List<string>(8)); } Dictionary<string, LocalPair> SCCPairs = new Dictionary<string, LocalPair>(1024); Stack<LocalPair> stepStack = new Stack<LocalPair>(1024); //# Preorder counter int i = 0; //store the expended event step of a node to avoid multiple invocation of the make one move. Dictionary<string, List<LocalPair>> ExpendedNode = new Dictionary<string, List<LocalPair>>(1024); //PrintMessage("Start to find the Strongly Connected Component of graph."); do { if (SearchedDepth < TaskStack.Count) { SearchedDepth = TaskStack.Count; } if (JobFinished) { return; } LocalPair pair = TaskStack.Peek(); ConfigurationBase evt = pair.configuration; string BAState = pair.state; string v = pair.GetCompressedState(); List<string> outgoing = OutgoingTransitionTable[v]; int[] nodeData = DFSData.GetContainsKey(v); if (nodeData[0] == VISITED_NOPREORDER) { nodeData[0] = i; i++; } bool done = true; if (ExpendedNode.ContainsKey(v)) { List<LocalPair> list = ExpendedNode[v]; if (list.Count > 0) { //transverse all steps for (int k = list.Count - 1; k >= 0; k--) { LocalPair step = list[k]; string tmp = step.GetCompressedState(); //if the step is a unvisited step if (DFSData.GetContainsKey(tmp)[0] == VISITED_NOPREORDER) { //only add the first unvisited step //for the second or more unvisited steps, ignore at the monent if (done) { TaskStack.Push(step); done = false; list.RemoveAt(k); } } else { list.RemoveAt(k); } } } } else { //ConfigurationBase[] list = evt.MakeOneMove().ToArray(); IEnumerable<ConfigurationBase> list = evt.MakeOneMove(); pair.SetEnabled(list, FairnessType); List<LocalPair> product = LocalPair.NextLocal(BA, list, BAState); //count the transitions visited Transitions += product.Count; for (int k = product.Count - 1; k >= 0; k--) { LocalPair step = product[k]; string tmp = step.GetCompressedState(); //if (VisitedWithID.ContainsKey(tmp)) int[] data = DFSData.GetContainsKey(tmp); if (data != null) { //update the incoming and outgoing edges //int t = VisitedWithID.GetContainsKey(tmp); //DataStore.DataManager.GetID(tmp); outgoing.Add(tmp); //if this node is still not visited if (data[0] == VISITED_NOPREORDER) { //step.ID = t; //only put the first one to the work list stack. //if there are more than one node to be visited, //simply ignore them and keep its event step in the list. if (done) { TaskStack.Push(step); done = false; product.RemoveAt(k); } else { product[k] = step; } } //this node is truly visited. can be removed else { product.RemoveAt(k); } } else { //int stateID = VisitedWithID.Count; //VisitedWithID.Add(tmp,false); DFSData.Add(tmp, new int[] { VISITED_NOPREORDER, 0 }); OutgoingTransitionTable.Add(tmp, new List<string>(8)); //step.ID = stateID; outgoing.Add(tmp); //only put the first one into the stack. if (done) { TaskStack.Push(step); done = false; product.RemoveAt(k); } else { product[k] = step; } } } //create the remaining steps as the expending list for v ExpendedNode.Add(v, product); } if (done) { int lowlinkV = nodeData[0]; int preorderV = lowlinkV; bool selfLoop = false; // Calculate the low link of an explored state for (int j = 0; j < outgoing.Count; j++) { string w = outgoing[j]; if (w == v) { selfLoop = true; } int[] wdata = DFSData.GetContainsKey(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; TaskStack.Pop(); // Check whether the current state is the root of the SCC if (lowlinkV == preorderV) { SCCPairs.Add(v, pair); nodeData[0] = SCC_FOUND; bool BuchiFair = pair.state.EndsWith(Constants.ACCEPT_STATE); //for buchi-fair // Get the elements of the SCC from the step stack while (stepStack.Count > 0 && DFSData.GetContainsKey(stepStack.Peek().GetCompressedState())[0] > preorderV) { LocalPair s = stepStack.Pop(); string k = s.GetCompressedState(); SCCPairs.Add(k, s); DFSData.GetContainsKey(k)[0] = SCC_FOUND; if (!BuchiFair && s.state.EndsWith(Constants.ACCEPT_STATE)) { BuchiFair = true; } } //outgoing.Count == 0 --> deadlock, we need to check //outgoing.Count == 0 //StronglyConnectedComponets.Count > 1 || selfLoop -> non-trivial case, we need to check int SCCSize = SCCPairs.Count; if (BuchiFair && (evt.IsDeadLock || SCCSize > 1 || selfLoop)) { //SCCCount++; SCCTotalSize += SCCSize; //System.Diagnostics.Debug.WriteLine(size); // If forking condition is met, create new thread to process the SCC if (SCCSize >= SCC_MINIMUM_SIZE_BOUND_FOR_THREAD_FORKING && ThreadPool.ThreadNumber < Ultility.Ultility.PARALLEL_MODEL_CHECKIMG_BOUND) { //System.Diagnostics.Debug.WriteLine("fork"); //BigSCCCount++; Dictionary<string, LocalPair> SCC = new Dictionary<string, LocalPair>(SCCPairs); StartFairThread(SCC); //System.Diagnostics.Debug.WriteLine("(" + ThreadPool.ThreadNumber + ")"); } // If the size of scc is small or the thread pool is full, // process the SCC locally is more efficient else { //System.Diagnostics.Debug.WriteLine("self"); Dictionary<string, LocalPair> value = IsFair(SCCPairs, OutgoingTransitionTable); if(value != null) { JobFinished = true; VerificationResult = VerificationResultType.INVALID; FairSCC = value; ThreadPool.StopAllThreads(); return; } } } foreach (string componet in SCCPairs.Keys) { ExpendedNode.Remove(componet); //BuchiFairTable.Remove(componet.ToString()); //OutgoingTransitionTable.Remove(componet); } SCCPairs = new Dictionary<string, LocalPair>(1024); } else { stepStack.Push(pair); } } } while (TaskStack.Count > 0); JobFinished = true; return; }
public VerificationOutput(string engine) { VerificationResult = VerificationResultType.UNKNOWN; CounterExampleTrace = new List<ConfigurationBase>(64); Transitions = 0; NoOfStates = 0; LoopIndex = -1; ReducedMDPTransitions = 0; ReducedMDPStates = 0; Timer = new Stopwatch(); switch (engine) { case Constants.ENGINE_BDD_SEARCH: case Constants.ENGINE_BACKWARD_SEARCH_BDD: case Constants.ENGINE_FORWARD_BACKWARD_SEARCH_BDD: case Constants.ENGINE_FORWARD_SEARCH_BDD: VerificationOutputType = VerificationOutputType.LTS_BDD; break; case Constants.ENGINE_MDP_SEARCH: case Constants.ENGINE_SMT_MDP: case Constants.ENGINE_SMT_DTMC: VerificationOutputType = VerificationOutputType.MDP_EXPLICIT; break; case Constants.ENGINE_SCC_BASED_SEARCH_MULTICORE: VerificationOutputType = VerificationOutputType.LTS_EXPLICIT_MULTI_CORE; break; default: VerificationOutputType = VerificationOutputType.LTS_EXPLICIT; break; } }