3#include <boost/algorithm/string/join.hpp>
17template<
typename ValueType>
21 if (locationVariable.bitWidth != 0) {
22 evaluator.setIntegerValue(locationVariable.variable, state.
getAsInt(locationVariable.bitOffset, locationVariable.bitWidth));
24 evaluator.setIntegerValue(locationVariable.variable, 0);
28 evaluator.setBooleanValue(booleanVariable.variable, state.
get(booleanVariable.bitOffset));
31 evaluator.setIntegerValue(integerVariable.variable,
32 static_cast<int_fast64_t
>(state.
getAsInt(integerVariable.bitOffset, integerVariable.bitWidth)) + integerVariable.lowerBound);
40 if (locationVariable.bitWidth != 0) {
41 result.
setIntegerValue(locationVariable.variable, state.
getAsInt(locationVariable.bitOffset, locationVariable.bitWidth));
47 result.
setBooleanValue(booleanVariable.variable, state.
get(booleanVariable.bitOffset));
51 static_cast<int_fast64_t
>(state.
getAsInt(integerVariable.bitOffset, integerVariable.bitWidth)) + integerVariable.lowerBound);
60 result.
set(booleanVariable.bitOffset, valuation.
getBooleanValue(booleanVariable.variable));
63 int64_t assignedValue = valuation.
getIntegerValue(integerVariable.variable);
64 if (checkOutOfBounds) {
65 STORM_LOG_THROW(assignedValue >= integerVariable.lowerBound, storm::exceptions::InvalidArgumentException,
66 "The assignment leads to an out-of-bounds value (" << assignedValue <<
") for the variable '" << integerVariable.getName() <<
"'.");
67 STORM_LOG_THROW(assignedValue <= integerVariable.upperBound, storm::exceptions::InvalidArgumentException,
68 "The assignment leads to an out-of-bounds value (" << assignedValue <<
") for the variable '" << integerVariable.getName() <<
"'.");
70 result.
setFromInt(integerVariable.bitOffset, integerVariable.bitWidth, assignedValue - integerVariable.lowerBound);
72 static_cast<int_fast64_t
>(result.
getAsInt(integerVariable.bitOffset, integerVariable.bitWidth)) + integerVariable.lowerBound == assignedValue,
73 "Writing to the bit vector bucket failed (read " << result.
getAsInt(integerVariable.bitOffset, integerVariable.bitWidth) <<
" but wrote "
74 << assignedValue <<
").");
82template<UnpackStateIntoValuationsMode Mode>
87 "Valuation entity index " << entityIndex <<
" is out of bounds for valuations of size " << valuations.
size() <<
".");
89 "State size does not match the expected size based on the variable information.");
92 "Observation class size does not match the expected size based on the variable information.");
98 if (Mode ==
Observation && !locationVariable.observable) {
101 int64_t
const value = locationVariable.bitWidth != 0 ? entityEncoding.
getAsInt(locationVariable.bitOffset, locationVariable.bitWidth) : 0;
102 valuations.
writeValue(entityIndex, locationVariable.variable, value);
105 if (Mode ==
Observation && !booleanVariable.observable) {
108 valuations.
writeValue(entityIndex, booleanVariable.variable, entityEncoding.
get(booleanVariable.bitOffset));
111 if (Mode ==
Observation && !integerVariable.observable) {
114 int64_t
const value = entityEncoding.
getAsInt(integerVariable.bitOffset, integerVariable.bitWidth) + integerVariable.lowerBound;
115 valuations.
writeValue(entityIndex, integerVariable.variable, value);
120 STORM_LOG_ASSERT(observationLabel.deterministic,
"Only deterministic observation labels supported for unpacking into valuations.");
121 STORM_LOG_ASSERT(labelEncodingStart + 64 <= entityEncoding.
size(),
"Not enough bits left in the observation class encoding.");
122 int64_t
const labelValue = entityEncoding.
getAsInt(labelEncodingStart, 64);
123 valuations.
writeCallback<
false,
false, bool, int64_t>(entityIndex, observationLabel.variable,
124 [labelValue](
auto,
auto,
auto& value) { value = labelValue; });
143 std::vector<std::string> assignments;
145 assignments.push_back(locationVariable.variable.getName() +
"=");
146 assignments.back() += std::to_string(locationVariable.bitWidth == 0 ? 0 : state.
getAsInt(locationVariable.bitOffset, locationVariable.bitWidth));
149 if (!state.
get(booleanVariable.bitOffset)) {
150 assignments.push_back(
"!" + booleanVariable.variable.getName());
152 assignments.push_back(booleanVariable.variable.getName());
156 assignments.push_back(
157 integerVariable.variable.getName() +
"=" +
158 std::to_string(
static_cast<int_fast64_t
>(state.
getAsInt(integerVariable.bitOffset, integerVariable.bitWidth)) + integerVariable.lowerBound));
160 return boost::join(assignments,
" & ");
166 if (locationVariable.observable) {
167 for (uint64_t i = locationVariable.bitOffset; i < locationVariable.bitOffset + locationVariable.bitWidth; ++i) {
174 if (booleanVariable.observable) {
175 result.
set(booleanVariable.bitOffset,
true);
180 if (integerVariable.observable) {
181 for (uint64_t i = integerVariable.bitOffset; i < integerVariable.bitOffset + integerVariable.bitWidth; ++i) {
193 if (observationVector.
size() != 0) {
194 observeClass.
concat(observationVector);
197 auto it = observabilityMap.find(observeClass);
198 if (it != observabilityMap.end()) {
201 uint32_t newClassIndex = observabilityMap.size();
202 observabilityMap.emplace(observeClass, newClassIndex);
203 return newClassIndex;
207template<
typename ValueType>
211 if (onlyObservable && !locationVariable.observable) {
214 if (locationVariable.bitWidth != 0) {
215 result[locationVariable.variable.getName()] = state.
getAsInt(locationVariable.bitOffset, locationVariable.bitWidth);
217 result[locationVariable.variable.getName()] = 0;
221 if (onlyObservable && !booleanVariable.observable) {
224 result[booleanVariable.getName()] = state.
get(booleanVariable.bitOffset);
227 if (onlyObservable && !integerVariable.observable) {
230 STORM_LOG_ASSERT(integerVariable.bitWidth <= 63,
"Only integer variables with at most 63 bits are supported.");
231 result[integerVariable.getName()] =
232 static_cast<int64_t
>(state.
getAsInt(integerVariable.bitOffset, integerVariable.bitWidth)) + integerVariable.lowerBound;
245 std::map<storm::expressions::Variable, storm::expressions::Expression>
const& stateDescription,
bool checkOutOfBounds) {
249 for (
auto boolIt = varInfo.
booleanVariables.begin(); boolIt != boolItEnd; ++boolIt) {
250 STORM_LOG_THROW(stateDescription.count(boolIt->variable) > 0, storm::exceptions::InvalidArgumentException,
251 "Assignment for Boolean variable " << boolIt->getName() <<
" missing.");
252 result.
set(boolIt->bitOffset, stateDescription.at(boolIt->variable).evaluateAsBool());
257 for (
auto integerIt = varInfo.
integerVariables.begin(); integerIt != integerItEnd; ++integerIt) {
258 STORM_LOG_THROW(stateDescription.count(integerIt->variable) > 0, storm::exceptions::InvalidArgumentException,
259 "Assignment for Integer variable " << integerIt->getName() <<
" missing.");
261 int64_t assignedValue = stateDescription.at(integerIt->variable).evaluateAsInt();
262 if (checkOutOfBounds) {
263 STORM_LOG_THROW(assignedValue >= integerIt->lowerBound, storm::exceptions::InvalidArgumentException,
264 "The assignment leads to an out-of-bounds value (" << assignedValue <<
") for the variable '" << integerIt->getName() <<
"'.");
265 STORM_LOG_THROW(assignedValue <= integerIt->upperBound, storm::exceptions::InvalidArgumentException,
266 "The assignment leads to an out-of-bounds value (" << assignedValue <<
") for the variable '" << integerIt->getName() <<
"'.");
268 result.
setFromInt(integerIt->bitOffset, integerIt->bitWidth, assignedValue - integerIt->lowerBound);
269 STORM_LOG_ASSERT(
static_cast<int_fast64_t
>(result.
getAsInt(integerIt->bitOffset, integerIt->bitWidth)) + integerIt->lowerBound == assignedValue,
270 "Writing to the bit vector bucket failed (read " << result.
getAsInt(integerIt->bitOffset, integerIt->bitWidth) <<
" but wrote "
271 << assignedValue <<
").");
This class is responsible for managing a set of typed variables and all expressions using these varia...
A simple implementation of the valuation interface.
virtual void setIntegerValue(Variable const &integerVariable, int_fast64_t value) override
Sets the value of the given integer variable to the provided value.
virtual int_fast64_t getIntegerValue(Variable const &integerVariable) const override
Retrieves the value of the given integer variable.
virtual void setBooleanValue(Variable const &booleanVariable, bool value) override
Sets the value of the given boolean variable to the provided value.
virtual bool getBooleanValue(Variable const &booleanVariable) const override
Retrieves the value of the given boolean variable.
A bit vector that is internally represented as a vector of 64-bit values.
void setFromInt(uint64_t bitIndex, uint64_t numberOfBits, uint64_t value)
Sets the selected number of lowermost bits of the provided value at the given bit index.
void set(uint64_t index, bool value=true)
Sets the given truth value at the given index.
uint64_t getAsInt(uint64_t bitIndex, uint64_t numberOfBits) const
Retrieves the content of the current bit vector at the given index for the given number of bits as an...
size_t size() const
Retrieves the number of bits this bit vector can store.
bool get(uint64_t index) const
Retrieves the truth value of the bit at the given index and performs a bound check.
void concat(BitVector const &extension)
Concatenate this bitvector with another bitvector.
Stores valuations of variables for a set of entities (e.g.
void resize(uint64_t newEntityCount, uint64_t classIndex=0)
Resizes the entity count to newEntityCount.
void writeValue(uint64_t entity, storm::expressions::Variable const &variable, ValueType const &value)
Directly writes value to the given variable of entity.
void writeCallback(uint64_t entity, Callback const &callback)
Writes all variables of the given entity by invoking callback for each one.
#define STORM_LOG_ASSERT(cond, message)
#define STORM_LOG_THROW(cond, exception, message)
void unpackIntoValuations(CompressedState const &entityEncoding, uint64_t const entityIndex, VariableInformation const &variableInformation, storm::storage::sparse::ValuationsStorage &valuations)
UnpackStateIntoValuationsMode
template storm::json< double > unpackStateIntoJson< double >(CompressedState const &state, VariableInformation const &variableInformation, bool onlyObservable)
void unpackStateIntoEvaluator(CompressedState const &state, VariableInformation const &variableInformation, storm::expressions::ExpressionEvaluator< ValueType > &evaluator)
Unpacks the compressed state into the evaluator.
CompressedState createCompressedState(VariableInformation const &varInfo, std::map< storm::expressions::Variable, storm::expressions::Expression > const &stateDescription, bool checkOutOfBounds)
template storm::json< storm::RationalNumber > unpackStateIntoJson< storm::RationalNumber >(CompressedState const &state, VariableInformation const &variableInformation, bool onlyObservable)
template void unpackStateIntoEvaluator< storm::RationalFunction >(CompressedState const &state, VariableInformation const &variableInformation, storm::expressions::ExpressionEvaluator< storm::RationalFunction > &evaluator)
template void unpackStateIntoEvaluator< double >(CompressedState const &state, VariableInformation const &variableInformation, storm::expressions::ExpressionEvaluator< double > &evaluator)
template void unpackStateIntoEvaluator< storm::RationalNumber >(CompressedState const &state, VariableInformation const &variableInformation, storm::expressions::ExpressionEvaluator< storm::RationalNumber > &evaluator)
void unpackStateAppendToValuations(CompressedState const &state, VariableInformation const &variableInformation, storm::storage::sparse::ValuationsStorage &valuations)
Appends the values of the variables in the given state to the valuations object.
storm::expressions::SimpleValuation unpackStateIntoValuation(CompressedState const &state, VariableInformation const &variableInformation, storm::expressions::ExpressionManager const &manager)
Converts the compressed state into an explicit representation in the form of a valuation.
uint32_t unpackStateToObservabilityClass(CompressedState const &state, storm::storage::BitVector const &observationVector, std::unordered_map< storm::storage::BitVector, uint32_t > &observabilityMap, storm::storage::BitVector const &mask)
std::string toString(CompressedState const &state, VariableInformation const &variableInformation)
Returns a (human readable) string representation of the variable valuation encoded by the given state...
CompressedState createOutOfBoundsState(VariableInformation const &varInfo, bool roundTo64Bit)
CompressedState packStateFromValuation(expressions::SimpleValuation const &valuation, VariableInformation const &variableInformation, bool checkOutOfBounds)
storm::storage::BitVector CompressedState
template storm::json< storm::RationalFunction > unpackStateIntoJson< storm::RationalFunction >(CompressedState const &state, VariableInformation const &variableInformation, bool onlyObservable)
void unpackObservationClassIntoValuations(CompressedState const &observationClass, uint64_t const observationClassIndex, VariableInformation const &variableInformation, storm::storage::sparse::ValuationsStorage &valuations)
Sets the values of observable variables and observation expressions to the given observationClassInde...
storm::storage::BitVector computeObservabilityMask(VariableInformation const &variableInformation)
storm::json< ValueType > unpackStateIntoJson(CompressedState const &state, VariableInformation const &variableInformation, bool onlyObservable)
nlohmann::basic_json< std::map, std::vector, std::string, bool, int64_t, uint64_t, ValueType > json