7#include <boost/algorithm/string/join.hpp>
21template<
typename ValueType>
25 if (locationVariable.bitWidth != 0) {
26 evaluator.setIntegerValue(locationVariable.variable, state.
getAsInt(locationVariable.bitOffset, locationVariable.bitWidth));
28 evaluator.setIntegerValue(locationVariable.variable, 0);
32 evaluator.setBooleanValue(booleanVariable.variable, state.
get(booleanVariable.bitOffset));
35 evaluator.setIntegerValue(integerVariable.variable,
36 static_cast<int_fast64_t
>(state.
getAsInt(integerVariable.bitOffset, integerVariable.bitWidth)) + integerVariable.lowerBound);
45template<u
int64_t StackCapacity = 16>
46class StackedIndexVector {
48 explicit StackedIndexVector(uint64_t size) : heapData(size > StackCapacity ? size : 0, 0) {
49 data = size > StackCapacity ? std::span<uint64_t>(heapData) :
std::span<uint64_t>(stackData).subspan(0, size);
52 StackedIndexVector(StackedIndexVector
const&) =
delete;
53 StackedIndexVector(StackedIndexVector&&) =
delete;
54 StackedIndexVector& operator=(StackedIndexVector
const&) =
delete;
55 StackedIndexVector& operator=(StackedIndexVector&&) =
delete;
56 std::span<uint64_t> get() {
61 std::array<uint64_t, StackCapacity> stackData;
62 std::vector<uint64_t> heapData;
63 std::span<uint64_t> data;
67template<
typename ValueType>
72 StackedIndexVector<> differenceStorage(newState.
bucketCount());
73 std::span<uint64_t> difference = differenceStorage.get();
74 uint64_t anyDifference = 0;
75 for (uint64_t i = 0; i < difference.size(); ++i) {
77 anyDifference |= difference[i];
79 if (anyDifference == 0) {
84 auto differs = [difference](uint64_t bitOffset, uint64_t bitWidth) {
85 uint64_t
const firstBucket = bitOffset >> 6;
86 uint64_t
const offsetInBucket = bitOffset & 63;
87 uint64_t bits = difference[firstBucket] << offsetInBucket;
88 if (64 - offsetInBucket < bitWidth) {
89 bits |= difference[firstBucket + 1] >> (64 - offsetInBucket);
91 return (bits >> (64 - bitWidth)) != 0;
96 if (locationVariable.bitWidth != 0 && differs(locationVariable.bitOffset, locationVariable.bitWidth)) {
97 evaluator.setIntegerValue(locationVariable.variable, newState.
getAsInt(locationVariable.bitOffset, locationVariable.bitWidth));
101 if (differs(booleanVariable.bitOffset, 1)) {
102 evaluator.setBooleanValue(booleanVariable.variable, newState.
get(booleanVariable.bitOffset));
106 if (integerVariable.bitWidth != 0 && differs(integerVariable.bitOffset, integerVariable.bitWidth)) {
107 evaluator.setIntegerValue(
108 integerVariable.variable,
109 static_cast<int_fast64_t
>(newState.
getAsInt(integerVariable.bitOffset, integerVariable.bitWidth)) + integerVariable.lowerBound);
118 if (locationVariable.bitWidth != 0) {
119 result.
setIntegerValue(locationVariable.variable, state.
getAsInt(locationVariable.bitOffset, locationVariable.bitWidth));
125 result.
setBooleanValue(booleanVariable.variable, state.
get(booleanVariable.bitOffset));
129 static_cast<int_fast64_t
>(state.
getAsInt(integerVariable.bitOffset, integerVariable.bitWidth)) + integerVariable.lowerBound);
138 result.
set(booleanVariable.bitOffset, valuation.
getBooleanValue(booleanVariable.variable));
141 int64_t assignedValue = valuation.
getIntegerValue(integerVariable.variable);
142 if (checkOutOfBounds) {
143 STORM_LOG_THROW(assignedValue >= integerVariable.lowerBound, storm::exceptions::InvalidArgumentException,
144 "The assignment leads to an out-of-bounds value (" << assignedValue <<
") for the variable '" << integerVariable.getName() <<
"'.");
145 STORM_LOG_THROW(assignedValue <= integerVariable.upperBound, storm::exceptions::InvalidArgumentException,
146 "The assignment leads to an out-of-bounds value (" << assignedValue <<
") for the variable '" << integerVariable.getName() <<
"'.");
148 result.
setFromInt(integerVariable.bitOffset, integerVariable.bitWidth, assignedValue - integerVariable.lowerBound);
150 static_cast<int_fast64_t
>(result.
getAsInt(integerVariable.bitOffset, integerVariable.bitWidth)) + integerVariable.lowerBound == assignedValue,
151 "Writing to the bit vector bucket failed (read " << result.
getAsInt(integerVariable.bitOffset, integerVariable.bitWidth) <<
" but wrote "
152 << assignedValue <<
").");
160template<UnpackStateIntoValuationsMode Mode>
165 "Valuation entity index " << entityIndex <<
" is out of bounds for valuations of size " << valuations.
size() <<
".");
167 "State size does not match the expected size based on the variable information.");
170 "Observation class size does not match the expected size based on the variable information.");
176 if (Mode ==
Observation && !locationVariable.observable) {
179 int64_t
const value = locationVariable.bitWidth != 0 ? entityEncoding.
getAsInt(locationVariable.bitOffset, locationVariable.bitWidth) : 0;
180 valuations.
writeValue(entityIndex, locationVariable.variable, value);
183 if (Mode ==
Observation && !booleanVariable.observable) {
186 valuations.
writeValue(entityIndex, booleanVariable.variable, entityEncoding.
get(booleanVariable.bitOffset));
189 if (Mode ==
Observation && !integerVariable.observable) {
192 int64_t
const value = entityEncoding.
getAsInt(integerVariable.bitOffset, integerVariable.bitWidth) + integerVariable.lowerBound;
193 valuations.
writeValue(entityIndex, integerVariable.variable, value);
198 STORM_LOG_ASSERT(observationLabel.deterministic,
"Only deterministic observation labels supported for unpacking into valuations.");
199 STORM_LOG_ASSERT(labelEncodingStart + 64 <= entityEncoding.
size(),
"Not enough bits left in the observation class encoding.");
200 int64_t
const labelValue = entityEncoding.
getAsInt(labelEncodingStart, 64);
201 valuations.
writeCallback<
false,
false, bool, int64_t>(entityIndex, observationLabel.variable,
202 [labelValue](
auto,
auto,
auto& value) { value = labelValue; });
221 std::vector<std::string> assignments;
223 assignments.push_back(locationVariable.variable.getName() +
"=");
224 assignments.back() += std::to_string(locationVariable.bitWidth == 0 ? 0 : state.
getAsInt(locationVariable.bitOffset, locationVariable.bitWidth));
227 if (!state.
get(booleanVariable.bitOffset)) {
228 assignments.push_back(
"!" + booleanVariable.variable.getName());
230 assignments.push_back(booleanVariable.variable.getName());
234 assignments.push_back(
235 integerVariable.variable.getName() +
"=" +
236 std::to_string(
static_cast<int_fast64_t
>(state.
getAsInt(integerVariable.bitOffset, integerVariable.bitWidth)) + integerVariable.lowerBound));
238 return boost::join(assignments,
" & ");
244 if (locationVariable.observable) {
245 for (uint64_t i = locationVariable.bitOffset; i < locationVariable.bitOffset + locationVariable.bitWidth; ++i) {
252 if (booleanVariable.observable) {
253 result.
set(booleanVariable.bitOffset,
true);
258 if (integerVariable.observable) {
259 for (uint64_t i = integerVariable.bitOffset; i < integerVariable.bitOffset + integerVariable.bitWidth; ++i) {
271 if (observationVector.
size() != 0) {
272 observeClass.
concat(observationVector);
275 auto it = observabilityMap.find(observeClass);
276 if (it != observabilityMap.end()) {
279 uint32_t newClassIndex = observabilityMap.size();
280 observabilityMap.emplace(observeClass, newClassIndex);
281 return newClassIndex;
285template<
typename ValueType>
289 if (onlyObservable && !locationVariable.observable) {
292 if (locationVariable.bitWidth != 0) {
293 result[locationVariable.variable.getName()] = state.
getAsInt(locationVariable.bitOffset, locationVariable.bitWidth);
295 result[locationVariable.variable.getName()] = 0;
299 if (onlyObservable && !booleanVariable.observable) {
302 result[booleanVariable.getName()] = state.
get(booleanVariable.bitOffset);
305 if (onlyObservable && !integerVariable.observable) {
308 STORM_LOG_ASSERT(integerVariable.bitWidth <= 63,
"Only integer variables with at most 63 bits are supported.");
309 result[integerVariable.getName()] =
310 static_cast<int64_t
>(state.
getAsInt(integerVariable.bitOffset, integerVariable.bitWidth)) + integerVariable.lowerBound;
323 std::map<storm::expressions::Variable, storm::expressions::Expression>
const& stateDescription,
bool checkOutOfBounds) {
327 for (
auto boolIt = varInfo.
booleanVariables.begin(); boolIt != boolItEnd; ++boolIt) {
328 STORM_LOG_THROW(stateDescription.count(boolIt->variable) > 0, storm::exceptions::InvalidArgumentException,
329 "Assignment for Boolean variable " << boolIt->getName() <<
" missing.");
330 result.
set(boolIt->bitOffset, stateDescription.at(boolIt->variable).evaluateAsBool());
335 for (
auto integerIt = varInfo.
integerVariables.begin(); integerIt != integerItEnd; ++integerIt) {
336 STORM_LOG_THROW(stateDescription.count(integerIt->variable) > 0, storm::exceptions::InvalidArgumentException,
337 "Assignment for Integer variable " << integerIt->getName() <<
" missing.");
339 int64_t assignedValue = stateDescription.at(integerIt->variable).evaluateAsInt();
340 if (checkOutOfBounds) {
341 STORM_LOG_THROW(assignedValue >= integerIt->lowerBound, storm::exceptions::InvalidArgumentException,
342 "The assignment leads to an out-of-bounds value (" << assignedValue <<
") for the variable '" << integerIt->getName() <<
"'.");
343 STORM_LOG_THROW(assignedValue <= integerIt->upperBound, storm::exceptions::InvalidArgumentException,
344 "The assignment leads to an out-of-bounds value (" << assignedValue <<
") for the variable '" << integerIt->getName() <<
"'.");
346 result.
setFromInt(integerIt->bitOffset, integerIt->bitWidth, assignedValue - integerIt->lowerBound);
347 STORM_LOG_ASSERT(
static_cast<int_fast64_t
>(result.
getAsInt(integerIt->bitOffset, integerIt->bitWidth)) + integerIt->lowerBound == assignedValue,
348 "Writing to the bit vector bucket failed (read " << result.
getAsInt(integerIt->bitOffset, integerIt->bitWidth) <<
" but wrote "
349 << 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.
uint64_t getBucket(uint64_t bucketIndex) const
Gets the bits in the given bucket.
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.
size_t bucketCount() const
Retrieves the number of buckets of the underlying storage.
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.
template void unpackStateDifferenceIntoEvaluator< storm::RationalNumber >(CompressedState const &newState, CompressedState const &oldState, VariableInformation const &variableInformation, storm::expressions::ExpressionEvaluator< storm::RationalNumber > &evaluator)
template void unpackStateDifferenceIntoEvaluator< double >(CompressedState const &newState, CompressedState const &oldState, VariableInformation const &variableInformation, storm::expressions::ExpressionEvaluator< double > &evaluator)
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.
void unpackStateDifferenceIntoEvaluator(CompressedState const &newState, CompressedState const &oldState, VariableInformation const &variableInformation, storm::expressions::ExpressionEvaluator< ValueType > &evaluator)
Updates the (non-transient) variable values in the given evaluator from the values of oldState to the...
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)
template void unpackStateDifferenceIntoEvaluator< storm::RationalFunction >(CompressedState const &newState, CompressedState const &oldState, VariableInformation const &variableInformation, storm::expressions::ExpressionEvaluator< storm::RationalFunction > &evaluator)
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