/// <summary> /// Calculates the probability of formula. /// </summary> /// <param name="model">The model that should be checked.</param> /// <param name="formula">The state formula to be checked.</param> /// <param name="terminateEarlyFormula">When terminateEarlyFormula is satisfied stop building the state space.</param> /// <param name="bound">The maximal number of steps. If stateFormula is satisfied the first time any step later than bound, this probability does not count into the end result.</param> public static ProbabilityRange CalculateProbabilityRangeOfFormulaBounded(ModelBase model, Formula formula, Formula terminateEarlyFormula, int bound) { ProbabilityRange probabilityRangeToReachState; var createModel = SafetySharpRuntimeModel.CreateExecutedModelFromFormulasCreator(model); var nmdpGenerator = new NmdpFromExecutableModelGenerator <SafetySharpRuntimeModel>(createModel) { Configuration = TraversalConfiguration }; nmdpGenerator.AddFormulaToCheck(formula); var nmdp = nmdpGenerator.GenerateMarkovDecisionProcess(terminateEarlyFormula); if (_convertNmdpToMdp) { var nmdpToMpd = new NmdpToMdp(nmdp); var mdp = nmdpToMpd.MarkovDecisionProcess; using (var modelChecker = new BuiltinMdpModelChecker(mdp, System.Console.Out)) { probabilityRangeToReachState = modelChecker.CalculateProbabilityRange(formula); } } else { using (var modelChecker = new BuiltinNmdpModelChecker(nmdp, System.Console.Out)) { probabilityRangeToReachState = modelChecker.CalculateProbabilityRange(formula); } } return(probabilityRangeToReachState); }
/// <summary> /// Calculates the probability to reach a state where <paramref name="stateFormula" /> holds. /// </summary> /// <param name="model">The model that should be checked.</param> /// <param name="stateFormula">The state formula which _must_ finally be true.</param> public static ProbabilityRange CalculateProbabilityRangeToReachState(ModelBase model, Formula stateFormula) { ProbabilityRange probabilityRangeToReachState; var probabilityToReachStateFormula = new UnaryFormula(stateFormula, UnaryOperator.Finally); var createModel = SafetySharpRuntimeModel.CreateExecutedModelFromFormulasCreator(model); var nmdpGenerator = new NmdpFromExecutableModelGenerator <SafetySharpRuntimeModel>(createModel) { Configuration = TraversalConfiguration }; nmdpGenerator.AddFormulaToCheck(probabilityToReachStateFormula); nmdpGenerator.Configuration.SuccessorCapacity *= 8; var nmdp = nmdpGenerator.GenerateMarkovDecisionProcess(stateFormula); if (_convertNmdpToMdp) { var nmdpToMpd = new NmdpToMdp(nmdp); var mdp = nmdpToMpd.MarkovDecisionProcess; using (var modelChecker = new BuiltinMdpModelChecker(mdp, System.Console.Out)) { probabilityRangeToReachState = modelChecker.CalculateProbabilityRange(probabilityToReachStateFormula); } } else { using (var modelChecker = new BuiltinNmdpModelChecker(nmdp, System.Console.Out)) { probabilityRangeToReachState = modelChecker.CalculateProbabilityRange(probabilityToReachStateFormula); } } return(probabilityRangeToReachState); }