Storm 1.14.0.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
monotonicity.cpp
Go to the documentation of this file.
2
9
13
15
17#include "storm/api/storm.h"
18
22
24
26
27#include "storm/io/file.h"
32
33namespace storm::pars {
34template<typename ValueType>
35void analyzeMonotonicity(storm::Environment const& env, std::shared_ptr<storm::models::sparse::Model<ValueType>> const& model, cli::SymbolicInput const& input,
36 std::vector<storm::storage::ParameterRegion<ValueType>> const& regions) {
37 std::ofstream outfile;
39
40 if (monSettings.isExportMonotonicitySet()) {
41 storm::io::openFile(monSettings.getExportMonotonicityFilename(), outfile);
42 }
43 std::vector<std::shared_ptr<storm::logic::Formula const>> formulas = storm::api::extractFormulasFromProperties(input.properties);
44 storm::utility::Stopwatch monotonicityWatch(true);
45 STORM_LOG_THROW(regions.size() <= 1, storm::exceptions::InvalidArgumentException, "Monotonicity analysis only allowed on single region.");
46 if (!monSettings.isMonSolutionSet()) {
48 env, model, formulas, regions, monSettings.getNumberOfSamples(),
49 storm::settings::getModule<storm::settings::modules::GeneralSettings>().getPrecision(), monSettings.isDotOutputSet());
50 if (monSettings.isExportMonotonicitySet()) {
51 monotonicityHelper.checkMonotonicityInBuild(outfile, monSettings.isUsePLABoundsSet(), monSettings.getDotOutputFilename());
52 } else {
53 monotonicityHelper.checkMonotonicityInBuild(std::cout, monSettings.isUsePLABoundsSet(), monSettings.getDotOutputFilename());
54 }
55 } else {
56 // Checking monotonicity based on solution function
57
60
61 bool const preferEliminationChecker = storm::cli::preferEliminationChecker();
62
63 std::function<std::unique_ptr<storm::modelchecker::CheckResult>(std::shared_ptr<storm::logic::Formula const> const& formula)> verificationCallback;
64 std::function<void(std::unique_ptr<storm::modelchecker::CheckResult> const&)> postprocessingCallback;
65
66 // Check the given set of regions with or without refinement
67 verificationCallback = [&](std::shared_ptr<storm::logic::Formula const> const& formula) {
68 std::unique_ptr<storm::modelchecker::CheckResult> result =
69 storm::api::verifyWithSparseEngine<ValueType>(env, model, storm::api::createTask<ValueType>(formula, true), preferEliminationChecker);
70 return result;
71 };
72
73 for (auto& property : input.properties) {
74 auto const checkResult = verificationCallback(property.getRawFormula());
75 auto const result = checkResult->asExplicitQuantitativeCheckResult<ValueType>().getFiniteValueVector();
76 ValueType valuation;
77
78 auto states = model->getInitialStates();
79 for (auto state : states) {
80 valuation += result[state];
81 }
82
84 for (auto& var : storm::models::sparse::getProbabilityParameters(*model)) {
85 auto res = storm::analysis::MonotonicityChecker<ValueType>::checkDerivative(valuation.derivative(var), regions[0]);
86
87 if (res.first && res.second) {
89 } else if (res.first) {
91 } else if (res.second) {
93 } else {
95 }
96 }
97 if (monSettings.isExportMonotonicitySet()) {
98 outfile << monRes.toString();
99 } else {
100 STORM_PRINT(monRes.toString());
101 }
102 }
103 }
104
105 if (monSettings.isExportMonotonicitySet()) {
106 storm::io::closeFile(outfile);
107 }
108
109 monotonicityWatch.stop();
110 STORM_PRINT("\nTotal time for monotonicity checking: " << monotonicityWatch << ".\n\n");
111}
112
114 cli::SymbolicInput const& input, std::vector<storm::storage::ParameterRegion<storm::RationalFunction>> const& regions);
115} // 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:34
A class that provides convenience operations to display run times.
Definition Stopwatch.h:13
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:39
storm::modelchecker::CheckTask< storm::logic::Formula, ValueType > createTask(std::shared_ptr< const storm::logic::Formula > const &formula, bool onlyInitialStatesRelevant=false)
std::vector< std::shared_ptr< storm::logic::Formula const > > extractFormulasFromProperties(std::vector< storm::jani::Property > const &properties)
std::unique_ptr< storm::modelchecker::CheckResult > verifyWithSparseEngine(storm::Environment const &env, std::shared_ptr< storm::models::sparse::Dtmc< ValueType > > const &dtmc, storm::modelchecker::CheckTask< storm::logic::Formula, ValueType > const &task, bool preferEliminationChecker=false)
bool preferEliminationChecker()
Returns whether the settings request to prefer the dedicated elimination model checker.
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:732
void analyzeMonotonicity(storm::Environment const &env, 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.
#define STORM_PRINT(message)
Define the macros that print information to stdout and optionally also log it.
Definition print.h:14
std::vector< storm::jani::Property > properties