16bool ItemLabeling::isStateLabeling()
const {
19bool ItemLabeling::isChoiceLabeling()
const {
43 for (
auto const& labelIndexPair : this->nameToLabelingIndexMap) {
47 if (labelings[labelIndexPair.second] != other.
getItems(labelIndexPair.first)) {
56 for (
auto const& labelIndexPair : nameToLabelingIndexMap) {
57 result.
addLabel(labelIndexPair.first, labelings[labelIndexPair.second] % items);
62void ItemLabeling::addLabel(std::string
const& label) {
66void ItemLabeling::removeLabel(std::string
const& label) {
67 auto labelIt = nameToLabelingIndexMap.find(label);
68 STORM_LOG_THROW(labelIt != nameToLabelingIndexMap.end(), storm::exceptions::InvalidArgumentException,
"Label '" << label <<
"' does not exist.");
69 uint64_t labelIndex = labelIt->second;
71 nameToLabelingIndexMap.erase(labelIt);
73 std::iter_swap(labelings.begin() + labelIndex, labelings.end() - 1);
77 for (
auto& it : nameToLabelingIndexMap) {
78 if (it.second == labelings.size()) {
79 it.second = labelIndex;
87 "The item count of the two labelings does not match: " << this->itemCount <<
" vs. " << other.
itemCount <<
".");
88 for (
auto const& label : other.
getLabels()) {
89 if (this->containsLabel(label)) {
90 this->setItems(label, this->getItems(label) | other.
getItems(label));
92 this->addLabel(label, other.
getItems(label));
97std::set<std::string> ItemLabeling::getLabels()
const {
98 std::set<std::string> result;
99 for (
auto const& labelIndexPair : this->nameToLabelingIndexMap) {
100 result.insert(labelIndexPair.first);
105std::set<std::string> ItemLabeling::getLabelsOfItem(uint64_t item)
const {
106 std::set<std::string> result;
107 for (
auto const& labelIndexPair : this->nameToLabelingIndexMap) {
108 if (this->getItemHasLabel(labelIndexPair.first, item)) {
109 result.insert(labelIndexPair.first);
115void ItemLabeling::permuteItems(std::vector<uint64_t>
const& inversePermutation) {
116 STORM_LOG_THROW(inversePermutation.size() == itemCount, storm::exceptions::InvalidArgumentException,
"Permutation does not match number of items");
117 std::vector<storm::storage::BitVector> newLabelings;
119 newLabelings.push_back(source.permute(inversePermutation));
122 this->labelings = newLabelings;
126 STORM_LOG_THROW(!this->containsLabel(label), storm::exceptions::InvalidArgumentException,
"Label '" << label <<
"' already exists.");
128 "Labeling vector has invalid size. Expected: " << itemCount <<
" Actual: " << labeling.
size());
129 nameToLabelingIndexMap.emplace(label, labelings.size());
130 labelings.push_back(labeling);
134 STORM_LOG_THROW(!this->containsLabel(label), storm::exceptions::InvalidArgumentException,
"Label '" << label <<
"' already exists.");
135 STORM_LOG_THROW(labeling.size() == itemCount, storm::exceptions::InvalidArgumentException,
136 "Labeling vector has invalid size. Expected: " << itemCount <<
" Actual: " << labeling.size());
137 nameToLabelingIndexMap.emplace(label, labelings.size());
138 labelings.emplace_back(std::move(labeling));
141std::string ItemLabeling::addUniqueLabel(std::string
const& prefix,
storage::BitVector const& labeling) {
142 std::string label = generateUniqueLabel(prefix);
143 addLabel(label, labeling);
147std::string ItemLabeling::addUniqueLabel(std::string
const& prefix,
storage::BitVector const&& labeling) {
148 std::string label = generateUniqueLabel(prefix);
149 addLabel(label, labeling);
153bool ItemLabeling::containsLabel(std::string
const& label)
const {
154 return nameToLabelingIndexMap.find(label) != nameToLabelingIndexMap.end();
157void ItemLabeling::addLabelToItem(std::string
const& label, uint64_t item) {
158 STORM_LOG_THROW(this->containsLabel(label), storm::exceptions::InvalidArgumentException,
"Label '" << label <<
"' unknown.");
159 STORM_LOG_THROW(item < itemCount, storm::exceptions::OutOfRangeException,
"Item index out of range.");
160 this->labelings[nameToLabelingIndexMap.at(label)].set(item,
true);
163void ItemLabeling::removeLabelFromItem(std::string
const& label, uint64_t item) {
164 STORM_LOG_THROW(item < itemCount, storm::exceptions::OutOfRangeException,
"Item index out of range.");
165 STORM_LOG_THROW(this->getItemHasLabel(label, item), storm::exceptions::InvalidArgumentException,
166 "Item " << item <<
" does not have label '" << label <<
"'.");
167 this->labelings[nameToLabelingIndexMap.at(label)].set(item,
false);
170bool ItemLabeling::getItemHasLabel(std::string
const& label, uint64_t item)
const {
171 STORM_LOG_THROW(this->containsLabel(label), storm::exceptions::InvalidArgumentException,
172 "The label '" << label <<
"' is invalid for the labeling of the model.");
173 return this->labelings[nameToLabelingIndexMap.at(label)].get(item);
176std::size_t ItemLabeling::getNumberOfLabels()
const {
177 return labelings.size();
180std::size_t ItemLabeling::getNumberOfItems()
const {
185 STORM_LOG_THROW(this->containsLabel(label), storm::exceptions::InvalidArgumentException,
186 "The label " << label <<
" is invalid for the labeling of the model.");
187 return this->labelings[nameToLabelingIndexMap.at(label)];
191 STORM_LOG_THROW(this->containsLabel(label), storm::exceptions::InvalidArgumentException,
192 "The label " << label <<
" is invalid for the labeling of the model.");
193 STORM_LOG_THROW(labeling.
size() == itemCount, storm::exceptions::InvalidArgumentException,
"Labeling vector has invalid size.");
194 this->labelings[nameToLabelingIndexMap.at(label)] = labeling;
198 STORM_LOG_THROW(this->containsLabel(label), storm::exceptions::InvalidArgumentException,
199 "The label " << label <<
" is invalid for the labeling of the model.");
200 STORM_LOG_THROW(labeling.size() == itemCount, storm::exceptions::InvalidArgumentException,
"Labeling vector has invalid size.");
201 this->labelings[nameToLabelingIndexMap.at(label)] = labeling;
204void ItemLabeling::printLabelingInformationToStream(std::ostream& out)
const {
205 out << this->getNumberOfLabels() <<
" labels\n";
206 for (
auto const& labelIndexPair : this->nameToLabelingIndexMap) {
207 out <<
" * " << labelIndexPair.first <<
" -> " << this->labelings[labelIndexPair.second].getNumberOfSetBits() <<
" item(s)\n";
211void ItemLabeling::printCompleteLabelingInformationToStream(std::ostream& out)
const {
212 out <<
"Labels: \t" << this->getNumberOfLabels() <<
'\n';
213 for (
auto label : nameToLabelingIndexMap) {
214 out <<
"Label '" << label.first <<
"': ";
215 for (
auto index : this->labelings[label.second]) {
222std::size_t ItemLabeling::hash()
const {
226std::ostream& operator<<(std::ostream& out,
ItemLabeling const& labeling) {
231std::string ItemLabeling::generateUniqueLabel(
const std::string& prefix)
const {
232 if (!containsLabel(prefix)) {
238 label = prefix +
"_" + std::to_string(i);
239 }
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.
uint64_t getNumberOfSetBits() const
Returns the number of bits that are set to true in this bit vector.
size_t size() const
Retrieves the number of bits this bit vector can store.
#define STORM_LOG_THROW(cond, exception, message)