3#include <boost/algorithm/string/join.hpp>
13 uint64_t
const numEntities)
15 umbValuations->resize(numEntities);
31 if (other.umbValuations) {
33 umbValuations = std::make_unique<ValuationsStorage>(*other.umbValuations);
39 if (other.umbValuations) {
41 umbValuations = std::make_unique<ValuationsStorage>(*other.umbValuations);
43 umbValuations.reset();
50 return umbValuations->getManager();
54 return *umbValuations;
57 return *umbValuations;
61 return umbValuations->
size();
65 return umbValuations->getAllVariables();
69 return umbValuations->entityHasVariable(entity, variable);
73 return umbValuations->readValue<
bool>(entity, booleanVariable);
80 std::optional<bool> result;
81 umbValuations->readCallback<std::nullopt_t,
bool>(entity, booleanVariable, [&result](
auto,
auto const&,
auto&& value) {
82 using T = std::remove_cvref_t<
decltype(value)>;
83 if constexpr (std::is_same_v<T, bool>) {
92 return umbValuations->readValue<int64_t>(entity, integerVariable);
99 std::optional<int64_t> result;
100 umbValuations->readCallback<std::nullopt_t, int64_t>(entity, integerVariable, [&result](
auto,
auto const&,
auto&& value) {
101 using T = std::remove_cvref_t<
decltype(value)>;
102 if constexpr (std::is_same_v<T, int64_t>) {
110 return umbValuations->readValue<
double>(entity, doubleVariable);
117 std::optional<double> result;
118 umbValuations->readCallback<std::nullopt_t,
double>(entity, doubleVariable, [&result](
auto,
auto const&,
auto&& value) {
119 using T = std::remove_cvref_t<
decltype(value)>;
120 if constexpr (std::is_same_v<T, double>) {
128 return umbValuations->readValue<storm::RationalNumber>(entity, rationalVariable);
135 std::optional<storm::RationalNumber> result;
136 umbValuations->readCallback<std::nullopt_t, storm::RationalNumber>(entity, rationalVariable, [&result](
auto,
auto const&,
auto&& value) {
137 using T = std::remove_cvref_t<
decltype(value)>;
138 if constexpr (std::is_same_v<T, storm::RationalNumber>) {
139 result = std::forward<decltype(value)>(value);
146 return umbValuations->readValue<std::string>(entity, stringVariable);
153 std::optional<std::string> result;
154 umbValuations->readCallback<std::nullopt_t, std::string>(entity, stringVariable, [&result](
auto,
auto const&,
auto&& value) {
155 using T = std::remove_cvref_t<
decltype(value)>;
156 if constexpr (std::is_same_v<T, std::string>) {
157 result = std::forward<decltype(value)>(value);
163template<
typename RationalValueType>
165 umbValuations->setValuesInEvaluator(entity, evaluator);
173 umbValuations->readCallback<
bool>(booleanVariable, [&result](
auto const entity,
auto,
bool value) {
183 std::vector<int64_t> result;
185 umbValuations->readCallback<int64_t>(integerVariable, [&result](
auto const entity,
auto, int64_t value) {
186 STORM_LOG_ASSERT(entity == result.size(),
"Entities processed in unexpected order.");
187 result.push_back(value);
194 std::vector<double> result;
196 umbValuations->readCallback<
double>(doubleVariable, [&result](
auto const entity,
auto,
double value) {
197 STORM_LOG_ASSERT(entity == result.size(),
"Entities processed in unexpected order.");
198 result.push_back(value);
205 std::vector<storm::RationalNumber> result;
207 umbValuations->readCallback<storm::RationalNumber>(rationalVariable, [&result](
auto const entity,
auto, storm::RationalNumber value) {
208 STORM_LOG_ASSERT(entity == result.size(),
"Entities processed in unexpected order.");
209 result.push_back(std::move(value));
216 std::vector<std::string> result;
218 umbValuations->readCallback<std::string>(stringVariable, [&result](
auto const entity,
auto, std::string&& value) {
219 STORM_LOG_ASSERT(entity == result.size(),
"Entities processed in unexpected order.");
220 result.push_back(std::move(value));
226 std::optional<std::set<storm::expressions::Variable>>
const& selectedVariables)
const {
227 std::vector<std::string> assignments;
228 umbValuations->readCallback(entity, [pretty, &selectedVariables, &assignments](
auto,
auto const& var,
auto&& value) {
229 if (selectedVariables && !selectedVariables->contains(var)) {
232 using ValueType = std::remove_cvref_t<
decltype(value)>;
233 if constexpr (std::is_same_v<ValueType, std::nullopt_t>) {
234 assignments.push_back(pretty ? (var.getName() +
"=none") :
"none");
235 }
else if constexpr (std::is_same_v<ValueType, bool>) {
237 assignments.push_back(value ?
"" :
"!" + var.getName());
239 assignments.push_back(value ?
"true" :
"false");
242 std::stringstream stream;
244 stream << var.getName() <<
"=";
247 assignments.push_back(stream.str());
250 return "[" + boost::join(assignments, pretty ?
"\t& " :
"\t") +
"]";
253template<
typename JsonRationalType>
256 umbValuations->readCallback<bool, uint64_t, int64_t, double, std::string>(entity, [&selectedVariables, &result](
auto,
auto const& var,
auto&& value) {
257 if (selectedVariables && !selectedVariables->contains(var)) {
260 result[var.getName()] = value;
266 return Valuations(umbValuations->selectEntities(selectedEntities));
270 return Valuations(umbValuations->selectEntities(selectedEntities));
274 return umbValuations->hash();
279 std::optional<std::set<storm::expressions::Variable>>
const&)
const;
This class is responsible for managing a set of typed variables and all expressions using these varia...
bool hasBooleanType() const
Checks whether the variable is of boolean type.
bool hasStringType() const
Checks whether the variable is of string type.
bool hasIntegerType() const
Checks whether the variable is of integral type.
bool hasRationalType() const
Checks whether the variable is of rational type.
std::string const & getName() const
Retrieves the name of the variable.
A bit vector that is internally represented as a vector of 64-bit values.
void set(uint64_t index, bool value=true)
Sets the given truth value at the given index.
Provides access to valuations of variables for a set of entities (e.g.
storm::RationalNumber getRationalValue(uint64_t const entity, storm::expressions::Variable const &rationalVariable) const
bool entityHasVariable(uint64_t entity, storm::expressions::Variable const &variable) const
Returns true iff the variable is relevant for the given entity.
void setValuesInEvaluator(uint64_t entity, storm::expressions::ExpressionEvaluator< RationalValueType > &evaluator) const
Reads the variable values for the given entity and sets them into the given expression evaluator.
double getDoubleValue(uint64_t const entity, storm::expressions::Variable const &doubleVariable) const
std::optional< bool > getOptionalBooleanValue(uint64_t const entity, storm::expressions::Variable const &booleanVariable) const
storm::storage::BitVector getBooleanValues(storm::expressions::Variable const &booleanVariable) const
Returns a vector of size getNumberOfEntities() such that the i'th entry is the value of the given var...
std::string toString(uint64_t const entity, bool const pretty=true, std::optional< std::set< storm::expressions::Variable > > const &selectedVariables={}) const
Returns a string representation of the valuation.
Valuations & operator=(Valuations &&other)
std::vector< int64_t > getInt64Values(storm::expressions::Variable const &integerVariable) const
Returns a vector of size getNumberOfEntities() such that the i'th entry is the value of the given var...
std::string getStringValue(uint64_t const entity, storm::expressions::Variable const &stringVariable) const
std::vector< std::string > getStringValues(storm::expressions::Variable const &stringVariable) const
Returns a vector of size getNumberOfEntities() such that the i'th entry is the value of the given var...
std::vector< storm::RationalNumber > getRationalValues(storm::expressions::Variable const &rationalVariable) const
Returns a vector of size getNumberOfEntities() such that the i'th entry is the value of the given var...
storm::json< JsonRationalType > toJson(uint64_t const entity, std::optional< std::set< storm::expressions::Variable > > const &selectedVariables={}) const
Returns a JSON representation of this valuation.
std::optional< storm::RationalNumber > getOptionalRationalValue(uint64_t const entity, storm::expressions::Variable const &rationalVariable) const
std::vector< double > getDoubleValues(storm::expressions::Variable const &doubleVariable) const
Returns a vector of size getNumberOfEntities() such that the i'th entry is the value of the given var...
uint64_t getNumberOfEntities() const
Valuations(ValuationClassDescription const valuationClassDescription, std::shared_ptr< storm::expressions::ExpressionManager const > const &manager={}, uint64_t const numEntities=0)
std::set< storm::expressions::Variable > getAllVariables() const
storm::expressions::ExpressionManager const & getManager() const
std::optional< double > getOptionalDoubleValue(uint64_t const entity, storm::expressions::Variable const &doubleVariable) const
bool getBooleanValue(uint64_t const entity, storm::expressions::Variable const &booleanVariable) const
int64_t getInt64Value(uint64_t const entity, storm::expressions::Variable const &integerVariable) const
Valuations selectEntities(storm::storage::BitVector const &selectedEntities) const
Derive new valuations from this by selecting the given entities.
ValuationsStorage const & getStorage() const
std::optional< int64_t > getOptionalInt64Value(uint64_t const entity, storm::expressions::Variable const &integerVariable) const
std::optional< std::string > getOptionalStringValue(uint64_t const entity, storm::expressions::Variable const &stringVariable) const
Stores valuations of variables for a set of entities (e.g.
#define STORM_LOG_ASSERT(cond, message)
nlohmann::basic_json< std::map, std::vector, std::string, bool, int64_t, uint64_t, ValueType > json
Describes the layout of a class of valuations (e.g.