private MDP BuildMDPSubset() { DeterministicAutomata_Subset specAutomaton = BuildDeterministicAutomata_Subset(InitSpecStep); Stack <TupleSub> working = new Stack <TupleSub>(1024); DeterministicFAState_Subset InitialSpec = specAutomaton.InitialState; Dictionary <string, Dictionary <int, MDPState> > visited = new Dictionary <string, Dictionary <int, MDPState> >(); int specID = InitialSpec.GetID(); string impID = InitialStep.GetID(); MDPState init = new MDPState(impID + Constants.SEPARATOR + specID); working.Push(new TupleSub(InitialStep as MDPConfiguration, InitialSpec, init)); Dictionary <int, MDPState> initialDic = new Dictionary <int, MDPState>(); initialDic.Add(specID, init); visited.Add(impID, initialDic); MDP mdp = new MDP(init, Ultility.Ultility.DEFAULT_PRECISION, Ultility.Ultility.MAX_DIFFERENCE); do { if (CancelRequested) { VerificationOutput.NoOfStates = mdp.States.Count; return(mdp); } TupleSub current = working.Pop(); if (current.SpecState == null) { mdp.AddTargetStates(current.MDPState); } else { IEnumerable <MDPConfiguration> list = current.ImplState.MakeOneMoveLocal(); VerificationOutput.Transitions += list.Count(); int currentDistriIndex = -1; Distribution newDis = new Distribution(Constants.TAU); //for (int i = 0; i < list.Count; i++) foreach (var step in list) { //MDPConfiguration step = list[i]; DeterministicFAState_Subset nextSpec = current.SpecState; if (step.Event != Constants.TAU) { nextSpec = current.SpecState.Next(step.Event); } //System.Diagnostics.Debug.Assert(nextSpec != null, "NextSpec is null!!"); //string stepID = step.GetID() + Constants.SEPARATOR + nextSpec.GetID().ToString(); impID = step.GetID(); string stepID = impID + Constants.SEPARATOR + (nextSpec == null ? "" : nextSpec.GetID().ToString()); MDPState nextState; if (!mdp.States.TryGetValue(stepID, out nextState)) { nextState = new MDPState(stepID); //mdp.AddState(nextState); //KeyValuePair<MDPConfiguration, DeterministicFAState_Subset> newPair = // new KeyValuePair<MDPConfiguration, DeterministicFAState_Subset>(step, nextSpec); working.Push(new TupleSub(step, nextSpec, nextState)); if (nextSpec != null) { specID = nextSpec.GetID(); //DeterministicFAState_Subset DFAstate = nextSpec; Dictionary <int, MDPState> mapping = null; if (visited.TryGetValue(impID, out mapping)) { //int Spec = nextSpec.GetID(); mapping.Add(specID, nextState); foreach (int spec in mapping.Keys) { if (specAutomaton.States[spec].Sub.Contains(nextSpec)) { mapping[spec].Sub.Add(nextState); } else if (nextSpec.Sub.Contains(specAutomaton.States[spec])) { nextState.Sub.Add(mapping[spec]); } } //foreach (var x in visited) //{ // if (x.Key.Key.GetID() == newPair.Key.GetID() && // x.SpecState.Sub.Contains(newPair.Value)) // { // x.Value.Sub.Add(nextState); // } // else if (x.Key.Key.GetID() == newPair.Key.GetID() && // newPair.Value.Sub.Contains(x.SpecState)) // { // nextState.Sub.Add(x.Value); // } //} //visited.Add(newPair, nextState); } else { Dictionary <int, MDPState> newDicDic = new Dictionary <int, MDPState>(); newDicDic.Add(specID, nextState); visited.Add(impID, newDicDic); } } mdp.AddState(nextState); } if (step.DisIndex == -1) { if (currentDistriIndex >= 0) { current.MDPState.AddDistribution(newDis); newDis = new Distribution(Constants.TAU); } Distribution newTrivialDis = new Distribution(step.Event, nextState); current.MDPState.AddDistribution(newTrivialDis); } else if (currentDistriIndex != -1 && step.DisIndex != currentDistriIndex) { current.MDPState.AddDistribution(newDis); newDis = new Distribution(Constants.TAU); newDis.AddProbStatePair(step.Probability, nextState); } else { newDis.AddProbStatePair(step.Probability, nextState); } currentDistriIndex = step.DisIndex; } if (currentDistriIndex >= 0) { current.MDPState.AddDistribution(newDis); } } } while (working.Count > 0); VerificationOutput.NoOfStates = mdp.States.Count; //mdp.BackUpTargetStates(); return(mdp); }
private MDP BuildMDPAntiChain_S() { DeterministicAutomata_Subset specAutomaton = BuildDeterministicAutomata_Subset(InitSpecStep); Stack <TupleSub> working = new Stack <TupleSub>(1024); DeterministicFAState_Subset InitialSpec = specAutomaton.InitialState; Dictionary <string, HashSet <DeterministicFAState_Subset> > antichain = new Dictionary <string, HashSet <DeterministicFAState_Subset> >(); string impID = InitialStep.GetID(); int specID = InitialSpec.GetID(); MDPState init = new MDPState(impID + Constants.SEPARATOR + specID); working.Push(new TupleSub(InitialStep as MDPConfiguration, InitialSpec, init)); MDP mdp = new MDP(init, Ultility.Ultility.DEFAULT_PRECISION, Ultility.Ultility.MAX_DIFFERENCE); HashSet <DeterministicFAState_Subset> Specs = new HashSet <DeterministicFAState_Subset>(); Specs.Add(InitialSpec); antichain.Add(impID, Specs); do { if (CancelRequested) { VerificationOutput.NoOfStates = mdp.States.Count; return(mdp); } TupleSub current = working.Pop(); if (current.SpecState == null) { mdp.AddTargetStates(current.MDPState); } else { IEnumerable <MDPConfiguration> list = current.ImplState.MakeOneMoveLocal(); VerificationOutput.Transitions += list.Count(); int currentDistriIndex = -1; Distribution newDis = new Distribution(Constants.TAU); //for (int i = 0; i < list.Count; i++) foreach (MDPConfiguration step in list) { //MDPConfiguration step = list[i]; DeterministicFAState_Subset nextSpec = current.SpecState; if (step.Event != Constants.TAU) { nextSpec = current.SpecState.Next(step.Event); } //System.Diagnostics.Debug.Assert(nextSpec != null, "NextSpec is null!!"); //string stepID = step.GetID() + Constants.SEPARATOR + nextSpec.GetID().ToString(); impID = step.GetID(); string stepID = impID + Constants.SEPARATOR + (nextSpec == null ? "" : nextSpec.GetID().ToString()); MDPState nextState; if (!mdp.States.TryGetValue(stepID, out nextState)) { nextState = new MDPState(stepID); //mdp.AddState(nextState); //KeyValuePair<MDPConfiguration, DeterministicFAState_Subset> newPair = // new KeyValuePair<MDPConfiguration, DeterministicFAState_Subset>(step, nextSpec); //working.Push(new TupleSub(step, nextSpec, nextState)); bool addstate = true; if (nextSpec != null) { //specID = nextSpec.GetID(); //DeterministicFAState_Subset DFAstate = nextSpec; HashSet <DeterministicFAState_Subset> specStates; //Dictionary<int, MDPState> mapping = null; if (antichain.TryGetValue(impID, out specStates)) { HashSet <DeterministicFAState_Subset> toRemove = new HashSet <DeterministicFAState_Subset>(); //int Spec = nextSpec.GetID(); bool chainIncrease = true; foreach (DeterministicFAState_Subset specState in specStates) { //DeterministicFAState_Subset specState = specStates[j]; if (specState.Sub.Contains(nextSpec)) { toRemove.Add(specState); nextSpec.Sub.Add(specState); chainIncrease = false; } if (nextSpec.Sub.Contains(specState)) { nextSpec = specState; addstate = false; chainIncrease = false; break; } } if (toRemove.Count > 0) { foreach (var specState in toRemove) { specStates.Remove(specState); } specStates.Add(nextSpec); // toRemove; } else if (chainIncrease) { specStates.Add(nextSpec); } } else { HashSet <DeterministicFAState_Subset> newSpecs = new HashSet <DeterministicFAState_Subset>(); newSpecs.Add(nextSpec); antichain.Add(impID, newSpecs); } } if (addstate) { mdp.AddState(nextState); working.Push(new TupleSub(step, nextSpec, nextState)); } } if (step.DisIndex == -1) { if (currentDistriIndex >= 0) { current.MDPState.AddDistribution(newDis); newDis = new Distribution(Constants.TAU); } Distribution newTrivialDis = new Distribution(step.Event, nextState); current.MDPState.AddDistribution(newTrivialDis); } else if (currentDistriIndex != -1 && step.DisIndex != currentDistriIndex) { current.MDPState.AddDistribution(newDis); newDis = new Distribution(Constants.TAU); newDis.AddProbStatePair(step.Probability, nextState); } else { newDis.AddProbStatePair(step.Probability, nextState); } currentDistriIndex = step.DisIndex; } if (currentDistriIndex >= 0) { current.MDPState.AddDistribution(newDis); } } } while (working.Count > 0); VerificationOutput.NoOfStates = mdp.States.Count; //mdp.BackUpTargetStates(); return(mdp); }
public TupleSub(MDPConfiguration imp, DeterministicFAState_Subset spec, MDPState mdp) { ImplState = imp; SpecState = spec; MDPState = mdp; }