|
|
@ -2,102 +2,74 @@ |
|
|
|
#include "src/storage/expressions/SimpleValuation.h"
|
|
|
|
#include "src/exceptions/ExceptionMacros.h"
|
|
|
|
#include "src/exceptions/InvalidArgumentException.h"
|
|
|
|
#include "src/exceptions/InvalidAccessException.h"
|
|
|
|
|
|
|
|
namespace storm { |
|
|
|
namespace expressions { |
|
|
|
SimpleValuation::SimpleValuation() : booleanIdentifierToIndexMap(new std::unordered_map<std::string, uint_fast64_t>()), integerIdentifierToIndexMap(new std::unordered_map<std::string, uint_fast64_t>()), doubleIdentifierToIndexMap(new std::unordered_map<std::string, uint_fast64_t>()), booleanValues(), integerValues(), doubleValues() { |
|
|
|
// Intentionally left empty.
|
|
|
|
} |
|
|
|
|
|
|
|
bool SimpleValuation::operator==(SimpleValuation const& other) const { |
|
|
|
return this->booleanIdentifierToIndexMap.get() == other.booleanIdentifierToIndexMap.get() && this->integerIdentifierToIndexMap.get() == other.integerIdentifierToIndexMap.get() && this->doubleIdentifierToIndexMap.get() == other.doubleIdentifierToIndexMap.get() && this->booleanValues == other.booleanValues && this->integerValues == other.integerValues && this->doubleValues == other.doubleValues; |
|
|
|
return this->identifierToValueMap == other.identifierToValueMap; |
|
|
|
} |
|
|
|
|
|
|
|
void SimpleValuation::addBooleanIdentifier(std::string const& name, bool initialValue) { |
|
|
|
LOG_THROW(this->booleanIdentifierToIndexMap->find(name) == this->booleanIdentifierToIndexMap->end(), storm::exceptions::InvalidArgumentException, "Boolean identifier '" << name << "' already registered."); |
|
|
|
|
|
|
|
this->booleanIdentifierToIndexMap->emplace(name, this->booleanValues.size()); |
|
|
|
this->booleanValues.push_back(initialValue); |
|
|
|
LOG_THROW(this->identifierToValueMap.find(name) == this->identifierToValueMap.end(), storm::exceptions::InvalidArgumentException, "Identifier '" << name << "' already registered."); |
|
|
|
this->identifierToValueMap.emplace(name, initialValue); |
|
|
|
} |
|
|
|
|
|
|
|
void SimpleValuation::addIntegerIdentifier(std::string const& name, int_fast64_t initialValue) { |
|
|
|
LOG_THROW(this->booleanIdentifierToIndexMap->find(name) == this->booleanIdentifierToIndexMap->end(), storm::exceptions::InvalidArgumentException, "Integer identifier '" << name << "' already registered."); |
|
|
|
|
|
|
|
this->integerIdentifierToIndexMap->emplace(name, this->integerValues.size()); |
|
|
|
this->integerValues.push_back(initialValue); |
|
|
|
LOG_THROW(this->identifierToValueMap.find(name) == this->identifierToValueMap.end(), storm::exceptions::InvalidArgumentException, "Identifier '" << name << "' already registered."); |
|
|
|
this->identifierToValueMap.emplace(name, initialValue); |
|
|
|
} |
|
|
|
|
|
|
|
void SimpleValuation::addDoubleIdentifier(std::string const& name, double initialValue) { |
|
|
|
LOG_THROW(this->booleanIdentifierToIndexMap->find(name) == this->booleanIdentifierToIndexMap->end(), storm::exceptions::InvalidArgumentException, "Double identifier '" << name << "' already registered."); |
|
|
|
|
|
|
|
this->doubleIdentifierToIndexMap->emplace(name, this->doubleValues.size()); |
|
|
|
this->doubleValues.push_back(initialValue); |
|
|
|
LOG_THROW(this->identifierToValueMap.find(name) == this->identifierToValueMap.end(), storm::exceptions::InvalidArgumentException, "Identifier '" << name << "' already registered."); |
|
|
|
this->identifierToValueMap.emplace(name, initialValue); |
|
|
|
} |
|
|
|
|
|
|
|
void SimpleValuation::setBooleanValue(std::string const& name, bool value) { |
|
|
|
this->booleanValues[this->booleanIdentifierToIndexMap->at(name)] = value; |
|
|
|
this->identifierToValueMap[name] = value; |
|
|
|
} |
|
|
|
|
|
|
|
void SimpleValuation::setIntegerValue(std::string const& name, int_fast64_t value) { |
|
|
|
this->integerValues[this->integerIdentifierToIndexMap->at(name)] = value; |
|
|
|
this->identifierToValueMap[name] = value; |
|
|
|
} |
|
|
|
|
|
|
|
void SimpleValuation::setDoubleValue(std::string const& name, double value) { |
|
|
|
this->doubleValues[this->doubleIdentifierToIndexMap->at(name)] = value; |
|
|
|
this->identifierToValueMap[name] = value; |
|
|
|
} |
|
|
|
|
|
|
|
bool SimpleValuation::getBooleanValue(std::string const& name) const { |
|
|
|
auto const& nameIndexPair = this->booleanIdentifierToIndexMap->find(name); |
|
|
|
return this->booleanValues[nameIndexPair->second]; |
|
|
|
auto nameValuePair = this->identifierToValueMap.find(name); |
|
|
|
LOG_THROW(nameValuePair != this->identifierToValueMap.end(), storm::exceptions::InvalidAccessException, "Access to unkown identifier '" << name << "'."); |
|
|
|
return boost::get<bool>(nameValuePair->second); |
|
|
|
} |
|
|
|
|
|
|
|
int_fast64_t SimpleValuation::getIntegerValue(std::string const& name) const { |
|
|
|
auto const& nameIndexPair = this->integerIdentifierToIndexMap->find(name); |
|
|
|
return this->integerValues[nameIndexPair->second]; |
|
|
|
auto nameValuePair = this->identifierToValueMap.find(name); |
|
|
|
LOG_THROW(nameValuePair != this->identifierToValueMap.end(), storm::exceptions::InvalidAccessException, "Access to unkown identifier '" << name << "'."); |
|
|
|
return boost::get<int_fast64_t>(nameValuePair->second); |
|
|
|
} |
|
|
|
|
|
|
|
double SimpleValuation::getDoubleValue(std::string const& name) const { |
|
|
|
auto const& nameIndexPair = this->doubleIdentifierToIndexMap->find(name); |
|
|
|
return this->doubleValues[nameIndexPair->second]; |
|
|
|
auto nameValuePair = this->identifierToValueMap.find(name); |
|
|
|
LOG_THROW(nameValuePair != this->identifierToValueMap.end(), storm::exceptions::InvalidAccessException, "Access to unkown identifier '" << name << "'."); |
|
|
|
return boost::get<double>(nameValuePair->second); |
|
|
|
} |
|
|
|
|
|
|
|
std::ostream& operator<<(std::ostream& stream, SimpleValuation const& valuation) { |
|
|
|
stream << "valuation { bool ["; |
|
|
|
if (!valuation.booleanValues.empty()) { |
|
|
|
for (uint_fast64_t i = 0; i < valuation.booleanValues.size() - 1; ++i) { |
|
|
|
stream << valuation.booleanValues[i] << ", "; |
|
|
|
} |
|
|
|
stream << valuation.booleanValues.back(); |
|
|
|
} |
|
|
|
stream << "] int ["; |
|
|
|
if (!valuation.integerValues.empty()) { |
|
|
|
for (uint_fast64_t i = 0; i < valuation.integerValues.size() - 1; ++i) { |
|
|
|
stream << valuation.integerValues[i] << ", "; |
|
|
|
} |
|
|
|
stream << valuation.integerValues.back(); |
|
|
|
stream << "valuation { "; |
|
|
|
for (auto const& nameValuePair : valuation.identifierToValueMap) { |
|
|
|
stream << nameValuePair.first << ": " << nameValuePair.second << std::endl; |
|
|
|
} |
|
|
|
stream << "] double ["; |
|
|
|
if (!valuation.doubleValues.empty()) { |
|
|
|
for (uint_fast64_t i = 0; i < valuation.doubleValues.size() - 1; ++i) { |
|
|
|
stream << valuation.doubleValues[i] << ", "; |
|
|
|
} |
|
|
|
stream << valuation.doubleValues.back(); |
|
|
|
} |
|
|
|
stream << "] }"; |
|
|
|
stream << "}"; |
|
|
|
|
|
|
|
return stream; |
|
|
|
} |
|
|
|
|
|
|
|
std::size_t SimpleValuationPointerHash::operator()(SimpleValuation* valuation) const { |
|
|
|
size_t seed = 0; |
|
|
|
for (auto const& value : valuation->booleanValues) { |
|
|
|
boost::hash_combine<bool>(seed, value); |
|
|
|
} |
|
|
|
for (auto const& value : valuation->integerValues) { |
|
|
|
boost::hash_combine<int_fast64_t>(seed, value); |
|
|
|
} |
|
|
|
for (auto const& value : valuation->doubleValues) { |
|
|
|
boost::hash_combine<double>(seed, value); |
|
|
|
for (auto const& nameValuePair : valuation->identifierToValueMap) { |
|
|
|
boost::hash_combine(seed, nameValuePair.first); |
|
|
|
boost::hash_combine(seed, nameValuePair.second); |
|
|
|
} |
|
|
|
return seed; |
|
|
|
} |
|
|
@ -107,21 +79,7 @@ namespace storm { |
|
|
|
} |
|
|
|
|
|
|
|
bool SimpleValuationPointerLess::operator()(SimpleValuation* valuation1, SimpleValuation* valuation2) const { |
|
|
|
// Compare boolean variables.
|
|
|
|
bool less = valuation1->booleanValues < valuation2->booleanValues; |
|
|
|
if (less) { |
|
|
|
return true; |
|
|
|
} |
|
|
|
less = valuation1->integerValues < valuation2->integerValues; |
|
|
|
if (less) { |
|
|
|
return true; |
|
|
|
} |
|
|
|
less = valuation1->doubleValues < valuation2->doubleValues; |
|
|
|
if (less) { |
|
|
|
return true; |
|
|
|
} else { |
|
|
|
return false; |
|
|
|
} |
|
|
|
return valuation1->identifierToValueMap < valuation2->identifierToValueMap; |
|
|
|
} |
|
|
|
} |
|
|
|
} |