3#include <boost/algorithm/string/join.hpp>
18template<
typename ValueType>
22 if (locationVariable.bitWidth != 0) {
23 evaluator.setIntegerValue(locationVariable.variable, state.
getAsInt(locationVariable.bitOffset, locationVariable.bitWidth));
25 evaluator.setIntegerValue(locationVariable.variable, 0);
29 evaluator.setBooleanValue(booleanVariable.variable, state.
get(booleanVariable.bitOffset));
32 evaluator.setIntegerValue(integerVariable.variable,
33 static_cast<int_fast64_t
>(state.
getAsInt(integerVariable.bitOffset, integerVariable.bitWidth)) + integerVariable.lowerBound);
41 if (locationVariable.bitWidth != 0) {
42 result.
setIntegerValue(locationVariable.variable, state.
getAsInt(locationVariable.bitOffset, locationVariable.bitWidth));
48 result.
setBooleanValue(booleanVariable.variable, state.
get(booleanVariable.bitOffset));
52 static_cast<int_fast64_t
>(state.
getAsInt(integerVariable.bitOffset, integerVariable.bitWidth)) + integerVariable.lowerBound);
61 result.
set(booleanVariable.bitOffset, valuation.
getBooleanValue(booleanVariable.variable));
64 int64_t assignedValue = valuation.
getIntegerValue(integerVariable.variable);
65 if (checkOutOfBounds) {
66 STORM_LOG_THROW(assignedValue >= integerVariable.lowerBound, storm::exceptions::InvalidArgumentException,
67 "The assignment leads to an out-of-bounds value (" << assignedValue <<
") for the variable '" << integerVariable.getName() <<
"'.");
68 STORM_LOG_THROW(assignedValue <= integerVariable.upperBound, storm::exceptions::InvalidArgumentException,
69 "The assignment leads to an out-of-bounds value (" << assignedValue <<
") for the variable '" << integerVariable.getName() <<
"'.");
71 result.
setFromInt(integerVariable.bitOffset, integerVariable.bitWidth, assignedValue - integerVariable.lowerBound);
73 static_cast<int_fast64_t
>(result.
getAsInt(integerVariable.bitOffset, integerVariable.bitWidth)) + integerVariable.lowerBound == assignedValue,
74 "Writing to the bit vector bucket failed (read " << result.
getAsInt(integerVariable.bitOffset, integerVariable.bitWidth) <<
" but wrote "
75 << assignedValue <<
").");
82 std::vector<bool>& booleanValues, std::vector<int64_t>& integerValues) {
84 if (locationVariable.bitWidth != 0) {
85 locationValues.push_back(state.
getAsInt(locationVariable.bitOffset, locationVariable.bitWidth));
87 locationValues.push_back(0);
91 booleanValues.push_back(state.
get(booleanVariable.bitOffset));
94 integerValues.push_back(
static_cast<int_fast64_t
>(state.
getAsInt(integerVariable.bitOffset, integerVariable.bitWidth)) + integerVariable.lowerBound);
99 std::vector<std::string> assignments;
101 assignments.push_back(locationVariable.variable.getName() +
"=");
102 assignments.back() += std::to_string(locationVariable.bitWidth == 0 ? 0 : state.
getAsInt(locationVariable.bitOffset, locationVariable.bitWidth));
105 if (!state.
get(booleanVariable.bitOffset)) {
106 assignments.push_back(
"!" + booleanVariable.variable.getName());
108 assignments.push_back(booleanVariable.variable.getName());
112 assignments.push_back(
113 integerVariable.variable.getName() +
"=" +
114 std::to_string(
static_cast<int_fast64_t
>(state.
getAsInt(integerVariable.bitOffset, integerVariable.bitWidth)) + integerVariable.lowerBound));
116 return boost::join(assignments,
" & ");
122 if (locationVariable.observable) {
123 for (uint64_t i = locationVariable.bitOffset; i < locationVariable.bitOffset + locationVariable.bitWidth; ++i) {
130 if (booleanVariable.observable) {
131 result.
set(booleanVariable.bitOffset,
true);
136 if (integerVariable.observable) {
137 for (uint64_t i = integerVariable.bitOffset; i < integerVariable.bitOffset + integerVariable.bitWidth; ++i) {
149 if (observationVector.
size() != 0) {
150 observeClass.
concat(observationVector);
153 auto it = observabilityMap.find(observeClass);
154 if (it != observabilityMap.end()) {
157 uint32_t newClassIndex = observabilityMap.size();
158 observabilityMap.emplace(observeClass, newClassIndex);
159 return newClassIndex;
163template<
typename ValueType>
167 if (onlyObservable && !locationVariable.observable) {
170 if (locationVariable.bitWidth != 0) {
171 result[locationVariable.variable.getName()] = state.
getAsInt(locationVariable.bitOffset, locationVariable.bitWidth);
173 result[locationVariable.variable.getName()] = 0;
177 if (onlyObservable && !booleanVariable.observable) {
180 result[booleanVariable.getName()] = state.
get(booleanVariable.bitOffset);
183 if (onlyObservable && !integerVariable.observable) {
186 STORM_LOG_ASSERT(integerVariable.bitWidth <= 63,
"Only integer variables with at most 63 bits are supported");
187 result[integerVariable.getName()] =
188 static_cast<int64_t
>(state.
getAsInt(integerVariable.bitOffset, integerVariable.bitWidth)) + integerVariable.lowerBound;
204 std::map<storm::expressions::Variable, storm::expressions::Expression>
const& stateDescription,
bool checkOutOfBounds) {
208 for (
auto boolIt = varInfo.
booleanVariables.begin(); boolIt != boolItEnd; ++boolIt) {
209 STORM_LOG_THROW(stateDescription.count(boolIt->variable) > 0, storm::exceptions::InvalidArgumentException,
210 "Assignment for Boolean variable " << boolIt->getName() <<
" missing.");
211 result.
set(boolIt->bitOffset, stateDescription.at(boolIt->variable).evaluateAsBool());
216 for (
auto integerIt = varInfo.
integerVariables.begin(); integerIt != integerItEnd; ++integerIt) {
217 STORM_LOG_THROW(stateDescription.count(integerIt->variable) > 0, storm::exceptions::InvalidArgumentException,
218 "Assignment for Integer variable " << integerIt->getName() <<
" missing.");
220 int64_t assignedValue = stateDescription.at(integerIt->variable).evaluateAsInt();
221 if (checkOutOfBounds) {
222 STORM_LOG_THROW(assignedValue >= integerIt->lowerBound, storm::exceptions::InvalidArgumentException,
223 "The assignment leads to an out-of-bounds value (" << assignedValue <<
") for the variable '" << integerIt->getName() <<
"'.");
224 STORM_LOG_THROW(assignedValue <= integerIt->upperBound, storm::exceptions::InvalidArgumentException,
225 "The assignment leads to an out-of-bounds value (" << assignedValue <<
") for the variable '" << integerIt->getName() <<
"'.");
227 result.
setFromInt(integerIt->bitOffset, integerIt->bitWidth, assignedValue - integerIt->lowerBound);
228 STORM_LOG_ASSERT(
static_cast<int_fast64_t
>(result.
getAsInt(integerIt->bitOffset, integerIt->bitWidth)) + integerIt->lowerBound == assignedValue,
229 "Writing to the bit vector bucket failed (read " << result.
getAsInt(integerIt->bitOffset, integerIt->bitWidth) <<
" but wrote "
230 << assignedValue <<
").");
240#ifdef STORM_HAVE_CARL
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(uint_fast64_t bitIndex, uint_fast64_t numberOfBits, uint64_t value)
Sets the selected number of lowermost bits of the provided value at the given bit index.
void set(uint_fast64_t index, bool value=true)
Sets the given truth value at the given index.
size_t size() const
Retrieves the number of bits this bit vector can store.
uint_fast64_t getAsInt(uint_fast64_t bitIndex, uint_fast64_t numberOfBits) const
Retrieves the content of the current bit vector at the given index for the given number of bits as an...
bool get(uint_fast64_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.
#define STORM_LOG_ASSERT(cond, message)
#define STORM_LOG_THROW(cond, exception, message)
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 void unpackStateIntoEvaluator< double >(CompressedState const &state, 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 extractVariableValues(CompressedState const &state, VariableInformation const &variableInformation, std::vector< int64_t > &locationValues, std::vector< bool > &booleanValues, std::vector< int64_t > &integerValues)
Appends the values of the given variables in the given state to the corresponding result vectors.
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
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