Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
counterexamples.cpp
Go to the documentation of this file.
2
5
6namespace storm {
7namespace api {
8
9std::shared_ptr<storm::counterexamples::Counterexample> computeHighLevelCounterexampleMilp(storm::storage::SymbolicModelDescription const& symbolicModel,
10 std::shared_ptr<storm::models::sparse::Mdp<double>> mdp,
11 std::shared_ptr<storm::logic::Formula const> const& formula) {
12 Environment env;
14}
15
16std::shared_ptr<storm::counterexamples::Counterexample> computeHighLevelCounterexampleMaxSmt(storm::storage::SymbolicModelDescription const& symbolicModel,
17 std::shared_ptr<storm::models::sparse::Model<double>> model,
18 std::shared_ptr<storm::logic::Formula const> const& formula) {
19 Environment env;
21}
22
23std::shared_ptr<storm::counterexamples::Counterexample> computeKShortestPathCounterexample(std::shared_ptr<storm::models::sparse::Model<double>> model,
24 std::shared_ptr<storm::logic::Formula const> const& formula,
25 size_t maxK) {
26 // Only accept formulas of the form "P </<= x [F target]
27 STORM_LOG_THROW(formula->isProbabilityOperatorFormula(), storm::exceptions::InvalidPropertyException,
28 "Counterexample generation does not support this kind of formula. Expecting a probability operator as the outermost formula element.");
29 storm::logic::ProbabilityOperatorFormula const& probabilityOperator = formula->asProbabilityOperatorFormula();
30 STORM_LOG_THROW(probabilityOperator.hasBound(), storm::exceptions::InvalidPropertyException, "Counterexample generation only supports bounded formulas.");
31 STORM_LOG_THROW(!storm::logic::isLowerBound(probabilityOperator.getComparisonType()), storm::exceptions::InvalidPropertyException,
32 "Counterexample generation only supports upper bounds.");
33 double threshold = probabilityOperator.getThresholdAs<double>();
34 storm::logic::Formula const& subformula = formula->asOperatorFormula().getSubformula();
35 STORM_LOG_THROW(subformula.isEventuallyFormula(), storm::exceptions::InvalidPropertyException,
36 "Path formula is required to be of the form 'F psi' for counterexample generation.");
37 bool strictBound = (probabilityOperator.getComparisonType() == storm::logic::ComparisonType::Less);
38 STORM_LOG_THROW(model->getInitialStates().getNumberOfSetBits() == 1, storm::exceptions::NotSupportedException,
39 "k-shortest paths is only supported for models with a unique initial state.");
40 size_t initialState = *(model->getInitialStates().begin());
41
42 // Perform model checking to get target states
43 Environment env;
45
46 storm::logic::EventuallyFormula const& eventuallyFormula = subformula.asEventuallyFormula();
47 std::unique_ptr<storm::modelchecker::CheckResult> subResult = modelchecker.check(env, eventuallyFormula.getSubformula());
49
50 // Check if counterexample is even possible
51 storm::storage::BitVector phiStates(model->getNumberOfStates(), true);
53 env, false, model->getTransitionMatrix(), model->getBackwardTransitions(), phiStates, subQualitativeResult.getTruthValuesVector(), true);
54 double reachProb = results.at(initialState);
55 STORM_LOG_THROW((reachProb > threshold) || (strictBound && reachProb >= threshold), storm::exceptions::InvalidArgumentException,
56 "Given probability threshold " << threshold << " cannot be " << (strictBound ? "achieved" : "exceeded")
57 << " in model with maximal reachability probability of " << reachProb << ".");
58
59 auto generator = storm::utility::ksp::ShortestPathsGenerator<double>(*model, subQualitativeResult.getTruthValuesVector());
61 double probability = 0;
62 bool thresholdExceeded = false;
63 for (size_t k = 1; k <= maxK; ++k) {
64 cex.addPath(generator.getPathAsList(k), k);
65 probability += generator.getDistance(k);
66 // Check if accumulated probability mass is already enough
67 if ((probability > threshold) || (strictBound && probability >= threshold && strictBound)) {
68 thresholdExceeded = true;
69 break;
70 }
71 }
72 STORM_LOG_WARN_COND(thresholdExceeded, "Aborted computation because maximal number of paths was reached. Probability threshold is not yet exceeded.");
73
74 return std::make_shared<storm::counterexamples::PathCounterexample<double>>(cex);
75}
76
77} // namespace api
78} // namespace storm
static std::shared_ptr< HighLevelCounterexample > computeCounterexample(Environment const &env, storm::storage::SymbolicModelDescription const &symbolicModel, storm::models::sparse::Mdp< T > const &mdp, std::shared_ptr< storm::logic::Formula const > const &formula)
Computes a (minimal) counterexample with respect to the number of prism commands for the given model ...
void addPath(std::vector< storage::sparse::state_type > path, size_t k)
static std::shared_ptr< HighLevelCounterexample > computeCounterexample(Environment const &env, storm::storage::SymbolicModelDescription const &symbolicModel, storm::models::sparse::Model< T > const &model, std::shared_ptr< storm::logic::Formula const > const &formula)
ProbabilityOperatorFormula & asProbabilityOperatorFormula()
Definition Formula.cpp:453
OperatorFormula & asOperatorFormula()
Definition Formula.cpp:469
EventuallyFormula & asEventuallyFormula()
Definition Formula.cpp:333
ComparisonType getComparisonType() const
ValueType getThresholdAs() const
Formula const & getSubformula() const
Formula const & getSubformula() const
virtual std::unique_ptr< CheckResult > check(Environment const &env, CheckTask< storm::logic::Formula, SolutionType > const &checkTask)
Checks the provided formula.
ExplicitQualitativeCheckResult & asExplicitQualitativeCheckResult()
static std::vector< ValueType > computeUntilProbabilities(Environment const &env, storm::solver::SolveGoal< ValueType > &&goal, storm::storage::SparseMatrix< ValueType > const &transitionMatrix, storm::storage::SparseMatrix< ValueType > const &backwardTransitions, storm::storage::BitVector const &phiStates, storm::storage::BitVector const &psiStates, bool qualitative, ModelCheckerHint const &hint=ModelCheckerHint())
This class represents a (discrete-time) Markov decision process.
Definition Mdp.h:14
Base class for all sparse models.
Definition Model.h:33
A bit vector that is internally represented as a vector of 64-bit values.
Definition BitVector.h:18
#define STORM_LOG_WARN_COND(cond, message)
Definition macros.h:38
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:30
std::shared_ptr< storm::counterexamples::Counterexample > computeHighLevelCounterexampleMilp(storm::storage::SymbolicModelDescription const &symbolicModel, std::shared_ptr< storm::models::sparse::Mdp< double > > mdp, std::shared_ptr< storm::logic::Formula const > const &formula)
std::shared_ptr< storm::counterexamples::Counterexample > computeHighLevelCounterexampleMaxSmt(storm::storage::SymbolicModelDescription const &symbolicModel, std::shared_ptr< storm::models::sparse::Model< double > > model, std::shared_ptr< storm::logic::Formula const > const &formula)
std::shared_ptr< storm::counterexamples::Counterexample > computeKShortestPathCounterexample(std::shared_ptr< storm::models::sparse::Model< double > > model, std::shared_ptr< storm::logic::Formula const > const &formula, size_t maxK)
bool isLowerBound(ComparisonType t)
LabParser.cpp.
Definition cli.cpp:18