Browse Source

(DA) ItemLabeling: addUniqueLabel, generateUniqueLabel

For model-automaton product constructions, we would like to add
automatically generated labels to the result, so we need a way to
ensure that we can get those without clashing with existing labels.
tempestpy_adaptions
Joachim Klein 4 years ago
committed by Stefan Pranger
parent
commit
3696e13736
  1. 24
      src/storm/models/sparse/ItemLabeling.cpp
  2. 29
      src/storm/models/sparse/ItemLabeling.h

24
src/storm/models/sparse/ItemLabeling.cpp

@ -137,6 +137,18 @@ namespace storm {
labelings.emplace_back(std::move(labeling)); labelings.emplace_back(std::move(labeling));
} }
std::string ItemLabeling::addUniqueLabel(std::string const& prefix, storage::BitVector const& labeling) {
std::string label = generateUniqueLabel(prefix);
addLabel(label, labeling);
return label;
}
std::string ItemLabeling::addUniqueLabel(std::string const& prefix, storage::BitVector const&& labeling) {
std::string label = generateUniqueLabel(prefix);
addLabel(label, labeling);
return label;
}
bool ItemLabeling::containsLabel(std::string const& label) const { bool ItemLabeling::containsLabel(std::string const& label) const {
return nameToLabelingIndexMap.find(label) != nameToLabelingIndexMap.end(); return nameToLabelingIndexMap.find(label) != nameToLabelingIndexMap.end();
} }
@ -210,6 +222,18 @@ namespace storm {
return out; return out;
} }
std::string ItemLabeling::generateUniqueLabel(const std::string& prefix) const {
if (!containsLabel(prefix)) {
return prefix;
}
unsigned int i = 0;
std::string label;
do {
label = prefix + "_" + std::to_string(i);
} while (containsLabel(label));
return label;
}
} }
} }
} }

29
src/storm/models/sparse/ItemLabeling.h

@ -3,6 +3,7 @@
#include <unordered_map> #include <unordered_map>
#include <set> #include <set>
#include <string>
#include <ostream> #include <ostream>
@ -90,6 +91,28 @@ namespace storm {
*/ */
void addLabel(std::string const& label, storage::BitVector&& labeling); void addLabel(std::string const& label, storage::BitVector&& labeling);
/*!
* Creates a new label with a unique name, derived from the prefix,
* and attaches it to the given items. Note that the dimension of given labeling must
* match the number of items for which this item labeling is valid.
*
* @param prefix A prefix to use for the new label.
* @param labeling A bit vector that indicates whether or not the new label is attached to a item.
* @return the new label
*/
std::string addUniqueLabel(std::string const& prefix, storage::BitVector const& labeling);
/*!
* Creates a new label with a unique name, derived from the prefix,
* and attaches it to the given items. Note that the dimension of given labeling must
* match the number of items for which this item labeling is valid.
*
* @param prefix A prefix to use for the new label.
* @param labeling A bit vector that indicates whether or not the new label is attached to a item.
* @return the new label
*/
std::string addUniqueLabel(std::string const& prefix, storage::BitVector const&& labeling);
/*! /*!
* Adds all labels from the other labeling to this labeling. * Adds all labels from the other labeling to this labeling.
* It is assumed that both labelings have the same itemcount. * It is assumed that both labelings have the same itemcount.
@ -217,6 +240,12 @@ namespace storm {
// A vector that holds the labeling for all known labels. // A vector that holds the labeling for all known labels.
std::vector<storm::storage::BitVector> labelings; std::vector<storm::storage::BitVector> labelings;
/*!
* Generate a unique, previously unused label from the given prefix string.
*/
std::string generateUniqueLabel(const std::string& prefix) const;
}; };
} // namespace sparse } // namespace sparse

Loading…
Cancel
Save