Storm 1.11.1.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
bisimulation.h
Go to the documentation of this file.
1#pragma once
2
12
13namespace storm {
14namespace api {
15
16template<typename ModelType>
17std::shared_ptr<ModelType> performDeterministicSparseBisimulationMinimization(std::shared_ptr<ModelType> model,
18 std::vector<std::shared_ptr<storm::logic::Formula const>> const& formulas,
19 storm::storage::BisimulationType type, bool graphPreserving = true) {
21 if (!formulas.empty() && graphPreserving) {
23 }
24 // If we cannot use formula-based decomposition because of
25 // non-graph-preserving regions but there are reward models, we need to
26 // preserve those
27 if (!graphPreserving &&
28 std::any_of(formulas.begin(), formulas.end(), [](auto const& formula) { return formula->getReferencedRewardModels().size() > 0; })) {
29 options.setKeepRewards(true);
30 }
31 options.setType(type);
32
33 storm::storage::DeterministicModelBisimulationDecomposition<ModelType> bisimulationDecomposition(*model, options);
34 bisimulationDecomposition.computeBisimulationDecomposition();
35 return bisimulationDecomposition.getQuotient();
36}
37
38template<typename ModelType>
39std::shared_ptr<ModelType> performNondeterministicSparseBisimulationMinimization(std::shared_ptr<ModelType> model,
40 std::vector<std::shared_ptr<storm::logic::Formula const>> const& formulas,
41 storm::storage::BisimulationType type, bool graphPreserving = true) {
43 if (!formulas.empty() && graphPreserving) {
45 }
46 // If we cannot use formula-based decomposition because of
47 // non-graph-preserving regions but there are reward models, we need to
48 // preserve those
49 if (!graphPreserving &&
50 std::any_of(formulas.begin(), formulas.end(), [](auto const& formula) { return formula->getReferencedRewardModels().size() > 0; })) {
51 options.setKeepRewards(true);
52 }
53 options.setType(type);
54
56 bisimulationDecomposition.computeBisimulationDecomposition();
57 return bisimulationDecomposition.getQuotient();
58}
59
60template<typename ValueType>
61std::shared_ptr<storm::models::sparse::Model<ValueType>> performBisimulationMinimization(
62 std::shared_ptr<storm::models::sparse::Model<ValueType>> const& model, std::vector<std::shared_ptr<storm::logic::Formula const>> const& formulas,
65 model->isOfType(storm::models::ModelType::Dtmc) || model->isOfType(storm::models::ModelType::Ctmc) || model->isOfType(storm::models::ModelType::Mdp),
66 storm::exceptions::NotSupportedException, "Bisimulation minimization is currently only available for DTMCs, CTMCs and MDPs.");
67
68 // Try to get rid of non state-rewards to easy bisimulation computation.
69 model->reduceToStateBasedRewards();
70
71 if (model->isOfType(storm::models::ModelType::Dtmc)) {
72 return performDeterministicSparseBisimulationMinimization<storm::models::sparse::Dtmc<ValueType>>(
73 model->template as<storm::models::sparse::Dtmc<ValueType>>(), formulas, type, graphPreserving);
74 } else if (model->isOfType(storm::models::ModelType::Ctmc)) {
75 return performDeterministicSparseBisimulationMinimization<storm::models::sparse::Ctmc<ValueType>>(
76 model->template as<storm::models::sparse::Ctmc<ValueType>>(), formulas, type, graphPreserving);
77 } else {
78 return performNondeterministicSparseBisimulationMinimization<storm::models::sparse::Mdp<ValueType>>(
79 model->template as<storm::models::sparse::Mdp<ValueType>>(), formulas, type, graphPreserving);
80 }
81}
82
83template<storm::dd::DdType DdType, typename ValueType, typename ExportValueType = ValueType>
84typename std::enable_if<DdType == storm::dd::DdType::Sylvan || std::is_same<ValueType, double>::value,
85 std::shared_ptr<storm::models::Model<ExportValueType>>>::type
87 std::vector<std::shared_ptr<storm::logic::Formula const>> const& formulas,
93 storm::exceptions::NotSupportedException, "Symbolic bisimulation minimization is currently only available for DTMCs, CTMCs, MDPs and MAs.");
94 STORM_LOG_THROW(bisimulationType == storm::storage::BisimulationType::Strong, storm::exceptions::NotSupportedException,
95 "Currently only strong bisimulation is supported.");
96
97 std::shared_ptr<storm::models::Model<ExportValueType>> result;
98 model->getManager().execute([&]() {
99 // Try to get rid of non state-rewards to easy bisimulation computation.
100 model->reduceToStateBasedRewards();
101
102 storm::dd::BisimulationDecomposition<DdType, ValueType, ExportValueType> decomposition(*model, formulas, bisimulationType);
103 decomposition.compute(mode);
104 result = decomposition.getQuotient(quotientFormat);
105 });
106 return result;
107}
108
109template<storm::dd::DdType DdType, typename ValueType, typename ExportValueType = ValueType>
110typename std::enable_if<DdType != storm::dd::DdType::Sylvan && !std::is_same<ValueType, double>::value,
111 std::shared_ptr<storm::models::Model<ExportValueType>>>::type
113 std::vector<std::shared_ptr<storm::logic::Formula const>> const&,
117 STORM_LOG_THROW(false, storm::exceptions::NotSupportedException,
118 "Symbolic bisimulation minimization is not supported for this combination of DD library and value type.");
119 return nullptr;
120}
121
122} // namespace api
123} // 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:32
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:30
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::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::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)