29namespace bisimulation {
31template<storm::dd::DdType DdType,
typename ValueType>
36template<storm::dd::DdType DdType,
typename ValueType>
38 std::pair<storm::expressions::Variable, storm::expressions::Variable>
const& blockVariables, uint64_t numberOfBlocks,
40 : partition(partitionAdd),
41 changedStates(changedStates),
42 blockVariables(blockVariables),
43 numberOfBlocks(numberOfBlocks),
44 nextFreeBlockIndex(nextFreeBlockIndex) {
48template<storm::dd::DdType DdType,
typename ValueType>
50 std::pair<storm::expressions::Variable, storm::expressions::Variable>
const& blockVariables, uint64_t numberOfBlocks,
52 : partition(partitionBdd),
53 changedStates(changedStates),
54 blockVariables(blockVariables),
55 numberOfBlocks(numberOfBlocks),
56 nextFreeBlockIndex(nextFreeBlockIndex) {
60template<storm::dd::DdType DdType,
typename ValueType>
62 return this->partition == other.partition && this->blockVariables == other.blockVariables && this->numberOfBlocks == other.numberOfBlocks &&
63 this->nextFreeBlockIndex == other.nextFreeBlockIndex;
66template<storm::dd::DdType DdType,
typename ValueType>
68 uint64_t nextFreeBlockIndex,
73template<storm::dd::DdType DdType,
typename ValueType>
75 uint64_t nextFreeBlockIndex,
80template<storm::dd::DdType DdType,
typename ValueType>
81boost::optional<std::pair<std::shared_ptr<storm::logic::Formula const>, std::shared_ptr<storm::logic::Formula const>>>
83 boost::optional<std::pair<std::shared_ptr<storm::logic::Formula const>, std::shared_ptr<storm::logic::Formula const>>> result;
92 result = std::pair<std::shared_ptr<storm::logic::Formula const>, std::shared_ptr<storm::logic::Formula const>>();
100 result = std::pair<std::shared_ptr<storm::logic::Formula const>, std::shared_ptr<storm::logic::Formula const>>();
101 result.get().first = std::make_shared<storm::logic::BooleanLiteralFormula>(
true);
108template<storm::dd::DdType DdType,
typename ValueType>
111 std::vector<std::shared_ptr<storm::logic::Formula const>>
const& formulas) {
114 boost::optional<std::pair<std::shared_ptr<storm::logic::Formula const>, std::shared_ptr<storm::logic::Formula const>>> constraintTargetFormulas;
116 constraintTargetFormulas = extractConstraintTargetFormulas(*formulas.front());
120 return createDistanceBased(model, *constraintTargetFormulas.get().first, *constraintTargetFormulas.get().second);
126template<storm::dd::DdType DdType,
typename ValueType>
130 std::vector<storm::expressions::Expression> expressionVector;
131 for (
auto const& expression : preservationInformation.
getExpressions()) {
132 expressionVector.emplace_back(expression);
135 return create(model, expressionVector, bisimulationType);
138template<storm::dd::DdType DdType,
typename ValueType>
144 std::unique_ptr<storm::modelchecker::CheckResult> subresult = propositionalChecker.check(constraintFormula);
146 subresult = propositionalChecker.check(targetFormula);
149 return createDistanceBased(model, constraintStates, targetStates);
152template<storm::dd::DdType DdType,
typename ValueType>
158 std::pair<storm::expressions::Variable, storm::expressions::Variable> blockVariables = createBlockVariables(model);
160 auto start = std::chrono::high_resolution_clock::now();
167 uint64_t blockCount = 0;
171 while (!backwardFrontier.
isZero()) {
172 partitionBdd |= backwardFrontier && manager.getEncoding(blockVariables.first, blockCount++,
false);
173 coveredStates |= backwardFrontier;
175 !coveredStates && constraintStates;
180 partitionBdd |= (model.
getReachableStates() && !coveredStates) && manager.getEncoding(blockVariables.first, blockCount++,
false);
186 auto end = std::chrono::high_resolution_clock::now();
187 STORM_LOG_INFO(
"Created distance and label-based initial partition in " << std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count()
192 return Partition<DdType, ValueType>(partitionBdd.template toAdd<ValueType>(), blockVariables, blockCount, blockCount);
194 return Partition<DdType, ValueType>(partitionBdd, blockVariables, blockCount, blockCount);
198template<storm::dd::DdType DdType,
typename ValueType>
199std::pair<storm::expressions::Variable, storm::expressions::Variable> Partition<DdType, ValueType>::createBlockVariables(
203 uint64_t numberOfDdVariables = 0;
204 for (
auto const& metaVariable : model.getRowVariables()) {
205 auto const& ddMetaVariable =
manager.getMetaVariable(metaVariable);
206 numberOfDdVariables += ddMetaVariable.getNumberOfDdVariables();
209 auto mdp = model.template as<storm::models::symbolic::Mdp<DdType, ValueType>>();
210 for (
auto const& metaVariable : mdp->getNondeterminismVariables()) {
211 auto const& ddMetaVariable =
manager.getMetaVariable(metaVariable);
212 numberOfDdVariables += ddMetaVariable.getNumberOfDdVariables();
216 return createBlockVariables(manager, numberOfDdVariables);
219template<storm::dd::DdType DdType,
typename ValueType>
221 std::vector<storm::expressions::Expression>
const& expressions,
224 "Currently only strong bisimulation is supported.");
226 std::pair<storm::expressions::Variable, storm::expressions::Variable> blockVariables = createBlockVariables(model);
228 std::vector<storm::dd::Bdd<DdType>> stateSets;
229 for (
auto const& expression : expressions) {
230 stateSets.emplace_back(model.
getStates(expression));
232 auto start = std::chrono::high_resolution_clock::now();
233 std::pair<storm::dd::Bdd<DdType>, uint64_t> partitionBddAndBlockCount = createPartitionBdd(model.
getManager(), model, stateSets, blockVariables.first);
234 auto end = std::chrono::high_resolution_clock::now();
235 STORM_LOG_INFO(
"Created label-based initial partition in " << std::chrono::duration_cast<std::chrono::milliseconds>(end - start).
count() <<
"ms.");
239 return Partition<DdType, ValueType>(partitionBddAndBlockCount.first.template toAdd<ValueType>(), blockVariables, partitionBddAndBlockCount.second,
240 partitionBddAndBlockCount.second);
242 return Partition<DdType, ValueType>(partitionBddAndBlockCount.first, blockVariables, partitionBddAndBlockCount.second,
243 partitionBddAndBlockCount.second);
247template<storm::dd::DdType DdType,
typename ValueType>
250 std::pair<storm::expressions::Variable, storm::expressions::Variable>
const& blockVariables) {
262template<storm::dd::DdType DdType,
typename ValueType>
264 return this->getStates().getNonZeroCount();
267template<storm::dd::DdType DdType,
typename ValueType>
269 if (this->storedAsAdd()) {
270 return this->asAdd().notZero().
existsAbstract({this->getBlockVariable()});
272 return this->asBdd().existsAbstract({this->getBlockVariable()});
276template<storm::dd::DdType DdType,
typename ValueType>
278 return static_cast<bool>(changedStates);
281template<storm::dd::DdType DdType,
typename ValueType>
283 return boost::get<storm::dd::Add<DdType, ValueType>>(changedStates.get());
286template<storm::dd::DdType DdType,
typename ValueType>
288 return boost::get<storm::dd::Bdd<DdType>>(changedStates.get());
291template<storm::dd::DdType DdType,
typename ValueType>
293 return numberOfBlocks;
296template<storm::dd::DdType DdType,
typename ValueType>
298 return partition.which() == 1;
301template<storm::dd::DdType DdType,
typename ValueType>
303 return partition.which() == 0;
306template<storm::dd::DdType DdType,
typename ValueType>
308 return boost::get<storm::dd::Add<DdType, ValueType>>(partition);
311template<storm::dd::DdType DdType,
typename ValueType>
313 return boost::get<storm::dd::Bdd<DdType>>(partition);
316template<storm::dd::DdType DdType,
typename ValueType>
318 return blockVariables;
321template<storm::dd::DdType DdType,
typename ValueType>
323 return blockVariables.first;
326template<storm::dd::DdType DdType,
typename ValueType>
328 return blockVariables.second;
331template<storm::dd::DdType DdType,
typename ValueType>
333 return nextFreeBlockIndex;
336template<storm::dd::DdType DdType,
typename ValueType>
338 if (this->storedAsBdd()) {
339 return asBdd().getNodeCount();
341 return asAdd().getNodeCount();
345template<storm::dd::DdType DdType>
348 if (currentStateSet.
isZero()) {
351 if (offset == stateSets.size()) {
352 callback(currentStateSet);
354 enumerateBlocksRec(stateSets, currentStateSet && stateSets[offset], offset + 1, blockVariable, callback);
355 enumerateBlocksRec(stateSets, currentStateSet && !stateSets[offset], offset + 1, blockVariable, callback);
359template<storm::dd::DdType DdType,
typename ValueType>
364 uint64_t blockCount = 0;
370 partitionBdd |= (stateSet && manager.getEncoding(blockVariable, blockCount, false));
377 return std::make_pair(partitionBdd, blockCount);
380template<storm::dd::DdType DdType,
typename ValueType>
381std::pair<storm::expressions::Variable, storm::expressions::Variable> Partition<DdType, ValueType>::createBlockVariables(
storm::dd::DdManager<DdType>& manager,
382 uint64_t numberOfDdVariables) {
383 std::vector<storm::expressions::Variable> blockVariables;
384 if (manager.hasMetaVariable(
"blocks")) {
386 while (manager.hasMetaVariable(
"block" + std::to_string(counter))) {
389 blockVariables = manager.addBitVectorMetaVariable(
"blocks" + std::to_string(counter), numberOfDdVariables, 2);
391 blockVariables =
manager.addBitVectorMetaVariable(
"blocks", numberOfDdVariables, 2);
393 return std::make_pair(blockVariables[0], blockVariables[1]);
396template class Partition<storm::dd::DdType::CUDD, double>;
398template class Partition<storm::dd::DdType::Sylvan, double>;
399template class Partition<storm::dd::DdType::Sylvan, storm::RationalNumber>;
400template class Partition<storm::dd::DdType::Sylvan, storm::RationalFunction>;
Bdd< LibraryType > notZero() const
Computes a BDD that represents the function in which all assignments with a function value unequal to...
Bdd< LibraryType > existsAbstract(std::set< storm::expressions::Variable > const &metaVariables) const
Existentially abstracts from the given meta variables.
Bdd< LibraryType > inverseRelationalProduct(Bdd< LibraryType > const &relation, std::set< storm::expressions::Variable > const &rowMetaVariables, std::set< storm::expressions::Variable > const &columnMetaVariables) const
Computes the inverse relational product of the current BDD and the given BDD representing a relation.
bool isZero() const
Retrieves whether this DD represents the constant zero function.
Bdd< LibraryType > swapVariables(std::vector< std::pair< storm::expressions::Variable, storm::expressions::Variable > > const &metaVariablePairs) const
Swaps the given pairs of meta variables in the BDD.
static Partition createTrivialChoicePartition(storm::models::symbolic::NondeterministicModel< DdType, ValueType > const &model, std::pair< storm::expressions::Variable, storm::expressions::Variable > const &blockVariables)
storm::expressions::Variable const & getBlockVariable() const
bool hasChangedStates() const
Retrieves whether this partition has information about the states whose partition block assignment ch...
storm::dd::Bdd< DdType > const & asBdd() const
storm::expressions::Variable const & getPrimedBlockVariable() const
uint64_t getNumberOfBlocks() const
storm::dd::Bdd< DdType > getStates() const
bool operator==(Partition< DdType, ValueType > const &other) const
uint64_t getNextFreeBlockIndex() const
storm::dd::Add< DdType, ValueType > const & changedStatesAsAdd() const
Retrieves the DD representing the states whose partition block assignment changed.
uint64_t getNodeCount() const
static Partition create(storm::models::symbolic::Model< DdType, ValueType > const &model, storm::storage::BisimulationType const &bisimulationType, PreservationInformation< DdType, ValueType > const &preservationInformation)
std::pair< storm::expressions::Variable, storm::expressions::Variable > const & getBlockVariables() const
storm::dd::Bdd< DdType > const & changedStatesAsBdd() const
storm::dd::Add< DdType, ValueType > const & asAdd() const
uint64_t getNumberOfStates() const
Partition< DdType, ValueType > replacePartition(storm::dd::Add< DdType, ValueType > const &newPartitionAdd, uint64_t numberOfBlocks, uint64_t nextFreeBlockIndex, boost::optional< storm::dd::Add< DdType, ValueType > > const &changedStates=boost::none) const
virtual ModelType getType() const
Return the actual type of the model.
Base class for all symbolic models.
storm::dd::DdManager< Type > & getManager() const
Retrieves the manager responsible for the DDs that represent this model.
storm::dd::Add< Type, ValueType > const & getTransitionMatrix() const
Retrieves the matrix representing the transitions of the model.
std::set< storm::expressions::Variable > const & getColumnVariables() const
Retrieves the meta variables used to encode the columns of the transition matrix and the vector indic...
virtual std::set< storm::expressions::Variable > const & getNondeterminismVariables() const
Retrieves all meta variables used to encode the nondeterminism.
std::vector< std::pair< storm::expressions::Variable, storm::expressions::Variable > > const & getRowColumnMetaVariablePairs() const
Retrieves the pairs of row and column meta variables.
std::set< storm::expressions::Variable > const & getRowVariables() const
Retrieves the meta variables used to encode the rows of the transition matrix and the vector indices.
virtual storm::dd::Bdd< Type > getStates(std::string const &label) const
Returns the sets of states labeled with the given label.
storm::dd::Bdd< Type > const & getReachableStates() const
Retrieves the reachable states of the model.
Base class for all nondeterministic symbolic models.
storm::dd::Bdd< Type > const & getIllegalMask() const
Retrieves a BDD characterizing all illegal nondeterminism encodings in the model.
#define STORM_LOG_INFO(message)
#define STORM_LOG_TRACE(message)
#define STORM_LOG_THROW(cond, exception, message)
void enumerateBlocksRec(std::vector< storm::dd::Bdd< DdType > > const &stateSets, storm::dd::Bdd< DdType > const ¤tStateSet, uint64_t offset, storm::expressions::Variable const &blockVariable, std::function< void(storm::dd::Bdd< DdType > const &)> const &callback)
FragmentSpecification propositional()
std::pair< storm::RationalNumber, storm::RationalNumber > count(std::vector< storm::storage::BitVector > const &origSets, std::vector< storm::storage::BitVector > const &intersects, std::vector< storm::storage::BitVector > const &intersectsInfo, storm::RationalNumber val, bool plus, uint64_t remdepth)
SettingsType const & getModule()
Get module.
SettingsManager const & manager()
Retrieves the settings manager.