Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
JaniNextStateGenerator.cpp
Go to the documentation of this file.
2
4
6
8
11
23
25
27
29
39
40namespace storm {
41namespace generator {
42
43template<typename ValueType, typename StateType>
45 : JaniNextStateGenerator(model.substituteConstantsFunctionsTranscendentals(), options, false) {
46 // Intentionally left empty.
47}
48
49template<typename ValueType, typename StateType>
51 : NextStateGenerator<ValueType, StateType>(model.getExpressionManager(), options),
52 model(model),
53 rewardExpressions(),
54 hasStateActionRewards(false),
55 evaluateRewardExpressionsAtEdges(false),
56 evaluateRewardExpressionsAtDestinations(false) {
57 STORM_LOG_THROW(!this->options.isBuildChoiceLabelsSet(), storm::exceptions::NotSupportedException,
58 "JANI next-state generator cannot generate choice labels.");
59
60 auto features = this->model.getModelFeatures();
64 // Eliminate arrays if necessary.
65 if (features.hasArrays()) {
66 arrayEliminatorData = this->model.eliminateArrays(true);
67 this->options.substituteExpressions([this](storm::expressions::Expression const& exp) { return arrayEliminatorData.transformExpression(exp); });
68 features.remove(storm::jani::ModelFeature::Arrays);
69 }
70 STORM_LOG_THROW(features.empty(), storm::exceptions::NotSupportedException,
71 "The explicit next-state generator does not support the following model feature(s): " << features.toString() << ".");
72 // Simplify the system compositions so that we can exclude the case where automata appear in the composition multiple times.
73 this->model.simplifyComposition();
74
75 // Get the reward expressions to be build. Also find out whether there is a non-trivial one.
76 bool hasNonTrivialRewardExpressions = false;
77 if (this->options.isBuildAllRewardModelsSet()) {
78 rewardExpressions = this->model.getAllRewardModelExpressions();
79 hasNonTrivialRewardExpressions = this->model.hasNonTrivialRewardExpression();
80 } else {
81 // Extract the reward models from the model based on the names we were given.
82 for (auto const& rewardModelName : this->options.getRewardModelNames()) {
83 rewardExpressions.emplace_back(rewardModelName, this->model.getRewardModelExpression(rewardModelName));
84 hasNonTrivialRewardExpressions = hasNonTrivialRewardExpressions || this->model.isNonTrivialRewardModelExpression(rewardModelName);
85 }
86 }
87 // If a transient variable has a non-zero default value, we also consider that non-trivial.
88 // In those cases, lifting edge destination assignments to the edges would mean that reward is collected twice:
89 // once at the edge (assigned value), once at the edge destinations (default value).
90 if (!hasNonTrivialRewardExpressions) {
91 for (auto const& rewExpr : rewardExpressions) {
92 STORM_LOG_ASSERT(rewExpr.second.isVariable(), "Expected trivial reward expression to be a variable. Got " << rewExpr.second << " instead.");
93 auto const& var = this->model.getGlobalVariables().getVariable(rewExpr.second.getBaseExpression().asVariableExpression().getVariable());
94 if (var.isTransient() && var.hasInitExpression() && !storm::utility::isZero(var.getInitExpression().evaluateAsRational())) {
95 hasNonTrivialRewardExpressions = true;
96 break;
97 }
98 }
99 }
100
101 // We try to lift the edge destination assignments to the edges as this reduces the number of evaluator calls.
102 // However, this will only be helpful if there are no assignment levels and only trivial reward expressions.
103 if (hasNonTrivialRewardExpressions || this->model.usesAssignmentLevels()) {
105 } else {
106 this->model.liftTransientEdgeDestinationAssignments(storm::jani::AssignmentLevelFinder().getLowestAssignmentLevel(this->model));
107 evaluateRewardExpressionsAtEdges = true;
108 }
109
110 // Create all synchronization-related information, e.g. the automata that are put in parallel.
111 this->createSynchronizationInformation();
112
113 // Now we are ready to initialize the variable information.
114 this->checkValid();
115 this->variableInformation =
116 VariableInformation(this->model, this->parallelAutomata, options.getReservedBitsForUnboundedVariables(), options.isAddOutOfBoundsStateSet());
118 this->transientVariableInformation = TransientVariableInformation<ValueType>(this->model, this->parallelAutomata);
119 this->transientVariableInformation.registerArrayVariableReplacements(arrayEliminatorData);
121
122 // Create a proper evaluator.
123 this->evaluator = std::make_unique<storm::expressions::ExpressionEvaluator<ValueType>>(this->model.getManager());
124 this->transientVariableInformation.setDefaultValuesInEvaluator(*this->evaluator);
125
126 // Build the information structs for the reward models.
127 buildRewardModelInformation();
128
129 // If there are terminal states we need to handle, we now need to translate all labels to expressions.
130 if (this->options.hasTerminalStates()) {
131 for (auto const& expressionOrLabelAndBool : this->options.getTerminalStates()) {
132 if (expressionOrLabelAndBool.first.isExpression()) {
133 this->terminalStates.emplace_back(expressionOrLabelAndBool.first.getExpression(), expressionOrLabelAndBool.second);
134 } else {
135 // If it's a label, i.e. refers to a transient boolean variable we do some sanity checks first
136 if (!this->isSpecialLabel(expressionOrLabelAndBool.first.getLabel())) {
137 STORM_LOG_THROW(this->model.getGlobalVariables().hasVariable(expressionOrLabelAndBool.first.getLabel()),
138 storm::exceptions::InvalidArgumentException,
139 "Terminal states refer to illegal label '" << expressionOrLabelAndBool.first.getLabel() << "'.");
140
141 storm::jani::Variable const& variable = this->model.getGlobalVariables().getVariable(expressionOrLabelAndBool.first.getLabel());
143 storm::exceptions::InvalidArgumentException,
144 "Terminal states refer to non-boolean variable '" << expressionOrLabelAndBool.first.getLabel() << "'.");
145 STORM_LOG_THROW(variable.isTransient(), storm::exceptions::InvalidArgumentException,
146 "Terminal states refer to non-transient variable '" << expressionOrLabelAndBool.first.getLabel() << "'.");
147
148 this->terminalStates.emplace_back(variable.getExpressionVariable().getExpression(), expressionOrLabelAndBool.second);
149 }
150 }
151 }
152 }
153}
154
155template<typename ValueType, typename StateType>
162 // We do not add Functions as these should ideally be substituted before creating this generator.
163 // This is because functions may also occur in properties and the user of this class should take care of that.
164 return features;
165}
166
167template<typename ValueType, typename StateType>
169 auto features = model.getModelFeatures();
172 features.remove(storm::jani::ModelFeature::Functions); // can be substituted
175 if (!features.empty()) {
176 STORM_LOG_INFO("The model can not be build as it contains these unsupported features: " << features.toString());
177 return false;
178 }
179 // There probably are more cases where the model is unsupported. However, checking these is more involved.
180 // As this method is supposed to be a quick check, we just return true at this point.
181 return true;
182}
183
184template<typename ValueType, typename StateType>
186 switch (model.getModelType()) {
188 return ModelType::DTMC;
190 return ModelType::CTMC;
192 return ModelType::MDP;
194 return ModelType::MA;
195 default:
196 STORM_LOG_THROW(false, storm::exceptions::WrongFormatException, "Invalid model type.");
197 }
198}
199
200template<typename ValueType, typename StateType>
204
205template<typename ValueType, typename StateType>
209
210template<typename ValueType, typename StateType>
214
215template<typename ValueType, typename StateType>
217 if (locationVariable.bitWidth == 0) {
218 return 0;
219 } else {
220 return state.getAsInt(locationVariable.bitOffset, locationVariable.bitWidth);
221 }
222}
223
224template<typename ValueType, typename StateType>
225void JaniNextStateGenerator<ValueType, StateType>::setLocation(CompressedState& state, LocationVariableInformation const& locationVariable,
226 uint64_t locationIndex) const {
227 if (locationVariable.bitWidth != 0) {
228 state.setFromInt(locationVariable.bitOffset, locationVariable.bitWidth, locationIndex);
229 }
230}
231
232template<typename ValueType, typename StateType>
233std::vector<uint64_t> JaniNextStateGenerator<ValueType, StateType>::getLocations(CompressedState const& state) const {
234 std::vector<uint64_t> result(this->variableInformation.locationVariables.size());
235
236 auto resultIt = result.begin();
237 for (auto it = this->variableInformation.locationVariables.begin(), ite = this->variableInformation.locationVariables.end(); it != ite; ++it, ++resultIt) {
238 if (it->bitWidth == 0) {
239 *resultIt = 0;
240 } else {
241 *resultIt = state.getAsInt(it->bitOffset, it->bitWidth);
242 }
243 }
244
245 return result;
246}
247
248template<typename ValueType, typename StateType>
250 std::vector<StateType> initialStateIndices;
251
252 if (this->model.hasNonTrivialInitialStates()) {
253 // Prepare an SMT solver to enumerate all initial states.
255 std::unique_ptr<storm::solver::SmtSolver> solver = factory.create(model.getExpressionManager());
256
257 std::vector<storm::expressions::Expression> rangeExpressions = model.getAllRangeExpressions(this->parallelAutomata);
258 for (auto const& expression : rangeExpressions) {
259 solver->add(expression);
260 }
261 solver->add(model.getInitialStatesExpression(this->parallelAutomata));
262
263 // Proceed as long as the solver can still enumerate initial states.
264 while (solver->check() == storm::solver::SmtSolver::CheckResult::Sat) {
265 // Create fresh state.
266 CompressedState initialState(this->variableInformation.getTotalBitOffset(true));
267
268 // Read variable assignment from the solution of the solver. Also, create an expression we can use to
269 // prevent the variable assignment from being enumerated again.
270 storm::expressions::Expression blockingExpression;
271 std::shared_ptr<storm::solver::SmtSolver::ModelReference> model = solver->getModel();
272 for (auto const& booleanVariable : this->variableInformation.booleanVariables) {
273 bool variableValue = model->getBooleanValue(booleanVariable.variable);
274 storm::expressions::Expression localBlockingExpression = variableValue ? !booleanVariable.variable : booleanVariable.variable;
275 blockingExpression = blockingExpression.isInitialized() ? blockingExpression || localBlockingExpression : localBlockingExpression;
276 initialState.set(booleanVariable.bitOffset, variableValue);
277 }
278 for (auto const& integerVariable : this->variableInformation.integerVariables) {
279 int_fast64_t variableValue = model->getIntegerValue(integerVariable.variable);
280 if (integerVariable.forceOutOfBoundsCheck || this->getOptions().isExplorationChecksSet()) {
281 STORM_LOG_THROW(variableValue >= integerVariable.lowerBound, storm::exceptions::WrongFormatException,
282 "The initial value for variable " << integerVariable.variable.getName() << " is lower than the lower bound.");
283 STORM_LOG_THROW(variableValue <= integerVariable.upperBound, storm::exceptions::WrongFormatException,
284 "The initial value for variable " << integerVariable.variable.getName() << " is higher than the upper bound");
285 }
286 storm::expressions::Expression localBlockingExpression = integerVariable.variable != model->getManager().integer(variableValue);
287 blockingExpression = blockingExpression.isInitialized() ? blockingExpression || localBlockingExpression : localBlockingExpression;
288 initialState.setFromInt(integerVariable.bitOffset, integerVariable.bitWidth,
289 static_cast<uint_fast64_t>(variableValue - integerVariable.lowerBound));
290 }
291
292 // Gather iterators to the initial locations of all the automata.
293 std::vector<std::set<uint64_t>::const_iterator> initialLocationsIts;
294 std::vector<std::set<uint64_t>::const_iterator> initialLocationsItes;
295 for (auto const& automatonRef : this->parallelAutomata) {
296 auto const& automaton = automatonRef.get();
297 initialLocationsIts.push_back(automaton.getInitialLocationIndices().cbegin());
298 initialLocationsItes.push_back(automaton.getInitialLocationIndices().cend());
299 }
301 initialLocationsIts, initialLocationsItes,
302 [this, &initialState](uint64_t index, uint64_t value) { setLocation(initialState, this->variableInformation.locationVariables[index], value); },
303 [&stateToIdCallback, &initialStateIndices, &initialState]() {
304 // Register initial state.
305 StateType id = stateToIdCallback(initialState);
306 initialStateIndices.push_back(id);
307 return true;
308 });
309
310 // Block the current initial state to search for the next one.
311 if (!blockingExpression.isInitialized()) {
312 break;
313 }
314 solver->add(blockingExpression);
315 }
316
317 STORM_LOG_DEBUG("Enumerated " << initialStateIndices.size() << " initial states using SMT solving.");
318 } else {
319 // Create vectors holding all possible values
320 std::vector<std::vector<uint64_t>> allValues;
321 for (auto const& aRef : this->parallelAutomata) {
322 auto const& aInitLocs = aRef.get().getInitialLocationIndices();
323 allValues.emplace_back(aInitLocs.begin(), aInitLocs.end());
324 }
325 uint64_t locEndIndex = allValues.size();
326 for (auto const& intVar : this->variableInformation.integerVariables) {
327 STORM_LOG_ASSERT(intVar.lowerBound <= intVar.upperBound, "Expecting variable with non-empty set of possible values.");
328 // The value of integer variables is shifted so that 0 is always the smallest possible value
329 allValues.push_back(storm::utility::vector::buildVectorForRange<uint64_t>(static_cast<uint64_t>(0), intVar.upperBound + 1 - intVar.lowerBound));
330 }
331 uint64_t intEndIndex = allValues.size();
332 // For boolean variables we consider the values 0 and 1.
333 allValues.resize(allValues.size() + this->variableInformation.booleanVariables.size(),
334 std::vector<uint64_t>({static_cast<uint64_t>(0), static_cast<uint64_t>(1)}));
335
336 std::vector<std::vector<uint64_t>::const_iterator> its;
337 std::vector<std::vector<uint64_t>::const_iterator> ites;
338 for (auto const& valVec : allValues) {
339 its.push_back(valVec.cbegin());
340 ites.push_back(valVec.cend());
341 }
342
343 // Now create an initial state for each combination of values
344 CompressedState initialState(this->variableInformation.getTotalBitOffset(true));
346 its, ites,
347 [this, &initialState, &locEndIndex, &intEndIndex](uint64_t index, uint64_t value) {
348 // Set the value for the variable corresponding to the given index
349 if (index < locEndIndex) {
350 // Location variable
351 setLocation(initialState, this->variableInformation.locationVariables[index], value);
352 } else if (index < intEndIndex) {
353 // Integer variable
354 auto const& intVar = this->variableInformation.integerVariables[index - locEndIndex];
355 initialState.setFromInt(intVar.bitOffset, intVar.bitWidth, value);
356 } else {
357 // Boolean variable
358 STORM_LOG_ASSERT(index - intEndIndex < this->variableInformation.booleanVariables.size(), "Unexpected index");
359 auto const& boolVar = this->variableInformation.booleanVariables[index - intEndIndex];
360 STORM_LOG_ASSERT(value <= 1u, "Unexpected value for boolean variable.");
361 initialState.set(boolVar.bitOffset, static_cast<bool>(value));
362 }
363 },
364 [&stateToIdCallback, &initialStateIndices, &initialState]() {
365 // Register initial state.
366 StateType id = stateToIdCallback(initialState);
367 initialStateIndices.push_back(id);
368 return true; // Keep on exploring
369 });
370 STORM_LOG_DEBUG("Enumerated " << initialStateIndices.size() << " initial states using brute force enumeration.");
371 }
372 return initialStateIndices;
373}
374
375template<typename ValueType, typename StateType>
377 storm::generator::LocationVariableInformation const& locationVariable, int64_t assignmentLevel,
378 storm::expressions::ExpressionEvaluator<ValueType> const& expressionEvaluator) {
379 // Update the location of the state.
380 setLocation(state, locationVariable, destination.getLocationIndex());
381
382 // Then perform the assignments.
383 auto const& assignments = destination.getOrderedAssignments().getNonTransientAssignments(assignmentLevel);
384 auto assignmentIt = assignments.begin();
385 auto assignmentIte = assignments.end();
386
387 // Iterate over all boolean assignments and carry them out.
388 auto boolIt = this->variableInformation.booleanVariables.begin();
389 for (; assignmentIt != assignmentIte && assignmentIt->lValueIsVariable() && assignmentIt->getExpressionVariable().hasBooleanType(); ++assignmentIt) {
390 while (assignmentIt->getExpressionVariable() != boolIt->variable) {
391 ++boolIt;
392 }
393 state.set(boolIt->bitOffset, expressionEvaluator.asBool(assignmentIt->getAssignedExpression()));
394 }
395
396 // Iterate over all integer assignments and carry them out.
397 auto integerIt = this->variableInformation.integerVariables.begin();
398 for (; assignmentIt != assignmentIte && assignmentIt->lValueIsVariable() && assignmentIt->getExpressionVariable().hasIntegerType(); ++assignmentIt) {
399 while (assignmentIt->getExpressionVariable() != integerIt->variable) {
400 ++integerIt;
401 }
402 int_fast64_t assignedValue = expressionEvaluator.asInt(assignmentIt->getAssignedExpression());
403 if (this->options.isAddOutOfBoundsStateSet()) {
404 if (assignedValue < integerIt->lowerBound || assignedValue > integerIt->upperBound) {
405 state = this->outOfBoundsState;
406 }
407 } else if (integerIt->forceOutOfBoundsCheck || this->options.isExplorationChecksSet()) {
408 STORM_LOG_THROW(assignedValue >= integerIt->lowerBound, storm::exceptions::WrongFormatException,
409 "The update " << assignmentIt->getExpressionVariable().getName() << " := " << assignmentIt->getAssignedExpression()
410 << " leads to an out-of-bounds value (" << assignedValue << ") for the variable '"
411 << assignmentIt->getExpressionVariable().getName() << "'.");
412 STORM_LOG_THROW(assignedValue <= integerIt->upperBound, storm::exceptions::WrongFormatException,
413 "The update " << assignmentIt->getExpressionVariable().getName() << " := " << assignmentIt->getAssignedExpression()
414 << " leads to an out-of-bounds value (" << assignedValue << ") for the variable '"
415 << assignmentIt->getExpressionVariable().getName() << "'.");
416 }
417 state.setFromInt(integerIt->bitOffset, integerIt->bitWidth, assignedValue - integerIt->lowerBound);
418 STORM_LOG_ASSERT(static_cast<int_fast64_t>(state.getAsInt(integerIt->bitOffset, integerIt->bitWidth)) + integerIt->lowerBound == assignedValue,
419 "Writing to the bit vector bucket failed (read " << state.getAsInt(integerIt->bitOffset, integerIt->bitWidth) << " but wrote "
420 << assignedValue << ").");
421 }
422 // Iterate over all array access assignments and carry them out.
423 for (; assignmentIt != assignmentIte && assignmentIt->lValueIsArrayAccess(); ++assignmentIt) {
424 auto const& arrayIndicesAsExpr = assignmentIt->getLValue().getArrayIndexVector();
425 std::vector<uint64_t> arrayIndices;
426 arrayIndices.reserve(arrayIndicesAsExpr.size());
427 for (auto const& i : arrayIndicesAsExpr) {
428 arrayIndices.push_back(static_cast<uint64_t>(expressionEvaluator.asInt(i)));
429 }
430 if (assignmentIt->getAssignedExpression().hasIntegerType()) {
431 IntegerVariableInformation const& intInfo =
432 this->variableInformation.getIntegerArrayVariableReplacement(assignmentIt->getLValue().getVariable().getExpressionVariable(), arrayIndices);
433 int_fast64_t assignedValue = expressionEvaluator.asInt(assignmentIt->getAssignedExpression());
434
435 if (this->options.isAddOutOfBoundsStateSet()) {
436 if (assignedValue < intInfo.lowerBound || assignedValue > intInfo.upperBound) {
437 state = this->outOfBoundsState;
438 }
439 } else if (this->options.isExplorationChecksSet()) {
440 STORM_LOG_THROW(assignedValue >= intInfo.lowerBound, storm::exceptions::WrongFormatException,
441 "The update " << assignmentIt->getLValue() << " := " << assignmentIt->getAssignedExpression()
442 << " leads to an out-of-bounds value (" << assignedValue << ") for the variable '"
443 << assignmentIt->getExpressionVariable().getName() << "'.");
444 STORM_LOG_THROW(assignedValue <= intInfo.upperBound, storm::exceptions::WrongFormatException,
445 "The update " << assignmentIt->getLValue() << " := " << assignmentIt->getAssignedExpression()
446 << " leads to an out-of-bounds value (" << assignedValue << ") for the variable '"
447 << assignmentIt->getExpressionVariable().getName() << "'.");
448 }
449 state.setFromInt(intInfo.bitOffset, intInfo.bitWidth, assignedValue - intInfo.lowerBound);
450 STORM_LOG_ASSERT(static_cast<int_fast64_t>(state.getAsInt(intInfo.bitOffset, intInfo.bitWidth)) + intInfo.lowerBound == assignedValue,
451 "Writing to the bit vector bucket failed (read " << state.getAsInt(intInfo.bitOffset, intInfo.bitWidth) << " but wrote "
452 << assignedValue << ").");
453 } else if (assignmentIt->getAssignedExpression().hasBooleanType()) {
454 BooleanVariableInformation const& boolInfo =
455 this->variableInformation.getBooleanArrayVariableReplacement(assignmentIt->getLValue().getVariable().getExpressionVariable(), arrayIndices);
456 state.set(boolInfo.bitOffset, expressionEvaluator.asBool(assignmentIt->getAssignedExpression()));
457 } else {
458 STORM_LOG_THROW(false, storm::exceptions::UnexpectedException, "Unhandled type of base variable.");
459 }
460 }
461
462 // Check that we processed all assignments.
463 STORM_LOG_ASSERT(assignmentIt == assignmentIte, "Not all assignments were consumed.");
464}
465
466template<typename ValueType, typename StateType>
467void JaniNextStateGenerator<ValueType, StateType>::applyTransientUpdate(TransientVariableValuation<ValueType>& transientValuation,
468 storm::jani::detail::ConstAssignments const& transientAssignments,
469 storm::expressions::ExpressionEvaluator<ValueType> const& expressionEvaluator) const {
470 auto assignmentIt = transientAssignments.begin();
471 auto assignmentIte = transientAssignments.end();
472
473 // Iterate over all boolean assignments and carry them out.
474 auto boolIt = this->transientVariableInformation.booleanVariableInformation.begin();
475 for (; assignmentIt != assignmentIte && assignmentIt->lValueIsVariable() && assignmentIt->getExpressionVariable().hasBooleanType(); ++assignmentIt) {
476 while (assignmentIt->getExpressionVariable() != boolIt->variable) {
477 ++boolIt;
478 }
479 transientValuation.booleanValues.emplace_back(&(*boolIt), expressionEvaluator.asBool(assignmentIt->getAssignedExpression()));
480 }
481 // Iterate over all integer assignments and carry them out.
482 auto integerIt = this->transientVariableInformation.integerVariableInformation.begin();
483 for (; assignmentIt != assignmentIte && assignmentIt->lValueIsVariable() && assignmentIt->getExpressionVariable().hasIntegerType(); ++assignmentIt) {
484 while (assignmentIt->getExpressionVariable() != integerIt->variable) {
485 ++integerIt;
486 }
487 int64_t assignedValue = expressionEvaluator.asInt(assignmentIt->getAssignedExpression());
488 if (this->options.isExplorationChecksSet()) {
489 STORM_LOG_THROW(!integerIt->lowerBound || assignedValue >= integerIt->lowerBound.get(), storm::exceptions::WrongFormatException,
490 "The update " << assignmentIt->getExpressionVariable().getName() << " := " << assignmentIt->getAssignedExpression()
491 << " leads to an out-of-bounds value (" << assignedValue << ") for the variable '"
492 << assignmentIt->getExpressionVariable().getName() << "'.");
493 STORM_LOG_THROW(!integerIt->upperBound || assignedValue <= integerIt->upperBound.get(), storm::exceptions::WrongFormatException,
494 "The update " << assignmentIt->getExpressionVariable().getName() << " := " << assignmentIt->getAssignedExpression()
495 << " leads to an out-of-bounds value (" << assignedValue << ") for the variable '"
496 << assignmentIt->getExpressionVariable().getName() << "'.");
497 }
498 transientValuation.integerValues.emplace_back(&(*integerIt), assignedValue);
499 }
500 // Iterate over all rational assignments and carry them out.
501 auto rationalIt = this->transientVariableInformation.rationalVariableInformation.begin();
502 for (; assignmentIt != assignmentIte && assignmentIt->lValueIsVariable() && assignmentIt->getExpressionVariable().hasRationalType(); ++assignmentIt) {
503 while (assignmentIt->getExpressionVariable() != rationalIt->variable) {
504 ++rationalIt;
505 }
506 transientValuation.rationalValues.emplace_back(&(*rationalIt), expressionEvaluator.asRational(assignmentIt->getAssignedExpression()));
507 }
508
509 // Iterate over all array access assignments and carry them out.
510 for (; assignmentIt != assignmentIte && assignmentIt->lValueIsArrayAccess(); ++assignmentIt) {
511 auto const& arrayIndicesAsExpr = assignmentIt->getLValue().getArrayIndexVector();
512 std::vector<uint64_t> arrayIndices;
513 arrayIndices.reserve(arrayIndicesAsExpr.size());
514 for (auto const& i : arrayIndicesAsExpr) {
515 arrayIndices.push_back(static_cast<uint64_t>(expressionEvaluator.asInt(i)));
516 }
517 storm::expressions::Type const& baseType = assignmentIt->getLValue().getVariable().getExpressionVariable().getType();
518 if (baseType.isIntegerType()) {
519 auto const& intInfo = this->transientVariableInformation.getIntegerArrayVariableReplacement(
520 assignmentIt->getLValue().getVariable().getExpressionVariable(), arrayIndices);
521 int64_t assignedValue = expressionEvaluator.asInt(assignmentIt->getAssignedExpression());
522 if (this->options.isExplorationChecksSet()) {
523 STORM_LOG_THROW(assignedValue >= intInfo.lowerBound, storm::exceptions::WrongFormatException,
524 "The update " << assignmentIt->getLValue() << " := " << assignmentIt->getAssignedExpression()
525 << " leads to an out-of-bounds value (" << assignedValue << ") for the variable '"
526 << assignmentIt->getExpressionVariable().getName() << "'.");
527 STORM_LOG_THROW(assignedValue <= intInfo.upperBound, storm::exceptions::WrongFormatException,
528 "The update " << assignmentIt->getLValue() << " := " << assignmentIt->getAssignedExpression()
529 << " leads to an out-of-bounds value (" << assignedValue << ") for the variable '"
530 << assignmentIt->getExpressionVariable().getName() << "'.");
531 }
532 transientValuation.integerValues.emplace_back(&intInfo, assignedValue);
533 } else if (baseType.isBooleanType()) {
534 auto const& boolInfo = this->transientVariableInformation.getBooleanArrayVariableReplacement(
535 assignmentIt->getLValue().getVariable().getExpressionVariable(), arrayIndices);
536 transientValuation.booleanValues.emplace_back(&boolInfo, expressionEvaluator.asBool(assignmentIt->getAssignedExpression()));
537 } else if (baseType.isRationalType()) {
538 auto const& rationalInfo = this->transientVariableInformation.getRationalArrayVariableReplacement(
539 assignmentIt->getLValue().getVariable().getExpressionVariable(), arrayIndices);
540 transientValuation.rationalValues.emplace_back(&rationalInfo, expressionEvaluator.asRational(assignmentIt->getAssignedExpression()));
541 } else {
542 STORM_LOG_THROW(false, storm::exceptions::UnexpectedException, "Unhandled type of base variable.");
543 }
544 }
545
546 // Check that we processed all assignments.
547 STORM_LOG_ASSERT(assignmentIt == assignmentIte, "Not all assignments were consumed.");
548}
549
550template<typename ValueType, typename StateType>
551TransientVariableValuation<ValueType> JaniNextStateGenerator<ValueType, StateType>::getTransientVariableValuationAtLocations(
552 std::vector<uint64_t> const& locations, storm::expressions::ExpressionEvaluator<ValueType> const& evaluator) const {
553 uint64_t automatonIndex = 0;
554 TransientVariableValuation<ValueType> transientVariableValuation;
555 for (auto const& automatonRef : this->parallelAutomata) {
556 auto const& automaton = automatonRef.get();
557 uint64_t currentLocationIndex = locations[automatonIndex];
558 storm::jani::Location const& location = automaton.getLocation(currentLocationIndex);
559 STORM_LOG_ASSERT(!location.getAssignments().hasMultipleLevels(true), "Indexed assignments at locations are not supported in the jani standard.");
560 applyTransientUpdate(transientVariableValuation, location.getAssignments().getTransientAssignments(), evaluator);
561 ++automatonIndex;
562 }
563 return transientVariableValuation;
564}
565
566template<typename ValueType, typename StateType>
569 transientVariableInformation.setDefaultValuesInEvaluator(evaluator);
570 auto transientVariableValuation = getTransientVariableValuationAtLocations(getLocations(state), evaluator);
571 transientVariableValuation.setInEvaluator(evaluator, this->getOptions().isExplorationChecksSet());
572}
573
574template<typename ValueType, typename StateType>
577 // Also add information for transient variables
578 for (auto const& varInfo : transientVariableInformation.booleanVariableInformation) {
579 result.addVariable(varInfo.variable);
580 }
581 for (auto const& varInfo : transientVariableInformation.integerVariableInformation) {
582 result.addVariable(varInfo.variable);
583 }
584 for (auto const& varInfo : transientVariableInformation.rationalVariableInformation) {
585 result.addVariable(varInfo.variable);
586 }
587 return result;
588}
589
590template<typename ValueType, typename StateType>
592 storm::storage::sparse::StateValuationsBuilder& valuationsBuilder) const {
593 std::vector<bool> booleanValues;
594 booleanValues.reserve(this->variableInformation.booleanVariables.size() + transientVariableInformation.booleanVariableInformation.size());
595 std::vector<int64_t> integerValues;
596 integerValues.reserve(this->variableInformation.locationVariables.size() + this->variableInformation.integerVariables.size() +
597 transientVariableInformation.integerVariableInformation.size());
598 std::vector<storm::RationalNumber> rationalValues;
599 rationalValues.reserve(transientVariableInformation.rationalVariableInformation.size());
600
601 // Add values for non-transient variables
602 extractVariableValues(*this->state, this->variableInformation, integerValues, booleanValues, integerValues);
603
604 // Add values for transient variables
605 auto transientVariableValuation = getTransientVariableValuationAtLocations(getLocations(*this->state), *this->evaluator);
606 {
607 auto varIt = transientVariableValuation.booleanValues.begin();
608 auto varIte = transientVariableValuation.booleanValues.end();
609 for (auto const& varInfo : transientVariableInformation.booleanVariableInformation) {
610 if (varIt != varIte && varIt->first->variable == varInfo.variable) {
611 booleanValues.push_back(varIt->second);
612 ++varIt;
613 } else {
614 booleanValues.push_back(varInfo.defaultValue);
615 }
616 }
617 }
618 {
619 auto varIt = transientVariableValuation.integerValues.begin();
620 auto varIte = transientVariableValuation.integerValues.end();
621 for (auto const& varInfo : transientVariableInformation.integerVariableInformation) {
622 if (varIt != varIte && varIt->first->variable == varInfo.variable) {
623 integerValues.push_back(varIt->second);
624 ++varIt;
625 } else {
626 integerValues.push_back(varInfo.defaultValue);
627 }
628 }
629 }
630 {
631 auto varIt = transientVariableValuation.rationalValues.begin();
632 auto varIte = transientVariableValuation.rationalValues.end();
633 for (auto const& varInfo : transientVariableInformation.rationalVariableInformation) {
634 if (varIt != varIte && varIt->first->variable == varInfo.variable) {
635 rationalValues.push_back(storm::utility::convertNumber<storm::RationalNumber>(varIt->second));
636 ++varIt;
637 } else {
638 rationalValues.push_back(storm::utility::convertNumber<storm::RationalNumber>(varInfo.defaultValue));
639 }
640 }
641 }
642
643 valuationsBuilder.addState(currentStateIndex, std::move(booleanValues), std::move(integerValues), std::move(rationalValues));
644}
645
646template<typename ValueType, typename StateType>
648 // The evaluator should have the default values of the transient variables right now.
649
650 // Prepare the result, in case we return early.
652
653 // Retrieve the locations from the state.
654 std::vector<uint64_t> locations = getLocations(*this->state);
655
656 // First, construct the state rewards, as we may return early if there are no choices later and we already
657 // need the state rewards then.
658 auto transientVariableValuation = getTransientVariableValuationAtLocations(locations, *this->evaluator);
659 transientVariableValuation.setInEvaluator(*this->evaluator, this->getOptions().isExplorationChecksSet());
660 result.addStateRewards(evaluateRewardExpressions());
661
662 // If a terminal expression was set and we must not expand this state, return now.
663 // Terminal state expressions do not consider transient variables.
664 if (!this->terminalStates.empty()) {
665 for (auto const& expressionBool : this->terminalStates) {
666 if (this->evaluator->asBool(expressionBool.first) == expressionBool.second) {
667 // Set back transient variables to default values so we are ready to process the next state
668 this->transientVariableInformation.setDefaultValuesInEvaluator(*this->evaluator);
669 return result;
670 }
671 }
672 }
673
674 // Set back transient variables to default values so we are ready to process the transition assignments
675 this->transientVariableInformation.setDefaultValuesInEvaluator(*this->evaluator);
676
677 // Get all choices for the state.
678 result.setExpanded();
679 std::vector<Choice<ValueType>> allChoices;
680 if (this->getOptions().isApplyMaximalProgressAssumptionSet()) {
681 // First explore only edges without a rate
682 allChoices = getActionChoices(locations, *this->state, stateToIdCallback, EdgeFilter::WithoutRate);
683 if (allChoices.empty()) {
684 // Expand the Markovian edges if there are no probabilistic ones.
685 allChoices = getActionChoices(locations, *this->state, stateToIdCallback, EdgeFilter::WithRate);
686 }
687 } else {
688 allChoices = getActionChoices(locations, *this->state, stateToIdCallback);
689 }
690 std::size_t totalNumberOfChoices = allChoices.size();
691
692 // If there is not a single choice, we return immediately, because the state has no behavior (other than
693 // the state reward).
694 if (totalNumberOfChoices == 0) {
695 return result;
696 }
697
698 // If the model is a deterministic model, we need to fuse the choices into one.
699 if (this->isDeterministicModel() && totalNumberOfChoices > 1) {
700 Choice<ValueType> globalChoice;
701
702 if (this->options.isAddOverlappingGuardLabelSet()) {
703 this->overlappingGuardStates->push_back(stateToIdCallback(*this->state));
704 }
705
706 // For CTMCs, we need to keep track of the total exit rate to scale the action rewards later. For DTMCs
707 // this is equal to the number of choices, which is why we initialize it like this here.
708 ValueType totalExitRate = this->isDiscreteTimeModel() ? static_cast<ValueType>(totalNumberOfChoices) : storm::utility::zero<ValueType>();
709
710 // Iterate over all choices and combine the probabilities/rates into one choice.
711 for (auto const& choice : allChoices) {
712 for (auto const& stateProbabilityPair : choice) {
713 if (this->isDiscreteTimeModel()) {
714 globalChoice.addProbability(stateProbabilityPair.first, stateProbabilityPair.second / totalNumberOfChoices);
715 } else {
716 globalChoice.addProbability(stateProbabilityPair.first, stateProbabilityPair.second);
717 }
718 }
719
720 if (hasStateActionRewards && !this->isDiscreteTimeModel()) {
721 totalExitRate += choice.getTotalMass();
722 }
723 }
724
725 std::vector<ValueType> stateActionRewards(rewardExpressions.size(), storm::utility::zero<ValueType>());
726 for (auto const& choice : allChoices) {
727 if (hasStateActionRewards) {
728 for (uint_fast64_t rewardVariableIndex = 0; rewardVariableIndex < rewardExpressions.size(); ++rewardVariableIndex) {
729 stateActionRewards[rewardVariableIndex] += choice.getRewards()[rewardVariableIndex] * choice.getTotalMass() / totalExitRate;
730 }
731 }
732
733 if (this->options.isBuildChoiceOriginsSet() && choice.hasOriginData()) {
734 globalChoice.addOriginData(choice.getOriginData());
735 }
736 }
737 globalChoice.addRewards(std::move(stateActionRewards));
738
739 // Move the newly fused choice in place.
740 allChoices.clear();
741 allChoices.push_back(std::move(globalChoice));
742 }
743
744 // Move all remaining choices in place.
745 for (auto& choice : allChoices) {
746 result.addChoice(std::move(choice));
747 }
748
749 this->postprocess(result);
750
751 return result;
752}
753
754template<typename ValueType, typename StateType>
756 uint64_t automatonIndex, CompressedState const& state,
757 StateToIdCallback stateToIdCallback) {
758 // Determine the exit rate if it's a Markovian edge.
759 boost::optional<ValueType> exitRate = boost::none;
760 if (edge.hasRate()) {
761 exitRate = this->evaluator->asRational(edge.getRate());
762 }
763
764 Choice<ValueType> choice(edge.getActionIndex(), static_cast<bool>(exitRate));
765 std::vector<ValueType> stateActionRewards;
766
767 // Perform the transient edge assignments and create the state action rewards
768 TransientVariableValuation<ValueType> transientVariableValuation;
769 if (!evaluateRewardExpressionsAtEdges || edge.getAssignments().empty()) {
770 stateActionRewards.resize(rewardModelInformation.size(), storm::utility::zero<ValueType>());
771 } else {
772 for (int64_t assignmentLevel = edge.getAssignments().getLowestLevel(true); assignmentLevel <= edge.getAssignments().getHighestLevel(true);
773 ++assignmentLevel) {
774 transientVariableValuation.clear();
775 applyTransientUpdate(transientVariableValuation, edge.getAssignments().getTransientAssignments(assignmentLevel), *this->evaluator);
776 transientVariableValuation.setInEvaluator(*this->evaluator, this->getOptions().isExplorationChecksSet());
777 }
778 stateActionRewards = evaluateRewardExpressions();
779 transientVariableInformation.setDefaultValuesInEvaluator(*this->evaluator);
780 }
781
782 // Iterate over all updates of the current command.
783 ValueType probabilitySum = storm::utility::zero<ValueType>();
784 for (auto const& destination : edge.getDestinations()) {
785 ValueType probability = this->evaluator->asRational(destination.getProbability());
786
787 if (probability != storm::utility::zero<ValueType>()) {
788 bool evaluatorChanged = false;
789 // Obtain target state index and add it to the list of known states. If it has not yet been
790 // seen, we also add it to the set of states that have yet to be explored.
791 int64_t assignmentLevel = edge.getLowestAssignmentLevel(); // Might be the largest possible integer, if there is no assignment
792 int64_t const& highestLevel = edge.getHighestAssignmentLevel();
793 bool hasTransientAssignments = destination.hasTransientAssignment();
794 CompressedState newState = state;
795 applyUpdate(newState, destination, this->variableInformation.locationVariables[automatonIndex], assignmentLevel, *this->evaluator);
796 if (hasTransientAssignments) {
798 "Transition rewards are not supported and scaling to action rewards is disabled.");
799 transientVariableValuation.clear();
800 applyTransientUpdate(transientVariableValuation, destination.getOrderedAssignments().getTransientAssignments(assignmentLevel),
801 *this->evaluator);
802 transientVariableValuation.setInEvaluator(*this->evaluator, this->getOptions().isExplorationChecksSet());
803 evaluatorChanged = true;
804 }
805 if (assignmentLevel < highestLevel) {
806 while (assignmentLevel < highestLevel) {
807 ++assignmentLevel;
808 unpackStateIntoEvaluator(newState, this->variableInformation, *this->evaluator);
809 evaluatorChanged = true;
810 applyUpdate(newState, destination, this->variableInformation.locationVariables[automatonIndex], assignmentLevel, *this->evaluator);
811 if (hasTransientAssignments) {
812 transientVariableValuation.clear();
813 applyTransientUpdate(transientVariableValuation, destination.getOrderedAssignments().getTransientAssignments(assignmentLevel),
814 *this->evaluator);
815 transientVariableValuation.setInEvaluator(*this->evaluator, this->getOptions().isExplorationChecksSet());
816 evaluatorChanged = true;
817 }
818 }
819 }
820 if (evaluateRewardExpressionsAtDestinations) {
821 unpackStateIntoEvaluator(newState, this->variableInformation, *this->evaluator);
822 evaluatorChanged = true;
823 addEvaluatedRewardExpressions(stateActionRewards, probability);
824 }
825
826 if (evaluatorChanged) {
827 // Restore the old variable valuation
828 unpackStateIntoEvaluator(state, this->variableInformation, *this->evaluator);
829 if (hasTransientAssignments) {
830 this->transientVariableInformation.setDefaultValuesInEvaluator(*this->evaluator);
831 }
832 }
833
834 StateType stateIndex = stateToIdCallback(newState);
835
836 // Update the choice by adding the probability/target state to it.
837 probability = exitRate ? exitRate.get() * probability : probability;
838 choice.addProbability(stateIndex, probability);
839
840 if (this->options.isExplorationChecksSet()) {
841 probabilitySum += probability;
842 }
843 }
844 }
845
846 // Add the state action rewards
847 choice.addRewards(std::move(stateActionRewards));
848
849 if (this->options.isExplorationChecksSet()) {
850 // Check that the resulting distribution is in fact a distribution.
851 STORM_LOG_THROW(!this->isDiscreteTimeModel() || (!storm::utility::isConstant(probabilitySum) || this->comparator.isOne(probabilitySum)),
852 storm::exceptions::WrongFormatException, "Probabilities do not sum to one for edge (actually sum to " << probabilitySum << ").");
853 }
854
855 return choice;
856}
857
858template<typename ValueType, typename StateType>
859void JaniNextStateGenerator<ValueType, StateType>::generateSynchronizedDistribution(storm::storage::BitVector const& state,
860 AutomataEdgeSets const& edgeCombination,
861 std::vector<EdgeSetWithIndices::const_iterator> const& iteratorList,
863 std::vector<ValueType>& stateActionRewards, EdgeIndexSet& edgeIndices,
864 StateToIdCallback stateToIdCallback) {
865 // Collect some information of the edges.
866 int64_t lowestDestinationAssignmentLevel = std::numeric_limits<int64_t>::max();
867 int64_t highestDestinationAssignmentLevel = std::numeric_limits<int64_t>::min();
868 int64_t lowestEdgeAssignmentLevel = std::numeric_limits<int64_t>::max();
869 int64_t highestEdgeAssignmentLevel = std::numeric_limits<int64_t>::min();
870 uint64_t numDestinations = 1;
871 for (uint_fast64_t i = 0; i < iteratorList.size(); ++i) {
872 if (this->getOptions().isBuildChoiceOriginsSet()) {
873 auto automatonIndex = model.getAutomatonIndex(parallelAutomata[edgeCombination[i].first].get().getName());
874 edgeIndices.insert(model.encodeAutomatonAndEdgeIndices(automatonIndex, iteratorList[i]->first));
875 }
876 storm::jani::Edge const& edge = *iteratorList[i]->second;
877 lowestDestinationAssignmentLevel = std::min(lowestDestinationAssignmentLevel, edge.getLowestAssignmentLevel());
878 highestDestinationAssignmentLevel = std::max(highestDestinationAssignmentLevel, edge.getHighestAssignmentLevel());
879 if (!edge.getAssignments().empty(true)) {
880 lowestEdgeAssignmentLevel = std::min(lowestEdgeAssignmentLevel, edge.getAssignments().getLowestLevel(true));
881 highestEdgeAssignmentLevel = std::max(highestEdgeAssignmentLevel, edge.getAssignments().getHighestLevel(true));
882 }
883 numDestinations *= edge.getNumberOfDestinations();
884 }
885
886 // Perform the edge assignments (if there are any)
887 TransientVariableValuation<ValueType> transientVariableValuation;
888 if (evaluateRewardExpressionsAtEdges && lowestEdgeAssignmentLevel <= highestEdgeAssignmentLevel) {
889 for (int64_t assignmentLevel = lowestEdgeAssignmentLevel; assignmentLevel <= highestEdgeAssignmentLevel; ++assignmentLevel) {
890 transientVariableValuation.clear();
891 for (uint_fast64_t i = 0; i < iteratorList.size(); ++i) {
892 storm::jani::Edge const& edge = *iteratorList[i]->second;
893 applyTransientUpdate(transientVariableValuation, edge.getAssignments().getTransientAssignments(assignmentLevel), *this->evaluator);
894 }
895 transientVariableValuation.setInEvaluator(*this->evaluator, this->getOptions().isExplorationChecksSet());
896 }
897 addEvaluatedRewardExpressions(stateActionRewards, storm::utility::one<ValueType>());
898 transientVariableInformation.setDefaultValuesInEvaluator(*this->evaluator);
899 }
900
901 std::vector<storm::jani::EdgeDestination const*> destinations;
902 std::vector<LocationVariableInformation const*> locationVars;
903 destinations.reserve(iteratorList.size());
904 locationVars.reserve(iteratorList.size());
905
906 for (uint64_t destinationId = 0; destinationId < numDestinations; ++destinationId) {
907 // First assignment level
908 destinations.clear();
909 locationVars.clear();
910 transientVariableValuation.clear();
911 CompressedState successorState = state;
912 ValueType successorProbability = storm::utility::one<ValueType>();
913
914 uint64_t destinationIndex = destinationId;
915 for (uint64_t i = 0; i < iteratorList.size(); ++i) {
916 storm::jani::Edge const& edge = *iteratorList[i]->second;
917 STORM_LOG_ASSERT(edge.getNumberOfDestinations() > 0, "Found an edge with zero destinations. This is not expected.");
918 uint64_t localDestinationIndex = destinationIndex % edge.getNumberOfDestinations();
919 destinations.push_back(&edge.getDestination(localDestinationIndex));
920 locationVars.push_back(&this->variableInformation.locationVariables[edgeCombination[i].first]);
921 destinationIndex /= edge.getNumberOfDestinations();
922 ValueType probability = this->evaluator->asRational(destinations.back()->getProbability());
923 if (edge.hasRate()) {
924 successorProbability *= probability * this->evaluator->asRational(edge.getRate());
925 } else {
926 successorProbability *= probability;
927 }
928 if (storm::utility::isZero(successorProbability)) {
929 break;
930 }
931
932 applyUpdate(successorState, *destinations.back(), *locationVars.back(), lowestDestinationAssignmentLevel, *this->evaluator);
933 applyTransientUpdate(transientVariableValuation,
934 destinations.back()->getOrderedAssignments().getTransientAssignments(lowestDestinationAssignmentLevel), *this->evaluator);
935 }
936
937 if (!storm::utility::isZero(successorProbability)) {
938 bool evaluatorChanged = false;
939 // remaining assignment levels (if there are any)
940 for (int64_t assignmentLevel = lowestDestinationAssignmentLevel + 1; assignmentLevel <= highestDestinationAssignmentLevel; ++assignmentLevel) {
941 unpackStateIntoEvaluator(successorState, this->variableInformation, *this->evaluator);
942 transientVariableValuation.setInEvaluator(*this->evaluator, this->getOptions().isExplorationChecksSet());
943 transientVariableValuation.clear();
944 evaluatorChanged = true;
945 auto locationVarIt = locationVars.begin();
946 for (auto const& destPtr : destinations) {
947 applyUpdate(successorState, *destPtr, **locationVarIt, assignmentLevel, *this->evaluator);
948 applyTransientUpdate(transientVariableValuation, destinations.back()->getOrderedAssignments().getTransientAssignments(assignmentLevel),
949 *this->evaluator);
950 ++locationVarIt;
951 }
952 }
953 if (!transientVariableValuation.empty()) {
954 evaluatorChanged = true;
955 transientVariableValuation.setInEvaluator(*this->evaluator, this->getOptions().isExplorationChecksSet());
956 }
957 if (evaluateRewardExpressionsAtDestinations) {
958 unpackStateIntoEvaluator(successorState, this->variableInformation, *this->evaluator);
959 evaluatorChanged = true;
960 addEvaluatedRewardExpressions(stateActionRewards, successorProbability);
961 }
962 if (evaluatorChanged) {
963 // Restore the old state information
964 unpackStateIntoEvaluator(state, this->variableInformation, *this->evaluator);
965 this->transientVariableInformation.setDefaultValuesInEvaluator(*this->evaluator);
966 }
967
968 StateType id = stateToIdCallback(successorState);
969 distribution.add(id, successorProbability);
970 }
971 }
972}
973
974template<typename ValueType, typename StateType>
975void JaniNextStateGenerator<ValueType, StateType>::expandSynchronizingEdgeCombination(AutomataEdgeSets const& edgeCombination, uint64_t outputActionIndex,
976 CompressedState const& state, StateToIdCallback stateToIdCallback,
977 std::vector<Choice<ValueType>>& newChoices) {
978 if (this->options.isExplorationChecksSet()) {
979 // Check whether a global variable is written multiple times in any combination.
980 checkGlobalVariableWritesValid(edgeCombination);
981 }
982
983 std::vector<EdgeSetWithIndices::const_iterator> iteratorList(edgeCombination.size());
984
985 // Initialize the list of iterators.
986 for (size_t i = 0; i < edgeCombination.size(); ++i) {
987 iteratorList[i] = edgeCombination[i].second.cbegin();
988 }
989
991
992 // As long as there is one feasible combination of commands, keep on expanding it.
993 bool done = false;
994 while (!done) {
995 distribution.clear();
996
997 EdgeIndexSet edgeIndices;
998 std::vector<ValueType> stateActionRewards(rewardExpressions.size(), storm::utility::zero<ValueType>());
999 // old version without assignment levels generateSynchronizedDistribution(state, storm::utility::one<ValueType>(), 0, edgeCombination, iteratorList,
1000 // distribution, stateActionRewards, edgeIndices, stateToIdCallback);
1001 generateSynchronizedDistribution(state, edgeCombination, iteratorList, distribution, stateActionRewards, edgeIndices, stateToIdCallback);
1002 distribution.compress();
1003
1004 // At this point, we applied all commands of the current command combination and newTargetStates
1005 // contains all target states and their respective probabilities. That means we are now ready to
1006 // add the choice to the list of transitions.
1007 newChoices.emplace_back(outputActionIndex);
1008
1009 // Now create the actual distribution.
1010 Choice<ValueType>& choice = newChoices.back();
1011
1012 // Add the edge indices if requested.
1013 if (this->getOptions().isBuildChoiceOriginsSet()) {
1014 choice.addOriginData(boost::any(std::move(edgeIndices)));
1015 }
1016
1017 // Add the rewards to the choice.
1018 choice.addRewards(std::move(stateActionRewards));
1019
1020 // Add the probabilities/rates to the newly created choice.
1021 ValueType probabilitySum = storm::utility::zero<ValueType>();
1022 choice.reserve(std::distance(distribution.begin(), distribution.end()));
1023 for (auto const& stateProbability : distribution) {
1024 choice.addProbability(stateProbability.getState(), stateProbability.getValue());
1025
1026 if (this->options.isExplorationChecksSet()) {
1027 probabilitySum += stateProbability.getValue();
1028 }
1029 }
1030
1031 if (this->options.isExplorationChecksSet()) {
1032 // Check that the resulting distribution is in fact a distribution.
1033 STORM_LOG_THROW(!this->isDiscreteTimeModel() || !this->comparator.isConstant(probabilitySum) || this->comparator.isOne(probabilitySum),
1034 storm::exceptions::WrongFormatException,
1035 "Sum of update probabilities do not sum to one for some edge (actually sum to " << probabilitySum << ").");
1036 }
1037
1038 // Now, check whether there is one more command combination to consider.
1039 bool movedIterator = false;
1040 for (uint64_t j = 0; !movedIterator && j < iteratorList.size(); ++j) {
1041 ++iteratorList[j];
1042 if (iteratorList[j] != edgeCombination[j].second.end()) {
1043 movedIterator = true;
1044 } else {
1045 // Reset the iterator to the beginning of the list.
1046 iteratorList[j] = edgeCombination[j].second.begin();
1047 }
1048 }
1049
1050 done = !movedIterator;
1051 }
1052}
1053
1054template<typename ValueType, typename StateType>
1055std::vector<Choice<ValueType>> JaniNextStateGenerator<ValueType, StateType>::getActionChoices(std::vector<uint64_t> const& locations,
1056 CompressedState const& state, StateToIdCallback stateToIdCallback,
1057 EdgeFilter const& edgeFilter) {
1058 std::vector<Choice<ValueType>> result;
1059
1060 // To avoid reallocations, we declare some memory here here.
1061 // This vector will store for each automaton the set of edges with the current output and the current source location
1062 std::vector<EdgeSetWithIndices const*> edgeSetsMemory;
1063 // This vector will store the 'first' combination of edges that is productive.
1064 std::vector<typename EdgeSetWithIndices::const_iterator> edgeIteratorMemory;
1065
1066 for (OutputAndEdges const& outputAndEdges : edges) {
1067 auto const& edges = outputAndEdges.second;
1068 if (edges.size() == 1) {
1069 // If the synch consists of just one element, it's non-synchronizing.
1070 auto const& nonsychingEdges = edges.front();
1071 uint64_t automatonIndex = nonsychingEdges.first;
1072
1073 auto edgesIt = nonsychingEdges.second.find(locations[automatonIndex]);
1074 if (edgesIt != nonsychingEdges.second.end()) {
1075 for (auto const& indexAndEdge : edgesIt->second) {
1076 if (edgeFilter != EdgeFilter::All) {
1077 STORM_LOG_ASSERT(edgeFilter == EdgeFilter::WithRate || edgeFilter == EdgeFilter::WithoutRate, "Unexpected edge filter.");
1078 if ((edgeFilter == EdgeFilter::WithRate) != indexAndEdge.second->hasRate()) {
1079 continue;
1080 }
1081 }
1082 if (!this->evaluator->asBool(indexAndEdge.second->getGuard())) {
1083 continue;
1084 }
1085
1086 result.push_back(expandNonSynchronizingEdge(*indexAndEdge.second,
1087 outputAndEdges.first ? outputAndEdges.first.get() : indexAndEdge.second->getActionIndex(),
1088 automatonIndex, state, stateToIdCallback));
1089
1090 if (this->getOptions().isBuildChoiceOriginsSet()) {
1091 auto modelAutomatonIndex = model.getAutomatonIndex(parallelAutomata[automatonIndex].get().getName());
1092 EdgeIndexSet edgeIndex{model.encodeAutomatonAndEdgeIndices(modelAutomatonIndex, indexAndEdge.first)};
1093 result.back().addOriginData(boost::any(std::move(edgeIndex)));
1094 }
1095 }
1096 }
1097 } else {
1098 // If the element has more than one set of edges, we need to perform a synchronization.
1099 STORM_LOG_ASSERT(outputAndEdges.first, "Need output action index for synchronization.");
1100
1101 uint64_t outputActionIndex = outputAndEdges.first.get();
1102
1103 // Find out whether this combination is productive
1104 bool productiveCombination = true;
1105 // First check, whether each automaton has at least one edge with the current output and the current source location
1106 // We will also store the edges of each automaton with the current outputAction
1107 edgeSetsMemory.clear();
1108 for (auto const& automatonAndEdges : outputAndEdges.second) {
1109 uint64_t automatonIndex = automatonAndEdges.first;
1110 LocationsAndEdges const& locationsAndEdges = automatonAndEdges.second;
1111 auto edgesIt = locationsAndEdges.find(locations[automatonIndex]);
1112 if (edgesIt == locationsAndEdges.end()) {
1113 productiveCombination = false;
1114 break;
1115 }
1116 edgeSetsMemory.push_back(&edgesIt->second);
1117 }
1118
1119 if (productiveCombination) {
1120 // second, check whether each automaton has at least one enabled action
1121 edgeIteratorMemory.clear(); // Store the first enabled edge in each automaton.
1122 for (auto const& edgesIt : edgeSetsMemory) {
1123 bool atLeastOneEdge = false;
1124 EdgeSetWithIndices const& edgeSetWithIndices = *edgesIt;
1125 for (auto indexAndEdgeIt = edgeSetWithIndices.begin(), indexAndEdgeIte = edgeSetWithIndices.end(); indexAndEdgeIt != indexAndEdgeIte;
1126 ++indexAndEdgeIt) {
1127 // check whether we do not consider this edge
1128 if (edgeFilter != EdgeFilter::All) {
1129 STORM_LOG_ASSERT(edgeFilter == EdgeFilter::WithRate || edgeFilter == EdgeFilter::WithoutRate, "Unexpected edge filter.");
1130 if ((edgeFilter == EdgeFilter::WithRate) != indexAndEdgeIt->second->hasRate()) {
1131 continue;
1132 }
1133 }
1134
1135 if (!this->evaluator->asBool(indexAndEdgeIt->second->getGuard())) {
1136 continue;
1137 }
1138
1139 // If we reach this point, the edge is considered enabled.
1140 atLeastOneEdge = true;
1141 edgeIteratorMemory.push_back(indexAndEdgeIt);
1142 break;
1143 }
1144
1145 // If there is no enabled edge of this automaton, the whole combination is not productive.
1146 if (!atLeastOneEdge) {
1147 productiveCombination = false;
1148 break;
1149 }
1150 }
1151 }
1152
1153 // produce the combination
1154 if (productiveCombination) {
1155 AutomataEdgeSets automataEdgeSets;
1156 automataEdgeSets.reserve(outputAndEdges.second.size());
1157 STORM_LOG_ASSERT(edgeSetsMemory.size() == outputAndEdges.second.size(), "Unexpected number of edge sets stored.");
1158 STORM_LOG_ASSERT(edgeIteratorMemory.size() == outputAndEdges.second.size(), "Unexpected number of edge iterators stored.");
1159 auto edgeSetIt = edgeSetsMemory.begin();
1160 auto edgeIteratorIt = edgeIteratorMemory.begin();
1161 for (auto const& automatonAndEdges : outputAndEdges.second) {
1162 EdgeSetWithIndices enabledEdgesOfAutomaton;
1163 uint64_t automatonIndex = automatonAndEdges.first;
1164 EdgeSetWithIndices const& edgeSetWithIndices = **edgeSetIt;
1165 auto indexAndEdgeIt = *edgeIteratorIt;
1166 // The first edge where the edgeIterator points to is always enabled.
1167 enabledEdgesOfAutomaton.emplace_back(*indexAndEdgeIt);
1168 auto indexAndEdgeIte = edgeSetWithIndices.end();
1169 for (++indexAndEdgeIt; indexAndEdgeIt != indexAndEdgeIte; ++indexAndEdgeIt) {
1170 // check whether we do not consider this edge
1171 if (edgeFilter != EdgeFilter::All) {
1172 STORM_LOG_ASSERT(edgeFilter == EdgeFilter::WithRate || edgeFilter == EdgeFilter::WithoutRate, "Unexpected edge filter.");
1173 if ((edgeFilter == EdgeFilter::WithRate) != indexAndEdgeIt->second->hasRate()) {
1174 continue;
1175 }
1176 }
1177
1178 if (!this->evaluator->asBool(indexAndEdgeIt->second->getGuard())) {
1179 continue;
1180 }
1181 // If we reach this point, the edge is considered enabled.
1182 enabledEdgesOfAutomaton.emplace_back(*indexAndEdgeIt);
1183 }
1184 automataEdgeSets.emplace_back(std::move(automatonIndex), std::move(enabledEdgesOfAutomaton));
1185 ++edgeSetIt;
1186 ++edgeIteratorIt;
1187 }
1188 // insert choices in the result vector.
1189 expandSynchronizingEdgeCombination(automataEdgeSets, outputActionIndex, state, stateToIdCallback, result);
1190 }
1191 }
1192 }
1193
1194 return result;
1195}
1196
1197template<typename ValueType, typename StateType>
1198void JaniNextStateGenerator<ValueType, StateType>::checkGlobalVariableWritesValid(AutomataEdgeSets const& enabledEdges) const {
1199 // Todo: this also throws if the writes are on different assignment level
1200 // Todo: this also throws if the writes are on different elements of the same array
1201 std::map<storm::expressions::Variable, uint64_t> writtenGlobalVariables;
1202 for (auto edgeSetIt = enabledEdges.begin(), edgeSetIte = enabledEdges.end(); edgeSetIt != edgeSetIte; ++edgeSetIt) {
1203 for (auto const& indexAndEdge : edgeSetIt->second) {
1204 for (auto const& globalVariable : indexAndEdge.second->getWrittenGlobalVariables()) {
1205 auto it = writtenGlobalVariables.find(globalVariable);
1206
1207 auto index = std::distance(enabledEdges.begin(), edgeSetIt);
1208 if (it != writtenGlobalVariables.end()) {
1209 STORM_LOG_THROW(it->second == static_cast<uint64_t>(index), storm::exceptions::WrongFormatException,
1210 "Multiple writes to global variable '" << globalVariable.getName() << "' in synchronizing edges.");
1211 } else {
1212 writtenGlobalVariables.emplace(globalVariable, index);
1213 }
1214 }
1215 }
1216 }
1217}
1218
1219template<typename ValueType, typename StateType>
1221 return rewardExpressions.size();
1222}
1223
1224template<typename ValueType, typename StateType>
1226 return rewardModelInformation[index];
1227}
1228
1229template<typename ValueType, typename StateType>
1231 std::vector<StateType> const& initialStateIndices,
1232 std::vector<StateType> const& deadlockStateIndices,
1233 std::vector<StateType> const& unexploredStateIndices) {
1234 // As in JANI we can use transient boolean variable assignments in locations to identify states, we need to
1235 // create a list of boolean transient variables and the expressions that define them.
1236 std::vector<std::pair<std::string, storm::expressions::Expression>> transientVariableExpressions;
1237 for (auto const& variable : model.getGlobalVariables().getTransientVariables()) {
1238 if (variable.getType().isBasicType() && variable.getType().asBasicType().isBooleanType()) {
1239 if (this->options.isBuildAllLabelsSet() || this->options.getLabelNames().find(variable.getName()) != this->options.getLabelNames().end()) {
1240 transientVariableExpressions.emplace_back(variable.getName(), variable.getExpressionVariable().getExpression());
1241 }
1242 }
1243 }
1244 return NextStateGenerator<ValueType, StateType>::label(stateStorage, initialStateIndices, deadlockStateIndices, unexploredStateIndices,
1245 transientVariableExpressions);
1246}
1247
1248template<typename ValueType, typename StateType>
1250 std::vector<ValueType> result;
1251 result.reserve(rewardExpressions.size());
1252 for (auto const& rewardExpression : rewardExpressions) {
1253 result.push_back(this->evaluator->asRational(rewardExpression.second));
1254 }
1255 return result;
1256}
1257
1258template<typename ValueType, typename StateType>
1259void JaniNextStateGenerator<ValueType, StateType>::addEvaluatedRewardExpressions(std::vector<ValueType>& rewards, ValueType const& factor) const {
1260 assert(rewards.size() == rewardExpressions.size());
1261 auto rewIt = rewards.begin();
1262 for (auto const& rewardExpression : rewardExpressions) {
1263 (*rewIt) += factor * this->evaluator->asRational(rewardExpression.second);
1264 ++rewIt;
1265 }
1266}
1267
1268template<typename ValueType, typename StateType>
1269void JaniNextStateGenerator<ValueType, StateType>::buildRewardModelInformation() {
1270 for (auto const& rewardModel : rewardExpressions) {
1271 storm::jani::RewardModelInformation info(this->model, rewardModel.second);
1272 rewardModelInformation.emplace_back(rewardModel.first, info.hasStateRewards(), false, false);
1273 STORM_LOG_THROW(this->options.isScaleAndLiftTransitionRewardsSet() || !info.hasTransitionRewards(), storm::exceptions::NotSupportedException,
1274 "Transition rewards are not supported and a reduction to action-based rewards was not possible.");
1275 if (info.hasTransitionRewards()) {
1276 evaluateRewardExpressionsAtDestinations = true;
1277 }
1278 if (info.hasActionRewards() || (this->options.isScaleAndLiftTransitionRewardsSet() && info.hasTransitionRewards())) {
1279 hasStateActionRewards = true;
1280 rewardModelInformation.back().setHasStateActionRewards();
1281 }
1282 }
1283 if (!hasStateActionRewards) {
1284 evaluateRewardExpressionsAtDestinations = false;
1285 evaluateRewardExpressionsAtEdges = false;
1286 }
1287}
1288
1289template<typename ValueType, typename StateType>
1290void JaniNextStateGenerator<ValueType, StateType>::createSynchronizationInformation() {
1291 // Create synchronizing edges information.
1292 storm::jani::Composition const& topLevelComposition = this->model.getSystemComposition();
1293 if (topLevelComposition.isAutomatonComposition()) {
1294 auto const& automaton = this->model.getAutomaton(topLevelComposition.asAutomatonComposition().getAutomatonName());
1295 this->parallelAutomata.push_back(automaton);
1296
1297 LocationsAndEdges locationsAndEdges;
1298 uint64_t edgeIndex = 0;
1299 for (auto const& edge : automaton.getEdges()) {
1300 locationsAndEdges[edge.getSourceLocationIndex()].emplace_back(std::make_pair(edgeIndex, &edge));
1301 ++edgeIndex;
1302 }
1303
1304 AutomataAndEdges automataAndEdges;
1305 automataAndEdges.emplace_back(std::make_pair(0, std::move(locationsAndEdges)));
1306
1307 this->edges.emplace_back(std::make_pair(boost::none, std::move(automataAndEdges)));
1308 } else {
1309 STORM_LOG_THROW(topLevelComposition.isParallelComposition(), storm::exceptions::WrongFormatException, "Expected parallel composition.");
1310 storm::jani::ParallelComposition const& parallelComposition = topLevelComposition.asParallelComposition();
1311
1312 uint64_t automatonIndex = 0;
1313 for (auto const& composition : parallelComposition.getSubcompositions()) {
1314 STORM_LOG_THROW(composition->isAutomatonComposition(), storm::exceptions::WrongFormatException, "Expected flat parallel composition.");
1315 STORM_LOG_THROW(composition->asAutomatonComposition().getInputEnabledActions().empty(), storm::exceptions::NotSupportedException,
1316 "Input-enabled actions are not supported right now.");
1317
1318 this->parallelAutomata.push_back(this->model.getAutomaton(composition->asAutomatonComposition().getAutomatonName()));
1319
1320 // Add edges with silent action.
1321 LocationsAndEdges locationsAndEdges;
1322 uint64_t edgeIndex = 0;
1323 for (auto const& edge : parallelAutomata.back().get().getEdges()) {
1325 locationsAndEdges[edge.getSourceLocationIndex()].emplace_back(std::make_pair(edgeIndex, &edge));
1326 }
1327 ++edgeIndex;
1328 }
1329
1330 if (!locationsAndEdges.empty()) {
1331 AutomataAndEdges automataAndEdges;
1332 automataAndEdges.emplace_back(std::make_pair(automatonIndex, std::move(locationsAndEdges)));
1333 this->edges.emplace_back(std::make_pair(boost::none, std::move(automataAndEdges)));
1334 }
1335 ++automatonIndex;
1336 }
1337
1338 for (auto const& vector : parallelComposition.getSynchronizationVectors()) {
1339 uint64_t outputActionIndex = this->model.getActionIndex(vector.getOutput());
1340
1341 AutomataAndEdges automataAndEdges;
1342 bool atLeastOneEdge = true;
1343 uint64_t automatonIndex = 0;
1344 for (auto const& element : vector.getInput()) {
1346 LocationsAndEdges locationsAndEdges;
1347 uint64_t actionIndex = this->model.getActionIndex(element);
1348 uint64_t edgeIndex = 0;
1349 for (auto const& edge : parallelAutomata[automatonIndex].get().getEdges()) {
1350 if (edge.getActionIndex() == actionIndex) {
1351 locationsAndEdges[edge.getSourceLocationIndex()].emplace_back(std::make_pair(edgeIndex, &edge));
1352 }
1353 ++edgeIndex;
1354 }
1355 if (locationsAndEdges.empty()) {
1356 atLeastOneEdge = false;
1357 break;
1358 }
1359 automataAndEdges.emplace_back(std::make_pair(automatonIndex, std::move(locationsAndEdges)));
1360 }
1361 ++automatonIndex;
1362 }
1363
1364 if (atLeastOneEdge) {
1365 this->edges.emplace_back(std::make_pair(outputActionIndex, std::move(automataAndEdges)));
1366 }
1367 }
1368 }
1369
1370 STORM_LOG_TRACE("Number of synchronizations: " << this->edges.size() << ".");
1371}
1372
1373template<typename ValueType, typename StateType>
1374std::shared_ptr<storm::storage::sparse::ChoiceOrigins> JaniNextStateGenerator<ValueType, StateType>::generateChoiceOrigins(
1375 std::vector<boost::any>& dataForChoiceOrigins) const {
1376 if (!this->getOptions().isBuildChoiceOriginsSet()) {
1377 return nullptr;
1378 }
1379
1380 std::vector<uint_fast64_t> identifiers;
1381 identifiers.reserve(dataForChoiceOrigins.size());
1382
1383 std::map<EdgeIndexSet, uint_fast64_t> edgeIndexSetToIdentifierMap;
1384 // The empty edge set (i.e., the choices without origin) always has to get identifier getIdentifierForChoicesWithNoOrigin() -- which is assumed to be 0
1385 STORM_LOG_ASSERT(storm::storage::sparse::ChoiceOrigins::getIdentifierForChoicesWithNoOrigin() == 0, "The no origin identifier is assumed to be zero");
1386 edgeIndexSetToIdentifierMap.insert(std::make_pair(EdgeIndexSet(), 0));
1387 uint_fast64_t currentIdentifier = 1;
1388 for (boost::any& originData : dataForChoiceOrigins) {
1389 STORM_LOG_ASSERT(originData.empty() || boost::any_cast<EdgeIndexSet>(&originData) != nullptr,
1390 "Origin data has unexpected type: " << originData.type().name() << ".");
1391
1392 EdgeIndexSet currentEdgeIndexSet = originData.empty() ? EdgeIndexSet() : boost::any_cast<EdgeIndexSet>(std::move(originData));
1393 auto insertionRes = edgeIndexSetToIdentifierMap.emplace(std::move(currentEdgeIndexSet), currentIdentifier);
1394 identifiers.push_back(insertionRes.first->second);
1395 if (insertionRes.second) {
1396 ++currentIdentifier;
1397 }
1398 }
1399
1400 std::vector<EdgeIndexSet> identifierToEdgeIndexSetMapping(currentIdentifier);
1401 for (auto const& setIdPair : edgeIndexSetToIdentifierMap) {
1402 identifierToEdgeIndexSetMapping[setIdPair.second] = setIdPair.first;
1403 }
1404
1405 return std::make_shared<storm::storage::sparse::JaniChoiceOrigins>(std::make_shared<storm::jani::Model>(model), std::move(identifiers),
1406 std::move(identifierToEdgeIndexSetMapping));
1407}
1408
1409template<typename ValueType, typename StateType>
1411 STORM_LOG_WARN("There are no observation labels in JANI currenty");
1412 return storm::storage::BitVector(0);
1413}
1414
1415template<typename ValueType, typename StateType>
1416void JaniNextStateGenerator<ValueType, StateType>::checkValid() const {
1417 // If the program still contains undefined constants and we are not in a parametric setting, assemble an appropriate error message.
1418#ifdef STORM_HAVE_CARL
1419 if (!std::is_same<ValueType, storm::RationalFunction>::value && model.hasUndefinedConstants()) {
1420#else
1421 if (model.hasUndefinedConstants()) {
1422#endif
1423 std::vector<std::reference_wrapper<storm::jani::Constant const>> undefinedConstants = model.getUndefinedConstants();
1424 std::stringstream stream;
1425 bool printComma = false;
1426 for (auto const& constant : undefinedConstants) {
1427 if (printComma) {
1428 stream << ", ";
1429 } else {
1430 printComma = true;
1431 }
1432 stream << constant.get().getName() << " (" << constant.get().getType() << ")";
1433 }
1434 stream << ".";
1435 STORM_LOG_THROW(false, storm::exceptions::InvalidArgumentException, "Program still contains these undefined constants: " + stream.str());
1436 }
1437#ifdef STORM_HAVE_CARL
1438 else if (std::is_same<ValueType, storm::RationalFunction>::value && !model.undefinedConstantsAreGraphPreserving()) {
1439 STORM_LOG_THROW(false, storm::exceptions::InvalidArgumentException,
1440 "The input model contains undefined constants that influence the graph structure of the underlying model, which is not allowed.");
1441 }
1442#endif
1443}
1444
1445template class JaniNextStateGenerator<double>;
1446
1447#ifdef STORM_HAVE_CARL
1448template class JaniNextStateGenerator<storm::RationalNumber>;
1449template class JaniNextStateGenerator<storm::RationalFunction>;
1450#endif
1451} // namespace generator
1452} // namespace storm
uint64_t getReservedBitsForUnboundedVariables() const
BuilderOptions & substituteExpressions(std::function< storm::expressions::Expression(storm::expressions::Expression const &)> const &substitutionFunction)
Substitutes all expressions occurring in these options.
std::set< std::string > const & getLabelNames() const
Which labels are built.
ExpressionManager const & getManager() const
Retrieves the manager responsible for this expression.
bool isInitialized() const
Checks whether the object encapsulates a base-expression.
Expression integer(int_fast64_t value) const
Creates an expression that characterizes the given integer literal.
bool isBooleanType() const
Checks whether this type is a boolean type.
Definition Type.cpp:178
bool isIntegerType() const
Checks whether this type is an integral type.
Definition Type.cpp:182
bool isRationalType() const
Checks whether this type is a rational type.
Definition Type.cpp:214
storm::expressions::Expression getExpression() const
Retrieves an expression that represents the variable.
Definition Variable.cpp:34
void clear()
Clears this distribution.
ContainerType::iterator begin()
Access to iterators over the entries of the distribution.
void compress()
Compresses the internal storage by summing the values of entries which agree on the index.
ContainerType::iterator end()
void add(DistributionEntry< IndexType, ValueType > const &entry)
Adds the given entry to the distribution.
storm::storage::FlatSet< uint_fast64_t > EdgeIndexSet
virtual ModelType getModelType() const override
static storm::jani::ModelFeatures getSupportedJaniFeatures()
Returns the jani features with which this builder can deal natively.
virtual std::shared_ptr< storm::storage::sparse::ChoiceOrigins > generateChoiceOrigins(std::vector< boost::any > &dataForChoiceOrigins) const override
virtual void addStateValuation(storm::storage::sparse::state_type const &currentStateIndex, storm::storage::sparse::StateValuationsBuilder &valuationsBuilder) const override
Adds the valuation for the currently loaded state to the given builder.
virtual StateBehavior< ValueType, StateType > expand(StateToIdCallback const &stateToIdCallback) override
virtual std::vector< StateType > getInitialStates(StateToIdCallback const &stateToIdCallback) override
JaniNextStateGenerator(storm::jani::Model const &model, NextStateGeneratorOptions const &options=NextStateGeneratorOptions())
virtual storm::builder::RewardModelInformation getRewardModelInformation(uint64_t const &index) const override
virtual bool isPartiallyObservable() const override
virtual std::size_t getNumberOfRewardModels() const override
virtual storm::storage::sparse::StateValuationsBuilder initializeStateValuationsBuilder() const override
Initializes a builder for state valuations by adding the appropriate variables.
static bool canHandle(storm::jani::Model const &model)
A quick check to detect whether the given model is not supported.
NextStateGenerator< ValueType, StateType >::StateToIdCallback StateToIdCallback
virtual storm::models::sparse::StateLabeling label(storm::storage::sparse::StateStorage< StateType > const &stateStorage, std::vector< StateType > const &initialStateIndices={}, std::vector< StateType > const &deadlockStateIndices={}, std::vector< StateType > const &unexploredStateIndices={}) override
virtual void unpackTransientVariableValuesIntoEvaluator(CompressedState const &state, storm::expressions::ExpressionEvaluator< ValueType > &evaluator) const override
Sets the values of all transient variables in the current state to the given evaluator.
std::unique_ptr< storm::expressions::ExpressionEvaluator< ValueType > > evaluator
An evaluator used to evaluate expressions.
bool isSpecialLabel(std::string const &label) const
Checks if the input label has a special purpose (e.g.
void initializeSpecialStates()
Initializes the out-of-bounds state and states with overlapping guards.
virtual storm::storage::sparse::StateValuationsBuilder initializeStateValuationsBuilder() const
Initializes a builder for state valuations by adding the appropriate variables.
std::vector< std::pair< storm::expressions::Expression, bool > > terminalStates
The expressions that define terminal states.
NextStateGeneratorOptions options
The options to be used for next-state generation.
VariableInformation variableInformation
Information about how the variables are packed.
virtual storm::models::sparse::StateLabeling label(storm::storage::sparse::StateStorage< StateType > const &stateStorage, std::vector< StateType > const &initialStateIndices={}, std::vector< StateType > const &deadlockStateIndices={}, std::vector< StateType > const &unexploredStateIndices={})=0
void addChoice(Choice< ValueType, StateType > &&choice)
Adds the given choice to the behavior of the state.
void addStateRewards(std::vector< ValueType > &&stateRewards)
Adds the given state rewards to the behavior of the state.
void setExpanded(bool newValue=true)
Sets whether the state was expanded.
std::string const & getAutomatonName() const
Retrieves the name of the automaton this composition element refers to.
bool isBooleanType() const
Definition BasicType.cpp:20
virtual bool isAutomatonComposition() const
virtual bool isParallelComposition() const
AutomatonComposition const & asAutomatonComposition() const
ParallelComposition const & asParallelComposition() const
storm::expressions::Expression const & getProbability() const
Retrieves the probability of choosing this destination.
bool hasTransientAssignment() const
Retrieves whether this destination has transient assignments.
OrderedAssignments const & getOrderedAssignments() const
Retrieves the assignments to make when choosing this destination.
uint64_t getLocationIndex() const
Retrieves the id of the destination location.
uint64_t getActionIndex() const
Retrieves the id of the action with which this edge is labeled.
Definition Edge.cpp:45
bool hasRate() const
Retrieves whether this edge has an associated rate.
Definition Edge.cpp:49
uint64_t getSourceLocationIndex() const
Retrieves the index of the source location.
Definition Edge.cpp:41
OrderedAssignments const & getAssignments() const
Retrieves the assignments of this edge.
Definition Edge.cpp:89
storm::expressions::Expression const & getRate() const
Retrieves the rate of this edge.
Definition Edge.cpp:53
int64_t const & getHighestAssignmentLevel() const
Retrieves the highest assignment level occurring in a destination assignment If no assignment exists,...
Definition Edge.cpp:147
std::size_t getNumberOfDestinations() const
Retrieves the number of destinations of this edge.
Definition Edge.cpp:85
int64_t const & getLowestAssignmentLevel() const
Retrieves the lowest assignment level occurring in a destination assignment.
Definition Edge.cpp:143
EdgeDestination const & getDestination(uint64_t index) const
Retrieves the destination with the given index.
Definition Edge.cpp:73
virtual bool isBasicType() const
Definition JaniType.cpp:11
BasicType const & asBasicType() const
Definition JaniType.cpp:31
Jani Location:
Definition Location.h:15
OrderedAssignments const & getAssignments() const
Retrieves the assignments of this location.
Definition Location.cpp:23
ModelFeatures & add(ModelFeature const &modelFeature)
void remove(ModelFeature const &modelFeature)
bool hasUndefinedConstants() const
Retrieves whether the model still has undefined constants.
Definition Model.cpp:1083
storm::expressions::ExpressionManager & getManager() const
Retrieves the expression manager responsible for the expressions in the model.
Definition Model.cpp:113
std::vector< storm::expressions::Expression > getAllRangeExpressions(std::vector< std::reference_wrapper< storm::jani::Automaton const > > const &automata={}) const
Retrieves a list of expressions that characterize the legal values of the variables in this model.
Definition Model.cpp:1377
VariableSet & getGlobalVariables()
Retrieves the variables of this automaton.
Definition Model.cpp:721
storm::expressions::ExpressionManager & getExpressionManager() const
Retrieves the manager responsible for the expressions in the JANI model.
Definition Model.cpp:789
storm::expressions::Expression getRewardModelExpression(std::string const &identifier) const
Retrieves the defining reward expression of the reward model with the given identifier.
Definition Model.cpp:813
static uint64_t encodeAutomatonAndEdgeIndices(uint64_t automatonIndex, uint64_t edgeIndex)
Encode and decode a tuple of automaton and edge index in one 64-bit index.
Definition Model.cpp:1589
Composition const & getSystemComposition() const
Retrieves the system composition expression.
Definition Model.cpp:949
void liftTransientEdgeDestinationAssignments(int64_t maxLevel=0)
Lifts the common edge destination assignments of transient variables to edge assignments.
Definition Model.cpp:1545
storm::expressions::Expression getInitialStatesExpression() const
Retrieves the expression defining the legal initial values of the variables.
Definition Model.cpp:1312
static const uint64_t SILENT_ACTION_INDEX
The index of the silent action.
Definition Model.h:642
ModelType const & getModelType() const
Retrieves the type of the model.
Definition Model.cpp:121
bool hasNonTrivialRewardExpression() const
Returns true iff there is a non-trivial reward model, i.e., a reward model that does not consist of a...
Definition Model.cpp:793
bool undefinedConstantsAreGraphPreserving() const
Checks that undefined constants (parameters) of the model preserve the graph of the underlying model.
Definition Model.cpp:1486
void pushEdgeAssignmentsToDestinations()
Definition Model.cpp:1539
std::vector< std::pair< std::string, storm::expressions::Expression > > getAllRewardModelExpressions() const
Retrieves all available reward model names and expressions of the model.
Definition Model.cpp:841
bool isNonTrivialRewardModelExpression(std::string const &identifier) const
Returns true iff the given identifier corresponds to a non-trivial reward expression i....
Definition Model.cpp:797
bool isDeterministicModel() const
Determines whether this model is a deterministic one in the sense that each state only has one choice...
Definition Model.cpp:1369
void simplifyComposition()
Attempts to simplify the composition.
Definition Model.cpp:985
bool isDiscreteTimeModel() const
Determines whether this model is a discrete-time model.
Definition Model.cpp:1373
ModelFeatures const & getModelFeatures() const
Retrieves the enabled model features.
Definition Model.cpp:129
Automaton & getAutomaton(std::string const &name)
Retrieves the automaton with the given name.
Definition Model.cpp:888
bool hasNonTrivialInitialStates() const
Retrieves whether there are non-trivial initial states in the model or any of the contained automata.
Definition Model.cpp:1292
uint64_t getActionIndex(std::string const &name) const
Get the index of the action.
Definition Model.cpp:636
bool usesAssignmentLevels(bool onlyTransient=false) const
Retrieves whether the model uses an assignment level other than zero.
Definition Model.cpp:1560
uint64_t getAutomatonIndex(std::string const &name) const
Retrieves the index of the given automaton.
Definition Model.cpp:908
ArrayEliminatorData eliminateArrays(bool keepNonTrivialArrayAccess=false)
Eliminates occurring array variables and expressions by replacing array variables by multiple basic v...
Definition Model.cpp:1231
std::vector< std::reference_wrapper< Constant const > > getUndefinedConstants() const
Retrieves all undefined constants of the model.
Definition Model.cpp:1092
bool hasMultipleLevels(bool onlyTransient=false) const
Checks whether the assignments have several levels.
bool empty(bool onlyTransient=false) const
Retrieves whether this set of assignments is empty.
int64_t getLowestLevel(bool onlyTransient=false) const
Retrieves the lowest level among all assignments.
detail::ConstAssignments getNonTransientAssignments() const
Returns all non-transient assignments in this set of assignments.
detail::ConstAssignments getTransientAssignments() const
Returns all transient assignments in this set of assignments.
int64_t getHighestLevel(bool onlyTransient=false) const
Retrieves the highest level among all assignments.
static bool isNoActionInput(std::string const &action)
storm::expressions::Variable const & getExpressionVariable() const
Retrieves the associated expression variable.
Definition Variable.cpp:26
JaniType & getType()
Definition Variable.cpp:67
bool isTransient() const
Definition Variable.cpp:42
bool hasVariable(std::string const &name) const
Retrieves whether this variable set contains a variable with the given name.
Variable const & getVariable(std::string const &name) const
Retrieves the variable with the given name.
detail::ConstVariables< Variable > getTransientVariables() const
Retrieves the transient variables in this variable set.
This class manages the labeling of the state space with a number of (atomic) labels.
A bit vector that is internally represented as a vector of 64-bit values.
Definition BitVector.h:18
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.
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...
static uint_fast64_t getIdentifierForChoicesWithNoOrigin()
void addState(storm::storage::sparse::state_type const &state, std::vector< bool > &&booleanValues={}, std::vector< int64_t > &&integerValues={})
Adds a new state.
virtual std::unique_ptr< storm::solver::SmtSolver > create(storm::expressions::ExpressionManager &manager) const
Creates a new SMT solver instance.
Definition solver.cpp:124
#define STORM_LOG_INFO(message)
Definition logging.h:29
#define STORM_LOG_WARN(message)
Definition logging.h:30
#define STORM_LOG_DEBUG(message)
Definition logging.h:23
#define STORM_LOG_TRACE(message)
Definition logging.h:17
#define STORM_LOG_ASSERT(cond, message)
Definition macros.h:11
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:30
SFTBDDChecker::ValueType ValueType
Expression ite(Expression const &condition, Expression const &thenExpression, Expression const &elseExpression)
void unpackStateIntoEvaluator(CompressedState const &state, VariableInformation const &variableInformation, storm::expressions::ExpressionEvaluator< ValueType > &evaluator)
Unpacks the compressed state into the evaluator.
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.
storm::storage::BitVector CompressedState
bool isDiscreteTimeModel(ModelType const &modelType)
Definition ModelType.cpp:89
void forEach(std::vector< IteratorType > const &its, std::vector< IteratorType > const &ites, std::function< void(uint64_t, decltype(*std::declval< IteratorType >()))> const &setValueCallback, std::function< bool()> const &newCombinationCallback)
bool isConstant(ValueType const &)
Definition constants.cpp:66
bool isZero(ValueType const &a)
Definition constants.cpp:41
LabParser.cpp.
Definition cli.cpp:18
void addOriginData(boost::any const &data)
Adds the given data that specifies the origin of this choice w.r.t.
Definition Choice.cpp:116
void addRewards(std::vector< ValueType > &&values)
Adds the given choices rewards to this choice.
Definition Choice.cpp:169
void addProbability(StateType const &state, ValueType const &value)
Adds the given probability value to the given state in the underlying distribution.
Definition Choice.cpp:158
void registerArrayVariableReplacements(storm::jani::ArrayEliminatorData const &arrayEliminatorData)
storm::expressions::Expression transformExpression(storm::expressions::Expression const &arrayExpression) const