Storm 1.14.0.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
bisimulation.h
Go to the documentation of this file.
1#pragma once
2
3#include <optional>
4
19
20namespace storm {
21namespace api {
22
23template<typename ModelType>
24std::shared_ptr<ModelType> performDeterministicSparseBisimulationMinimization(std::shared_ptr<ModelType> model,
25 std::vector<std::shared_ptr<storm::logic::Formula const>> const& formulas,
26 storm::storage::BisimulationType type, bool graphPreserving = true,
27 std::optional<double> const& tolerance = std::nullopt) {
28 using OptionsType = typename storm::storage::DeterministicModelBisimulationDecomposition<ModelType>::Options;
29 // Falls back to the general precision setting when the caller does not deliberately choose a tolerance;
30 // may be reworked to require an explicit choice throughout the API in the future.
31 typename ModelType::ValueType const resolvedTolerance = storm::NumberTraits<typename ModelType::ValueType>::IsExact
35 OptionsType options =
36 (!formulas.empty() && graphPreserving) ? OptionsType(*model, formulas, resolvedTolerance) : OptionsType::preservingAllLabels(resolvedTolerance);
37 // If we cannot use formula-based decomposition because of
38 // non-graph-preserving regions but there are reward models, we need to
39 // preserve those
40 if (!graphPreserving &&
41 std::any_of(formulas.begin(), formulas.end(), [](auto const& formula) { return formula->getReferencedRewardModels().size() > 0; })) {
42 options.setKeepRewards(true);
43 }
44 options.setType(type);
45
46 storm::storage::DeterministicModelBisimulationDecomposition<ModelType> bisimulationDecomposition(*model, options);
47 bisimulationDecomposition.computeBisimulationDecomposition();
48 return bisimulationDecomposition.getQuotient();
49}
50
51template<typename ModelType>
52std::shared_ptr<ModelType> performNondeterministicSparseBisimulationMinimization(std::shared_ptr<ModelType> model,
53 std::vector<std::shared_ptr<storm::logic::Formula const>> const& formulas,
54 storm::storage::BisimulationType type, bool graphPreserving = true,
55 std::optional<double> const& tolerance = std::nullopt) {
56 using OptionsType = typename storm::storage::NondeterministicModelBisimulationDecomposition<ModelType>::Options;
57 // Falls back to the general precision setting when the caller does not deliberately choose a tolerance;
58 // may be reworked to require an explicit choice throughout the API in the future.
59 typename ModelType::ValueType const resolvedTolerance = storm::NumberTraits<typename ModelType::ValueType>::IsExact
63 OptionsType options =
64 (!formulas.empty() && graphPreserving) ? OptionsType(*model, formulas, resolvedTolerance) : OptionsType::preservingAllLabels(resolvedTolerance);
65 // If we cannot use formula-based decomposition because of
66 // non-graph-preserving regions but there are reward models, we need to
67 // preserve those
68 if (!graphPreserving &&
69 std::any_of(formulas.begin(), formulas.end(), [](auto const& formula) { return formula->getReferencedRewardModels().size() > 0; })) {
70 options.setKeepRewards(true);
71 }
72 options.setType(type);
73
75 bisimulationDecomposition.computeBisimulationDecomposition();
76 return bisimulationDecomposition.getQuotient();
77}
78
79template<typename ValueType>
80std::shared_ptr<storm::models::sparse::Model<ValueType>> performBisimulationMinimization(
81 std::shared_ptr<storm::models::sparse::Model<ValueType>> const& model, std::vector<std::shared_ptr<storm::logic::Formula const>> const& formulas,
83 std::optional<double> const& tolerance = std::nullopt) {
85 model->isOfType(storm::models::ModelType::Dtmc) || model->isOfType(storm::models::ModelType::Ctmc) || model->isOfType(storm::models::ModelType::Mdp),
86 storm::exceptions::NotSupportedException, "Bisimulation minimization is currently only available for DTMCs, CTMCs and MDPs.");
87
88 // Try to get rid of non state-rewards to easy bisimulation computation.
89 model->reduceToStateBasedRewards();
90
91 if (model->isOfType(storm::models::ModelType::Dtmc)) {
93 model->template as<storm::models::sparse::Dtmc<ValueType>>(), formulas, type, graphPreserving, tolerance);
94 } else if (model->isOfType(storm::models::ModelType::Ctmc)) {
96 model->template as<storm::models::sparse::Ctmc<ValueType>>(), formulas, type, graphPreserving, tolerance);
97 } else {
99 model->template as<storm::models::sparse::Mdp<ValueType>>(), formulas, type, graphPreserving, tolerance);
100 }
101}
102
103template<storm::dd::DdType DdType, typename ValueType, typename ExportValueType = ValueType>
104typename std::enable_if<DdType == storm::dd::DdType::Sylvan || std::is_same<ValueType, double>::value,
105 std::shared_ptr<storm::models::Model<ExportValueType>>>::type
107 std::vector<std::shared_ptr<storm::logic::Formula const>> const& formulas,
114 storm::exceptions::NotSupportedException, "Symbolic bisimulation minimization is currently only available for DTMCs, CTMCs, MDPs and MAs.");
115 STORM_LOG_THROW(bisimulationType == storm::storage::BisimulationType::Strong, storm::exceptions::NotSupportedException,
116 "Currently only strong bisimulation is supported.");
117
118 std::shared_ptr<storm::models::Model<ExportValueType>> result;
119 model->getManager().execute([&]() {
120 // Try to get rid of non state-rewards to easy bisimulation computation.
121 model->reduceToStateBasedRewards();
122
123 storm::dd::BisimulationDecomposition<DdType, ValueType, ExportValueType> decomposition(*model, formulas, bisimulationType, bisimulationOptions);
124 decomposition.compute(mode);
125 result = decomposition.getQuotient(quotientFormat);
126 });
127 return result;
128}
129
130template<storm::dd::DdType DdType, typename ValueType, typename ExportValueType = ValueType>
131typename std::enable_if<DdType != storm::dd::DdType::Sylvan && !std::is_same<ValueType, double>::value,
132 std::shared_ptr<storm::models::Model<ExportValueType>>>::type
134 std::vector<std::shared_ptr<storm::logic::Formula const>> const&,
139 STORM_LOG_THROW(false, storm::exceptions::NotSupportedException,
140 "Symbolic bisimulation minimization is not supported for this combination of DD library and value type.");
141 return nullptr;
142}
143
144} // namespace api
145} // namespace storm
void compute(bisimulation::SignatureMode const &mode=bisimulation::SignatureMode::Eager)
Performs partition refinement until a fixpoint has been reached.
std::shared_ptr< storm::models::Model< ExportValueType > > getQuotient(storm::dd::bisimulation::QuotientFormat const &quotientFormat) const
Retrieves the quotient model after the bisimulation decomposition was computed.
Base class for all sparse models.
Definition Model.h:30
Base class for all symbolic models.
Definition Model.h:42
std::shared_ptr< ModelType > getQuotient() const
Retrieves the quotient of the model under the computed bisimulation.
void computeBisimulationDecomposition()
Computes the decomposition of the model into bisimulation equivalence classes.
This class represents the decomposition of a deterministic model into its bisimulation quotient.
This class represents the decomposition of a nondeterministic model into its bisimulation quotient.
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:28
std::shared_ptr< storm::models::sparse::Model< ValueType > > performBisimulationMinimization(std::shared_ptr< storm::models::sparse::Model< ValueType > > const &model, std::vector< std::shared_ptr< storm::logic::Formula const > > const &formulas, storm::storage::BisimulationType type=storm::storage::BisimulationType::Strong, bool graphPreserving=true, std::optional< double > const &tolerance=std::nullopt)
std::shared_ptr< ModelType > performNondeterministicSparseBisimulationMinimization(std::shared_ptr< ModelType > model, std::vector< std::shared_ptr< storm::logic::Formula const > > const &formulas, storm::storage::BisimulationType type, bool graphPreserving=true, std::optional< double > const &tolerance=std::nullopt)
std::shared_ptr< ModelType > performDeterministicSparseBisimulationMinimization(std::shared_ptr< ModelType > model, std::vector< std::shared_ptr< storm::logic::Formula const > > const &formulas, storm::storage::BisimulationType type, bool graphPreserving=true, std::optional< double > const &tolerance=std::nullopt)
SettingsType const & getModule()
Get module.
ValueType zero()
Definition constants.cpp:24
TargetType convertNumber(SourceType const &number)
static const bool IsExact