public DeterministicAutomata Determinize() { Dictionary <string, DeterministicFAState> Visited = new Dictionary <string, DeterministicFAState>(Ultility.Ultility.MC_INITIAL_SIZE); Stack <NormalizedFAState> pending = new Stack <NormalizedFAState>(1024); NormalizedFAState current = (new NormalizedFAState(InitialState)).TauReachable(); pending.Push(current); DeterministicAutomata toReturn = new DeterministicAutomata(); Visited.Add(current.GetID(), toReturn.AddInitialState()); while (pending.Count > 0) { current = pending.Pop(); DeterministicFAState currentState = Visited[current.GetID()]; Dictionary <string, HashSet <FAState> > nexts = new Dictionary <string, HashSet <FAState> >(); foreach (FAState state in current.States) { foreach (KeyValuePair <string, HashSet <FAState> > pair in state.Post) { if (pair.Key != Constants.TAU) { HashSet <FAState> states; if (!nexts.TryGetValue(pair.Key, out states)) { states = new HashSet <FAState>(); nexts.Add(pair.Key, states); } foreach (FAState faState in pair.Value) { states.Add(faState); } } } } foreach (KeyValuePair <string, HashSet <FAState> > keyValuePair in nexts) { NormalizedFAState next = new NormalizedFAState(keyValuePair.Value); NormalizedFAState newState = next.TauReachable(); DeterministicFAState target; if (!Visited.TryGetValue(newState.GetID(), out target)) { target = toReturn.AddState(); Visited.Add(newState.GetID(), target); pending.Push(newState); } toReturn.AddTransition(currentState, keyValuePair.Key, target); } } return(toReturn); }
public static void TraceInclusionCheck(ConfigurationBase currentImpl, Automata spec, VerificationOutput VerificationOutput) { FAState[] states = spec.States.Values.ToArray(); //bool[] isFinal = new bool[states.Length]; bool[,] fsim = new bool[states.Length, states.Length]; // sim[u][v]=true iff v in sim(u) iff v simulates u //for (int i = 0; i < states.Length; i++) //{ // isFinal[i] = spec.F.Contains(states[i]); //} for (int i = 0; i < states.Length; i++) { for (int j = i; j < states.Length; j++) { fsim[i, j] = states[j].covers(states[i]); //(!isFinal[i] || isFinal[j]) && fsim[j, i] = states[i].covers(states[j]); //(isFinal[i] || !isFinal[j]) && } } Dictionary <string, HashSet <FAState> > rel_spec = FastFSimRelNBW(spec, fsim); StringHashTable Visited = new StringHashTable(Ultility.Ultility.MC_INITIAL_SIZE); List <ConfigurationBase> toReturn = new List <ConfigurationBase>(); Stack <ConfigurationBase> pendingImpl = new Stack <ConfigurationBase>(1024); Stack <NormalizedFAState> pendingSpec = new Stack <NormalizedFAState>(1024); //The following are for identifying a counterexample trace. Stack <int> depthStack = new Stack <int>(1024); depthStack.Push(0); List <int> depthList = new List <int>(1024); //The above are for identifying a counterexample trace. //implementation initial state pendingImpl.Push(currentImpl); //specification initial state NormalizedFAState currentSpec = new NormalizedFAState(spec.InitialState, rel_spec); #if TEST pendingSpec.Push(currentSpec.TauReachable()); #else pendingSpec.Push(currentSpec); #endif while (pendingImpl.Count > 0) { currentImpl = pendingImpl.Pop(); currentSpec = pendingSpec.Pop(); string ID = currentImpl.GetID() + Constants.SEPARATOR + currentSpec.GetID(); if (Visited.ContainsKey(ID)) { continue; } Visited.Add(ID); //The following are for identifying a counterexample trace. int depth = depthStack.Pop(); while (depth > 0 && depthList[depthList.Count - 1] >= depth) { int lastIndex = depthList.Count - 1; depthList.RemoveAt(lastIndex); toReturn.RemoveAt(lastIndex); } toReturn.Add(currentImpl); depthList.Add(depth); //If the specification has no corresponding state, then it implies that the trace is allowed by the //implementation but not the specification -- which means trace-refinement is failed. if (currentSpec.States.Count == 0) { VerificationOutput.NoOfStates = Visited.Count; VerificationOutput.CounterExampleTrace = toReturn; VerificationOutput.VerificationResult = VerificationResultType.INVALID; return; } ConfigurationBase[] nextImpl = currentImpl.MakeOneMove(); VerificationOutput.Transitions += nextImpl.Length; for (int k = 0; k < nextImpl.Length; k++) { ConfigurationBase next = nextImpl[k]; if (next.Event != Constants.TAU) { NormalizedFAState nextSpec = currentSpec.Next(next.Event, rel_spec); pendingImpl.Push(next); pendingSpec.Push(nextSpec); depthStack.Push(depth + 1); } else { pendingImpl.Push(next); pendingSpec.Push(currentSpec); depthStack.Push(depth + 1); } } } VerificationOutput.NoOfStates = Visited.Count; VerificationOutput.VerificationResult = VerificationResultType.VALID; //return null; }
public DeterministicAutomata_Subset DeterminizeSubset() { Dictionary <string, DeterministicFAState_Subset> Visited = new Dictionary <string, DeterministicFAState_Subset>(Ultility.Ultility.MC_INITIAL_SIZE); HashSet <NormalizedFAState> VisitedNormalizedState = new HashSet <NormalizedFAState>(); Stack <NormalizedFAState> pending = new Stack <NormalizedFAState>(1024); NormalizedFAState current = (new NormalizedFAState(InitialState)).TauReachable(); VisitedNormalizedState.Add(current); pending.Push(current); DeterministicAutomata_Subset toReturn = new DeterministicAutomata_Subset(); Visited.Add(current.GetID(), toReturn.AddInitialState()); while (pending.Count > 0) { current = pending.Pop(); DeterministicFAState_Subset currentState = Visited[current.GetID()]; Dictionary <string, HashSet <FAState> > nexts = new Dictionary <string, HashSet <FAState> >(); foreach (FAState state in current.States) { foreach (KeyValuePair <string, HashSet <FAState> > pair in state.Post) { if (pair.Key != Constants.TAU) { HashSet <FAState> states; if (!nexts.TryGetValue(pair.Key, out states)) { states = new HashSet <FAState>(); nexts.Add(pair.Key, states); } foreach (FAState faState in pair.Value) { states.Add(faState); } } } } foreach (KeyValuePair <string, HashSet <FAState> > keyValuePair in nexts) { NormalizedFAState next = new NormalizedFAState(keyValuePair.Value); NormalizedFAState newState = next.TauReachable(); //foreach (NormalizedFAState state in ) //{ // if(newState.States.IsProperSupersetOf(state.States)) // { // newState.sub.Add(state); // } //} DeterministicFAState_Subset target; if (!Visited.TryGetValue(newState.GetID(), out target)) { VisitedNormalizedState.Add(newState); target = toReturn.AddState(); Visited.Add(newState.GetID(), target); //foreach(var deterministicFaState in Visited) //{ //} pending.Push(newState); } toReturn.AddTransition(currentState, keyValuePair.Key, target); foreach (var nstate in VisitedNormalizedState) { if (newState.States.IsProperSupersetOf(nstate.States)) { Visited[newState.GetID()].Sub.Add(Visited[nstate.GetID()]); } else if (newState.States.IsProperSubsetOf(nstate.States)) { Visited[nstate.GetID()].Sub.Add(Visited[newState.GetID()]); } } } } return(toReturn); }