Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
monotonicity.cpp
Go to the documentation of this file.
2
8
12
14
16#include "storm/api/storm.h"
17
21
23
25
26#include "storm/io/file.h"
31
32namespace storm::pars {
33template<typename ValueType>
35 std::vector<storm::storage::ParameterRegion<ValueType>> const& regions) {
36 std::ofstream outfile;
38
39 if (monSettings.isExportMonotonicitySet()) {
40 storm::io::openFile(monSettings.getExportMonotonicityFilename(), outfile);
41 }
42 std::vector<std::shared_ptr<storm::logic::Formula const>> formulas = storm::api::extractFormulasFromProperties(input.properties);
43 storm::utility::Stopwatch monotonicityWatch(true);
44 STORM_LOG_THROW(regions.size() <= 1, storm::exceptions::InvalidArgumentException, "Monotonicity analysis only allowed on single region");
45 if (!monSettings.isMonSolutionSet()) {
47 model, formulas, regions, monSettings.getNumberOfSamples(), storm::settings::getModule<storm::settings::modules::GeneralSettings>().getPrecision(),
48 monSettings.isDotOutputSet());
49 if (monSettings.isExportMonotonicitySet()) {
50 monotonicityHelper.checkMonotonicityInBuild(outfile, monSettings.isUsePLABoundsSet(), monSettings.getDotOutputFilename());
51 } else {
52 monotonicityHelper.checkMonotonicityInBuild(std::cout, monSettings.isUsePLABoundsSet(), monSettings.getDotOutputFilename());
53 }
54 } else {
55 // Checking monotonicity based on solution function
56
59
60 std::function<std::unique_ptr<storm::modelchecker::CheckResult>(std::shared_ptr<storm::logic::Formula const> const& formula)> verificationCallback;
61 std::function<void(std::unique_ptr<storm::modelchecker::CheckResult> const&)> postprocessingCallback;
62
63 // Check the given set of regions with or without refinement
64 verificationCallback = [&](std::shared_ptr<storm::logic::Formula const> const& formula) {
65 std::unique_ptr<storm::modelchecker::CheckResult> result =
66 storm::api::verifyWithSparseEngine<ValueType>(model, storm::api::createTask<ValueType>(formula, true));
67 return result;
68 };
69
70 for (auto& property : input.properties) {
71 auto result = verificationCallback(property.getRawFormula())->asExplicitQuantitativeCheckResult<ValueType>().getValueVector();
72 ValueType valuation;
73
74 auto states = model->getInitialStates();
75 for (auto state : states) {
76 valuation += result[state];
77 }
78
80 for (auto& var : storm::models::sparse::getProbabilityParameters(*model)) {
81 auto res = storm::analysis::MonotonicityChecker<ValueType>::checkDerivative(valuation.derivative(var), regions[0]);
82
83 if (res.first && res.second) {
85 } else if (res.first) {
87 } else if (res.second) {
89 } else {
91 }
92 }
93 if (monSettings.isExportMonotonicitySet()) {
94 outfile << monRes.toString();
95 } else {
96 STORM_PRINT(monRes.toString());
97 }
98 }
99 }
100
101 if (monSettings.isExportMonotonicitySet()) {
102 storm::io::closeFile(outfile);
103 }
104
105 monotonicityWatch.stop();
106 STORM_PRINT("\nTotal time for monotonicity checking: " << monotonicityWatch << ".\n\n");
107 return;
108}
109
112} // namespace storm::pars
static std::pair< bool, bool > checkDerivative(ValueType const &derivative, storage::ParameterRegion< ValueType > const &reg)
Checks if a derivative >=0 or/and <=0.
void addMonotonicityResult(VariableType var, Monotonicity mon)
Adds a new variable with a given Monotonicity to the map.
std::string toString() const
Constructs a string output of all variables and their corresponding Monotonicity.
Base class for all sparse models.
Definition Model.h:33
A class that provides convenience operations to display run times.
Definition Stopwatch.h:14
void stop()
Stop stopwatch and add measured time to total time.
Definition Stopwatch.cpp:42
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:30
#define STORM_PRINT(message)
Define the macros that print information and optionally also log it.
Definition macros.h:62
std::vector< std::shared_ptr< storm::logic::Formula const > > extractFormulasFromProperties(std::vector< storm::jani::Property > const &properties)
void closeFile(std::ofstream &stream)
Close the given file after writing.
Definition file.h:47
void openFile(std::string const &filepath, std::ofstream &filestream, bool append=false, bool silent=false)
Open the given file for writing.
Definition file.h:18
std::set< storm::RationalFunctionVariable > getProbabilityParameters(Model< storm::RationalFunction > const &model)
Get all probability parameters occurring on transitions.
Definition Model.cpp:703
void analyzeMonotonicity(std::shared_ptr< storm::models::sparse::Model< ValueType > > const &model, cli::SymbolicInput const &input, std::vector< storm::storage::ParameterRegion< ValueType > > const &regions)
SettingsType const & getModule()
Get module.
std::vector< storm::jani::Property > properties