Storm 1.14.0.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
MonotonicityHelper.h
Go to the documentation of this file.
1#pragma once
2
3#include <map>
4#include "AssumptionMaker.h"
7#include "Order.h"
8#include "OrderExtender.h"
9
10#include "storm/logic/Formula.h"
11
15
17
22
24
26
27namespace storm {
28namespace analysis {
29
30template<typename ValueType, typename ConstantType>
32 public:
37
49 MonotonicityHelper(std::shared_ptr<models::sparse::Model<ValueType>> model, std::vector<std::shared_ptr<logic::Formula const>> formulas,
50 std::vector<storage::ParameterRegion<ValueType>> regions, uint_fast64_t numberOfSamples = 0, double const& precision = 0.000001,
51 bool dotOutput = false);
52
59 static std::pair<bool, bool> checkDerivative(ValueType derivative, storage::ParameterRegion<ValueType> reg) {
60 bool monIncr = false;
61 bool monDecr = false;
62
63 if (derivative.isZero()) {
64 monIncr = true;
65 monDecr = true;
66 } else if (derivative.isConstant()) {
67 monIncr = derivative.constantPart() >= 0;
68 monDecr = derivative.constantPart() <= 0;
69 } else {
70 std::shared_ptr<utility::solver::SmtSolverFactory> smtSolverFactory = std::make_shared<utility::solver::MathsatSmtSolverFactory>();
71 std::shared_ptr<expressions::ExpressionManager> manager(new expressions::ExpressionManager());
72 solver::Z3SmtSolver s(*manager);
73 std::set<VariableType> variables = derivative.gatherVariables();
74
75 expressions::Expression exprBounds = manager->boolean(true);
76 for (auto variable : variables) {
77 auto managerVariable = manager->declareRationalVariable(variable.name());
80 exprBounds = exprBounds && manager->rational(lb) < managerVariable && managerVariable < manager->rational(ub);
81 }
82
84
85 // < 0, so not monotone increasing. If this is unsat, then it should be monotone increasing.
86 expressions::Expression exprToCheck = converter.toExpression(derivative) < manager->rational(0);
87 s.add(exprBounds);
88 s.add(exprToCheck);
90
91 // > 0, so not monotone decreasing. If this is unsat it should be monotone decreasing.
92 exprToCheck = converter.toExpression(derivative) > manager->rational(0);
93 s.reset();
94 s.add(exprBounds);
95 s.add(exprToCheck);
97 }
98 STORM_LOG_ASSERT(!(monIncr && monDecr) || derivative.isZero(), "Monotonicity both increasing and decreasing but derivative not zero.");
99
100 return std::pair<bool, bool>(monIncr, monDecr);
101 }
102
110 std::map<std::shared_ptr<Order>,
111 std::pair<std::shared_ptr<MonotonicityResult<VariableType>>, std::vector<std::shared_ptr<expressions::BinaryRelationExpression>>>>
112 checkMonotonicityInBuild(std::ostream& outfile, bool usePLA = false, std::string dotOutfileName = "dotOutput");
113
118 std::shared_ptr<LocalMonotonicityResult<VariableType>> createLocalMonotonicityResult(std::shared_ptr<Order> order,
120
121 private:
122 void createOrder();
123
124 void checkMonotonicityOnSamples(std::shared_ptr<models::sparse::Dtmc<ValueType>> model, uint_fast64_t numberOfSamples);
125
126 void checkMonotonicityOnSamples(std::shared_ptr<models::sparse::Mdp<ValueType>> model, uint_fast64_t numberOfSamples);
127
128 void extendOrderWithAssumptions(std::shared_ptr<Order> order, uint_fast64_t val1, uint_fast64_t val2,
129 std::vector<std::shared_ptr<expressions::BinaryRelationExpression>> assumptions,
130 std::shared_ptr<MonotonicityResult<VariableType>> monRes);
131
132 std::shared_ptr<models::ModelBase> model;
133
134 std::vector<std::shared_ptr<logic::Formula const>> formulas;
135
136 bool dotOutput;
137
138 bool checkSamples;
139
140 bool onlyCheckOnOrder;
141
142 MonotonicityResult<VariableType> resultCheckOnSamples;
143
144 std::map<VariableType, std::vector<uint_fast64_t>> occuringStatesAtVariable;
145
146 std::map<std::shared_ptr<Order>,
147 std::pair<std::shared_ptr<MonotonicityResult<VariableType>>, std::vector<std::shared_ptr<expressions::BinaryRelationExpression>>>>
148 monResults;
149
151
152 ConstantType precision;
153
154 Region region;
155
157
158 std::unordered_map<ValueType, std::unordered_map<VariableType, ValueType>> derivatives;
159
161};
162} // namespace analysis
163} // namespace storm
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
MonotonicityHelper(std::shared_ptr< models::sparse::Model< ValueType > > model, std::vector< std::shared_ptr< logic::Formula const > > formulas, std::vector< storage::ParameterRegion< ValueType > > regions, uint_fast64_t numberOfSamples=0, double const &precision=0.000001, bool dotOutput=false)
Constructor of MonotonicityHelper.
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.
storm::analysis::MonotonicityKind Monotonicity
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:30
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.
#define STORM_LOG_ASSERT(cond, message)
Definition macros.h:9
TargetType convertNumber(SourceType const &number)