Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
MonotonicityHelper.h
Go to the documentation of this file.
1#ifndef STORM_MONOTONICITYHELPER_H
2#define STORM_MONOTONICITYHELPER_H
3
4#include <map>
5#include "AssumptionMaker.h"
8#include "Order.h"
9#include "OrderExtender.h"
10
11#include "storm/logic/Formula.h"
12
16
18
23
25
27
28namespace storm {
29namespace analysis {
30
31template<typename ValueType, typename ConstantType>
33 public:
38
50 MonotonicityHelper(std::shared_ptr<models::sparse::Model<ValueType>> model, std::vector<std::shared_ptr<logic::Formula const>> formulas,
51 std::vector<storage::ParameterRegion<ValueType>> regions, uint_fast64_t numberOfSamples = 0, double const& precision = 0.000001,
52 bool dotOutput = false);
53
60 static std::pair<bool, bool> checkDerivative(ValueType derivative, storage::ParameterRegion<ValueType> reg) {
61 bool monIncr = false;
62 bool monDecr = false;
63
64 if (derivative.isZero()) {
65 monIncr = true;
66 monDecr = true;
67 } else if (derivative.isConstant()) {
68 monIncr = derivative.constantPart() >= 0;
69 monDecr = derivative.constantPart() <= 0;
70 } else {
71 std::shared_ptr<utility::solver::SmtSolverFactory> smtSolverFactory = std::make_shared<utility::solver::MathsatSmtSolverFactory>();
72 std::shared_ptr<expressions::ExpressionManager> manager(new expressions::ExpressionManager());
73 solver::Z3SmtSolver s(*manager);
74 std::set<VariableType> variables = derivative.gatherVariables();
75
76 expressions::Expression exprBounds = manager->boolean(true);
77 for (auto variable : variables) {
78 auto managerVariable = manager->declareRationalVariable(variable.name());
79 auto lb = utility::convertNumber<RationalNumber>(reg.getLowerBoundary(variable));
80 auto ub = utility::convertNumber<RationalNumber>(reg.getUpperBoundary(variable));
81 exprBounds = exprBounds && manager->rational(lb) < managerVariable && managerVariable < manager->rational(ub);
82 }
83
85
86 // < 0, so not monotone increasing. If this is unsat, then it should be monotone increasing.
87 expressions::Expression exprToCheck = converter.toExpression(derivative) < manager->rational(0);
88 s.add(exprBounds);
89 s.add(exprToCheck);
91
92 // > 0, so not monotone decreasing. If this is unsat it should be monotone decreasing.
93 exprToCheck = converter.toExpression(derivative) > manager->rational(0);
94 s.reset();
95 s.add(exprBounds);
96 s.add(exprToCheck);
98 }
99 assert(!(monIncr && monDecr) || derivative.isZero());
100
101 return std::pair<bool, bool>(monIncr, monDecr);
102 }
103
111 std::map<std::shared_ptr<Order>,
112 std::pair<std::shared_ptr<MonotonicityResult<VariableType>>, std::vector<std::shared_ptr<expressions::BinaryRelationExpression>>>>
113 checkMonotonicityInBuild(std::ostream& outfile, bool usePLA = false, std::string dotOutfileName = "dotOutput");
114
119 std::shared_ptr<LocalMonotonicityResult<VariableType>> createLocalMonotonicityResult(std::shared_ptr<Order> order,
121
131 Monotonicity checkLocalMonotonicity(std::shared_ptr<Order> order, uint_fast64_t state, VariableType var, storage::ParameterRegion<ValueType> region);
132
133 private:
134 void createOrder();
135
136 void checkMonotonicityOnSamples(std::shared_ptr<models::sparse::Dtmc<ValueType>> model, uint_fast64_t numberOfSamples);
137
138 void checkMonotonicityOnSamples(std::shared_ptr<models::sparse::Mdp<ValueType>> model, uint_fast64_t numberOfSamples);
139
140 void extendOrderWithAssumptions(std::shared_ptr<Order> order, uint_fast64_t val1, uint_fast64_t val2,
141 std::vector<std::shared_ptr<expressions::BinaryRelationExpression>> assumptions,
142 std::shared_ptr<MonotonicityResult<VariableType>> monRes);
143
144 Monotonicity checkTransitionMonRes(ValueType function, VariableType param, Region region);
145
146 ValueType getDerivative(ValueType function, VariableType var);
147
148 std::shared_ptr<models::ModelBase> model;
149
150 std::vector<std::shared_ptr<logic::Formula const>> formulas;
151
152 bool dotOutput;
153
154 bool checkSamples;
155
156 bool onlyCheckOnOrder;
157
158 MonotonicityResult<VariableType> resultCheckOnSamples;
159
160 std::map<VariableType, std::vector<uint_fast64_t>> occuringStatesAtVariable;
161
162 std::map<std::shared_ptr<Order>,
163 std::pair<std::shared_ptr<MonotonicityResult<VariableType>>, std::vector<std::shared_ptr<expressions::BinaryRelationExpression>>>>
164 monResults;
165
167
168 ConstantType precision;
169
170 Region region;
171
173
174 std::unordered_map<ValueType, std::unordered_map<VariableType, ValueType>> derivatives;
175
177};
178} // namespace analysis
179} // namespace storm
180#endif // STORM_MONOTONICITYHELPER_H
MonotonicityResult< VariableType >::Monotonicity Monotonicity
std::map< std::shared_ptr< Order >, std::pair< std::shared_ptr< MonotonicityResult< VariableType > >, std::vector< std::shared_ptr< expressions::BinaryRelationExpression > > > > checkMonotonicityInBuild(std::ostream &outfile, bool usePLA=false, std::string dotOutfileName="dotOutput")
Builds Reachability Orders for the given model and simultaneously uses them to check for Monotonicity...
std::shared_ptr< LocalMonotonicityResult< VariableType > > createLocalMonotonicityResult(std::shared_ptr< Order > order, storage::ParameterRegion< ValueType > region)
Builds Reachability Orders for the given model and simultaneously uses them to check for Monotonicity...
Monotonicity checkLocalMonotonicity(std::shared_ptr< Order > order, uint_fast64_t state, VariableType var, storage::ParameterRegion< ValueType > region)
Checks for local monotonicity at the given state.
storage::ParameterRegion< ValueType > Region
utility::parametric::VariableType< ValueType >::type VariableType
utility::parametric::CoefficientType< ValueType >::type CoefficientType
static std::pair< bool, bool > checkDerivative(ValueType derivative, storage::ParameterRegion< ValueType > reg)
Checks if a derivative >=0 or/and <=0.
Monotonicity
The results of monotonicity checking for a single Parameter Region.
This class is responsible for managing a set of typed variables and all expressions using these varia...
This class represents a discrete-time Markov chain.
Definition Dtmc.h:14
This class represents a (discrete-time) Markov decision process.
Definition Mdp.h:14
Base class for all sparse models.
Definition Model.h:33
virtual void add(storm::expressions::Expression const &assertion) override
Adds an assertion to the solver's stack.
virtual void reset() override
Removes all assertions from the solver's stack.
virtual CheckResult check() override
Checks whether the conjunction of assertions that are currently on the solver's stack is satisfiable.
CoefficientType const & getLowerBoundary(VariableType const &variable) const
CoefficientType const & getUpperBoundary(VariableType const &variable) const
A class that holds a possibly non-square matrix in the compressed row storage format.
LabParser.cpp.
Definition cli.cpp:18