Storm 1.11.1.1
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
122 private:
123 void createOrder();
124
125 void checkMonotonicityOnSamples(std::shared_ptr<models::sparse::Dtmc<ValueType>> model, uint_fast64_t numberOfSamples);
126
127 void checkMonotonicityOnSamples(std::shared_ptr<models::sparse::Mdp<ValueType>> model, uint_fast64_t numberOfSamples);
128
129 void extendOrderWithAssumptions(std::shared_ptr<Order> order, uint_fast64_t val1, uint_fast64_t val2,
130 std::vector<std::shared_ptr<expressions::BinaryRelationExpression>> assumptions,
131 std::shared_ptr<MonotonicityResult<VariableType>> monRes);
132
133 std::shared_ptr<models::ModelBase> model;
134
135 std::vector<std::shared_ptr<logic::Formula const>> formulas;
136
137 bool dotOutput;
138
139 bool checkSamples;
140
141 bool onlyCheckOnOrder;
142
143 MonotonicityResult<VariableType> resultCheckOnSamples;
144
145 std::map<VariableType, std::vector<uint_fast64_t>> occuringStatesAtVariable;
146
147 std::map<std::shared_ptr<Order>,
148 std::pair<std::shared_ptr<MonotonicityResult<VariableType>>, std::vector<std::shared_ptr<expressions::BinaryRelationExpression>>>>
149 monResults;
150
152
153 ConstantType precision;
154
155 Region region;
156
158
159 std::unordered_map<ValueType, std::unordered_map<VariableType, ValueType>> derivatives;
160
162};
163} // namespace analysis
164} // namespace storm
165#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...
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.
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:13
This class represents a (discrete-time) Markov decision process.
Definition Mdp.h:13
Base class for all sparse models.
Definition Model.h:32
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.
MonotonicityKind
The results of monotonicity checking for a single Parameter Region.