17bool ItemLabeling::isStateLabeling()
const {
20bool ItemLabeling::isChoiceLabeling()
const {
44 for (
auto const& labelIndexPair : this->nameToLabelingIndexMap) {
48 if (labelings[labelIndexPair.second] != other.
getItems(labelIndexPair.first)) {
57 for (
auto const& labelIndexPair : nameToLabelingIndexMap) {
58 result.
addLabel(labelIndexPair.first, labelings[labelIndexPair.second] % items);
63void ItemLabeling::addLabel(std::string
const& label) {
67void ItemLabeling::removeLabel(std::string
const& label) {
68 auto labelIt = nameToLabelingIndexMap.find(label);
69 STORM_LOG_THROW(labelIt != nameToLabelingIndexMap.end(), storm::exceptions::InvalidArgumentException,
"Label '" << label <<
"' does not exist.");
70 uint64_t labelIndex = labelIt->second;
72 nameToLabelingIndexMap.erase(labelIt);
74 std::iter_swap(labelings.begin() + labelIndex, labelings.end() - 1);
78 for (
auto& it : nameToLabelingIndexMap) {
79 if (it.second == labelings.size()) {
80 it.second = labelIndex;
88 "The item count of the two labelings does not match: " << this->itemCount <<
" vs. " << other.
itemCount <<
".");
89 for (
auto const& label : other.
getLabels()) {
90 if (this->containsLabel(label)) {
91 this->setItems(label, this->getItems(label) | other.
getItems(label));
93 this->addLabel(label, other.
getItems(label));
98std::set<std::string> ItemLabeling::getLabels()
const {
99 std::set<std::string> result;
100 for (
auto const& labelIndexPair : this->nameToLabelingIndexMap) {
101 result.insert(labelIndexPair.first);
106std::set<std::string> ItemLabeling::getLabelsOfItem(uint64_t item)
const {
107 std::set<std::string> result;
108 for (
auto const& labelIndexPair : this->nameToLabelingIndexMap) {
109 if (this->getItemHasLabel(labelIndexPair.first, item)) {
110 result.insert(labelIndexPair.first);
116void ItemLabeling::permuteItems(std::vector<uint64_t>
const& inversePermutation) {
117 STORM_LOG_THROW(inversePermutation.size() == itemCount, storm::exceptions::InvalidArgumentException,
"Permutation does not match number of items");
118 std::vector<storm::storage::BitVector> newLabelings;
120 newLabelings.push_back(source.permute(inversePermutation));
123 this->labelings = newLabelings;
127 STORM_LOG_THROW(!this->containsLabel(label), storm::exceptions::InvalidArgumentException,
"Label '" << label <<
"' already exists.");
129 "Labeling vector has invalid size. Expected: " << itemCount <<
" Actual: " << labeling.
size());
130 nameToLabelingIndexMap.emplace(label, labelings.size());
131 labelings.push_back(labeling);
135 STORM_LOG_THROW(!this->containsLabel(label), storm::exceptions::InvalidArgumentException,
"Label '" << label <<
"' already exists.");
136 STORM_LOG_THROW(labeling.size() == itemCount, storm::exceptions::InvalidArgumentException,
137 "Labeling vector has invalid size. Expected: " << itemCount <<
" Actual: " << labeling.size());
138 nameToLabelingIndexMap.emplace(label, labelings.size());
139 labelings.emplace_back(std::move(labeling));
142std::string ItemLabeling::addUniqueLabel(std::string
const& prefix,
storage::BitVector const& labeling) {
143 std::string label = generateUniqueLabel(prefix);
144 addLabel(label, labeling);
148std::string ItemLabeling::addUniqueLabel(std::string
const& prefix,
storage::BitVector const&& labeling) {
149 std::string label = generateUniqueLabel(prefix);
150 addLabel(label, labeling);
154bool ItemLabeling::containsLabel(std::string
const& label)
const {
155 return nameToLabelingIndexMap.find(label) != nameToLabelingIndexMap.end();
158void ItemLabeling::addLabelToItem(std::string
const& label, uint64_t item) {
159 STORM_LOG_THROW(this->containsLabel(label), storm::exceptions::InvalidArgumentException,
"Label '" << label <<
"' unknown.");
160 STORM_LOG_THROW(item < itemCount, storm::exceptions::OutOfRangeException,
"Item index out of range.");
161 this->labelings[nameToLabelingIndexMap.at(label)].set(item,
true);
164void ItemLabeling::removeLabelFromItem(std::string
const& label, uint64_t item) {
165 STORM_LOG_THROW(item < itemCount, storm::exceptions::OutOfRangeException,
"Item index out of range.");
166 STORM_LOG_THROW(this->getItemHasLabel(label, item), storm::exceptions::InvalidArgumentException,
167 "Item " << item <<
" does not have label '" << label <<
"'.");
168 this->labelings[nameToLabelingIndexMap.at(label)].set(item,
false);
171bool ItemLabeling::getItemHasLabel(std::string
const& label, uint64_t item)
const {
172 STORM_LOG_THROW(this->containsLabel(label), storm::exceptions::InvalidArgumentException,
173 "The label '" << label <<
"' is invalid for the labeling of the model.");
174 return this->labelings[nameToLabelingIndexMap.at(label)].get(item);
177std::size_t ItemLabeling::getNumberOfLabels()
const {
178 return labelings.size();
181std::size_t ItemLabeling::getNumberOfItems()
const {
186 STORM_LOG_THROW(this->containsLabel(label), storm::exceptions::InvalidArgumentException,
187 "The label " << label <<
" is invalid for the labeling of the model.");
188 return this->labelings[nameToLabelingIndexMap.at(label)];
192 STORM_LOG_THROW(this->containsLabel(label), storm::exceptions::InvalidArgumentException,
193 "The label " << label <<
" is invalid for the labeling of the model.");
194 STORM_LOG_THROW(labeling.
size() == itemCount, storm::exceptions::InvalidArgumentException,
"Labeling vector has invalid size.");
195 this->labelings[nameToLabelingIndexMap.at(label)] = labeling;
199 STORM_LOG_THROW(this->containsLabel(label), storm::exceptions::InvalidArgumentException,
200 "The label " << label <<
" is invalid for the labeling of the model.");
201 STORM_LOG_THROW(labeling.size() == itemCount, storm::exceptions::InvalidArgumentException,
"Labeling vector has invalid size.");
202 this->labelings[nameToLabelingIndexMap.at(label)] = labeling;
205void ItemLabeling::printLabelingInformationToStream(std::ostream& out)
const {
206 out << this->getNumberOfLabels() <<
" labels\n";
207 for (
auto const& labelIndexPair : this->nameToLabelingIndexMap) {
208 out <<
" * " << labelIndexPair.first <<
" -> " << this->labelings[labelIndexPair.second].getNumberOfSetBits() <<
" item(s)\n";
212void ItemLabeling::printCompleteLabelingInformationToStream(std::ostream& out)
const {
213 out <<
"Labels: \t" << this->getNumberOfLabels() <<
'\n';
214 for (
auto label : nameToLabelingIndexMap) {
215 out <<
"Label '" << label.first <<
"': ";
216 for (
auto index : this->labelings[label.second]) {
223std::size_t ItemLabeling::hash()
const {
227std::ostream& operator<<(std::ostream& out,
ItemLabeling const& labeling) {
232std::string ItemLabeling::generateUniqueLabel(
const std::string& prefix)
const {
233 if (!containsLabel(prefix)) {
239 label = prefix +
"_" + std::to_string(i);
240 }
while (containsLabel(label));
This class manages the labeling of the choice space with a number of (atomic) labels.
A base class managing the labeling of items with a number of (atomic) labels.
std::set< std::string > getLabels() const
Retrieves the set of labels contained in this labeling.
ItemLabeling(uint64_t itemCount=0)
Constructs an empty labeling for the given number of items.
void addLabel(std::string const &label)
Adds a new label to the labelings.
bool containsLabel(std::string const &label) const
Checks whether a label is registered within this labeling.
virtual storm::storage::BitVector const & getItems(std::string const &label) const
Returns the labeling of items associated with the given label.
void printLabelingInformationToStream(std::ostream &out=std::cout) const
Prints information about the labeling to the specified stream.
std::size_t getNumberOfLabels() const
Returns the number of labels managed by this object.
This class manages the labeling of the state space with a number of (atomic) labels.
A bit vector that is internally represented as a vector of 64-bit values.
size_t size() const
Retrieves the number of bits this bit vector can store.
uint_fast64_t getNumberOfSetBits() const
Returns the number of bits that are set to true in this bit vector.
#define STORM_LOG_THROW(cond, exception, message)