41template<
typename ValueType,
typename StateType>
48 std::vector<typename Generator::EdgeSetWithIndices::const_iterator>
iteratorList;
49 std::vector<typename Generator::EdgeSetWithIndices const*>
edgeSets;
64template<
typename ValueType,
typename StateType>
70template<
typename ValueType,
typename StateType>
75 hasStateActionRewards(false),
76 evaluateRewardExpressionsAtEdges(false),
77 evaluateRewardExpressionsAtDestinations(false),
85 if (features.hasArrays()) {
86 arrayEliminatorData = this->model.eliminateArrays(true);
87 this->options.substituteExpressions([this](storm::expressions::Expression const& exp) { return arrayEliminatorData.transformExpression(exp); });
90 STORM_LOG_THROW(features.empty(), storm::exceptions::NotSupportedException,
91 "The explicit next-state generator does not support the following model feature(s): " << features.toString() <<
".");
96 bool hasNonTrivialRewardExpressions =
false;
110 if (!hasNonTrivialRewardExpressions) {
111 for (
auto const& rewExpr : rewardExpressions) {
112 STORM_LOG_ASSERT(rewExpr.second.isVariable(),
"Expected trivial reward expression to be a variable. Got " << rewExpr.second <<
" instead.");
114 if (var.isTransient() && var.hasInitExpression() && !
storm::utility::isZero(var.getInitExpression().evaluateAsRational())) {
115 hasNonTrivialRewardExpressions =
true;
127 evaluateRewardExpressionsAtEdges =
true;
131 this->createSynchronizationInformation();
135 this->variableInformation =
137 this->variableInformation.registerArrayVariableReplacements(arrayEliminatorData);
139 this->transientVariableInformation.registerArrayVariableReplacements(arrayEliminatorData);
140 this->initializeSpecialStates();
143 this->evaluator = std::make_unique<storm::expressions::ExpressionEvaluator<ValueType>>(this->model.
getManager());
144 this->transientVariableInformation.setDefaultValuesInEvaluator(*this->evaluator);
147 buildRewardModelInformation();
152 if (expressionOrLabelAndBool.first.isExpression()) {
153 this->terminalStates.emplace_back(expressionOrLabelAndBool.first.getExpression(), expressionOrLabelAndBool.second);
156 if (!this->isSpecialLabel(expressionOrLabelAndBool.first.getLabel())) {
158 storm::exceptions::InvalidArgumentException,
159 "Terminal states refer to illegal label '" << expressionOrLabelAndBool.first.getLabel() <<
"'.");
163 storm::exceptions::InvalidArgumentException,
164 "Terminal states refer to non-boolean variable '" << expressionOrLabelAndBool.first.getLabel() <<
"'.");
166 "Terminal states refer to non-transient variable '" << expressionOrLabelAndBool.first.getLabel() <<
"'.");
177template<
typename ValueType,
typename StateType>
178JaniNextStateGenerator<ValueType, StateType>::~JaniNextStateGenerator() =
default;
180template<
typename ValueType,
typename StateType>
193template<
typename ValueType,
typename StateType>
195 auto features = model.getModelFeatures();
202 if (!features.empty()) {
203 STORM_LOG_INFO(
"The model can not be build as it contains these unsupported features: " << features.toString());
211template<
typename ValueType,
typename StateType>
213 switch (model.getModelType()) {
223 STORM_LOG_THROW(
false, storm::exceptions::WrongFormatException,
"Invalid model type.");
227template<
typename ValueType,
typename StateType>
229 return model.isDeterministicModel();
232template<
typename ValueType,
typename StateType>
234 return model.isDiscreteTimeModel();
237template<
typename ValueType,
typename StateType>
242template<
typename ValueType,
typename StateType>
244 if (locationVariable.
bitWidth == 0) {
251template<
typename ValueType,
typename StateType>
252void JaniNextStateGenerator<ValueType, StateType>::setLocation(CompressedState& state, LocationVariableInformation
const& locationVariable,
253 uint64_t locationIndex)
const {
254 if (locationVariable.bitWidth != 0) {
255 state.setFromInt(locationVariable.bitOffset, locationVariable.bitWidth, locationIndex);
259template<
typename ValueType,
typename StateType>
260std::vector<uint64_t> JaniNextStateGenerator<ValueType, StateType>::getLocations(CompressedState
const& state)
const {
261 std::vector<uint64_t> result;
262 getLocations(state, result);
266template<
typename ValueType,
typename StateType>
267void JaniNextStateGenerator<ValueType, StateType>::getLocations(CompressedState
const& state, std::vector<uint64_t>& result)
const {
268 result.resize(this->variableInformation.locationVariables.size());
270 auto resultIt = result.begin();
271 for (
auto it = this->variableInformation.locationVariables.begin(), ite = this->variableInformation.locationVariables.end(); it != ite; ++it, ++resultIt) {
272 if (it->bitWidth == 0) {
275 *resultIt = state.getAsInt(it->bitOffset, it->bitWidth);
280template<
typename ValueType,
typename StateType>
282 std::vector<StateType> initialStateIndices;
287 std::unique_ptr<storm::solver::SmtSolver>
solver = factory.
create(model.getExpressionManager());
289 std::vector<storm::expressions::Expression> rangeExpressions = model.getAllRangeExpressions(this->parallelAutomata);
290 for (
auto const& expression : rangeExpressions) {
293 solver->add(model.getInitialStatesExpression(this->parallelAutomata));
303 std::shared_ptr<storm::solver::SmtSolver::ModelReference> model =
solver->getModel();
305 bool variableValue = model->getBooleanValue(booleanVariable.variable);
307 blockingExpression = blockingExpression.
isInitialized() ? blockingExpression || localBlockingExpression : localBlockingExpression;
308 initialState.
set(booleanVariable.bitOffset, variableValue);
311 int_fast64_t variableValue = model->getIntegerValue(integerVariable.variable);
312 if (integerVariable.forceOutOfBoundsCheck || this->getOptions().isExplorationChecksSet()) {
313 STORM_LOG_THROW(variableValue >= integerVariable.lowerBound, storm::exceptions::WrongFormatException,
314 "The initial value for variable " << integerVariable.variable.getName() <<
" is lower than the lower bound.");
315 STORM_LOG_THROW(variableValue <= integerVariable.upperBound, storm::exceptions::WrongFormatException,
316 "The initial value for variable " << integerVariable.variable.getName() <<
" is higher than the upper bound.");
319 blockingExpression = blockingExpression.
isInitialized() ? blockingExpression || localBlockingExpression : localBlockingExpression;
320 initialState.
setFromInt(integerVariable.bitOffset, integerVariable.bitWidth,
321 static_cast<uint_fast64_t
>(variableValue - integerVariable.lowerBound));
325 std::vector<std::set<uint64_t>::const_iterator> initialLocationsIts;
326 std::vector<std::set<uint64_t>::const_iterator> initialLocationsItes;
327 for (
auto const& automatonRef : this->parallelAutomata) {
328 auto const& automaton = automatonRef.get();
329 initialLocationsIts.push_back(automaton.getInitialLocationIndices().cbegin());
330 initialLocationsItes.push_back(automaton.getInitialLocationIndices().cend());
333 initialLocationsIts, initialLocationsItes,
334 [
this, &initialState](uint64_t index, uint64_t value) { setLocation(initialState, this->
variableInformation.locationVariables[index], value); },
335 [&stateToIdCallback, &initialStateIndices, &initialState]() {
337 StateType
id = stateToIdCallback(initialState);
338 initialStateIndices.push_back(
id);
346 solver->add(blockingExpression);
349 STORM_LOG_DEBUG(
"Enumerated " << initialStateIndices.size() <<
" initial states using SMT solving.");
352 std::vector<std::vector<uint64_t>> allValues;
353 for (
auto const& aRef : this->parallelAutomata) {
354 auto const& aInitLocs = aRef.get().getInitialLocationIndices();
355 allValues.emplace_back(aInitLocs.begin(), aInitLocs.end());
357 uint64_t locEndIndex = allValues.size();
359 STORM_LOG_ASSERT(intVar.lowerBound <= intVar.upperBound,
"Expecting variable with non-empty set of possible values.");
363 uint64_t intEndIndex = allValues.size();
365 allValues.resize(allValues.size() + this->variableInformation.booleanVariables.size(),
366 std::vector<uint64_t>({static_cast<uint64_t>(0), static_cast<uint64_t>(1)}));
368 std::vector<std::vector<uint64_t>::const_iterator> its;
369 std::vector<std::vector<uint64_t>::const_iterator> ites;
370 for (
auto const& valVec : allValues) {
371 its.push_back(valVec.cbegin());
372 ites.push_back(valVec.cend());
379 [
this, &initialState, &locEndIndex, &intEndIndex](uint64_t index, uint64_t value) {
381 if (index < locEndIndex) {
384 }
else if (index < intEndIndex) {
387 initialState.
setFromInt(intVar.bitOffset, intVar.bitWidth, value);
393 initialState.
set(boolVar.bitOffset,
static_cast<bool>(value));
396 [&stateToIdCallback, &initialStateIndices, &initialState]() {
398 StateType
id = stateToIdCallback(initialState);
399 initialStateIndices.push_back(
id);
402 STORM_LOG_DEBUG(
"Enumerated " << initialStateIndices.size() <<
" initial states using brute force enumeration.");
404 return initialStateIndices;
407template<
typename ValueType,
typename StateType>
416 auto assignmentIt = assignments.
begin();
417 auto assignmentIte = assignments.end();
420 auto boolIt = this->variableInformation.booleanVariables.begin();
421 for (; assignmentIt != assignmentIte && assignmentIt->lValueIsVariable() && assignmentIt->getExpressionVariable().hasBooleanType(); ++assignmentIt) {
422 while (assignmentIt->getExpressionVariable() != boolIt->variable) {
425 state.
set(boolIt->bitOffset, expressionEvaluator.asBool(assignmentIt->getAssignedExpression()));
429 auto integerIt = this->variableInformation.integerVariables.begin();
430 for (; assignmentIt != assignmentIte && assignmentIt->lValueIsVariable() && assignmentIt->getExpressionVariable().hasIntegerType(); ++assignmentIt) {
431 while (assignmentIt->getExpressionVariable() != integerIt->variable) {
434 int_fast64_t assignedValue = expressionEvaluator.asInt(assignmentIt->getAssignedExpression());
436 if (assignedValue < integerIt->lowerBound || assignedValue > integerIt->upperBound) {
437 state = this->outOfBoundsState;
439 }
else if (integerIt->forceOutOfBoundsCheck || this->options.isExplorationChecksSet()) {
440 STORM_LOG_THROW(assignedValue >= integerIt->lowerBound, storm::exceptions::WrongFormatException,
441 "The update " << assignmentIt->getExpressionVariable().getName() <<
" := " << assignmentIt->getAssignedExpression()
442 <<
" leads to an out-of-bounds value (" << assignedValue <<
") for the variable '"
443 << assignmentIt->getExpressionVariable().getName() <<
"'.");
444 STORM_LOG_THROW(assignedValue <= integerIt->upperBound, storm::exceptions::WrongFormatException,
445 "The update " << assignmentIt->getExpressionVariable().getName() <<
" := " << assignmentIt->getAssignedExpression()
446 <<
" leads to an out-of-bounds value (" << assignedValue <<
") for the variable '"
447 << assignmentIt->getExpressionVariable().getName() <<
"'.");
449 state.
setFromInt(integerIt->bitOffset, integerIt->bitWidth, assignedValue - integerIt->lowerBound);
450 STORM_LOG_ASSERT(
static_cast<int_fast64_t
>(state.
getAsInt(integerIt->bitOffset, integerIt->bitWidth)) + integerIt->lowerBound == assignedValue,
451 "Writing to the bit vector bucket failed (read " << state.
getAsInt(integerIt->bitOffset, integerIt->bitWidth) <<
" but wrote "
452 << assignedValue <<
").");
455 for (; assignmentIt != assignmentIte && assignmentIt->lValueIsArrayAccess(); ++assignmentIt) {
456 auto const& arrayIndicesAsExpr = assignmentIt->getLValue().getArrayIndexVector();
457 std::vector<uint64_t> arrayIndices;
458 arrayIndices.reserve(arrayIndicesAsExpr.size());
459 for (
auto const& i : arrayIndicesAsExpr) {
460 arrayIndices.push_back(
static_cast<uint64_t
>(expressionEvaluator.asInt(i)));
462 if (assignmentIt->getAssignedExpression().hasIntegerType()) {
463 IntegerVariableInformation
const& intInfo =
464 this->variableInformation.getIntegerArrayVariableReplacement(assignmentIt->getLValue().getVariable().getExpressionVariable(), arrayIndices);
465 int_fast64_t assignedValue = expressionEvaluator.asInt(assignmentIt->getAssignedExpression());
468 if (assignedValue < intInfo.lowerBound || assignedValue > intInfo.upperBound) {
469 state = this->outOfBoundsState;
472 STORM_LOG_THROW(assignedValue >= intInfo.lowerBound, storm::exceptions::WrongFormatException,
473 "The update " << assignmentIt->getLValue() <<
" := " << assignmentIt->getAssignedExpression()
474 <<
" leads to an out-of-bounds value (" << assignedValue <<
") for the variable '"
475 << assignmentIt->getExpressionVariable().getName() <<
"'.");
476 STORM_LOG_THROW(assignedValue <= intInfo.upperBound, storm::exceptions::WrongFormatException,
477 "The update " << assignmentIt->getLValue() <<
" := " << assignmentIt->getAssignedExpression()
478 <<
" leads to an out-of-bounds value (" << assignedValue <<
") for the variable '"
479 << assignmentIt->getExpressionVariable().getName() <<
"'.");
481 state.
setFromInt(intInfo.bitOffset, intInfo.bitWidth, assignedValue - intInfo.lowerBound);
482 STORM_LOG_ASSERT(
static_cast<int_fast64_t
>(state.
getAsInt(intInfo.bitOffset, intInfo.bitWidth)) + intInfo.lowerBound == assignedValue,
483 "Writing to the bit vector bucket failed (read " << state.
getAsInt(intInfo.bitOffset, intInfo.bitWidth) <<
" but wrote "
484 << assignedValue <<
").");
485 }
else if (assignmentIt->getAssignedExpression().hasBooleanType()) {
486 BooleanVariableInformation
const& boolInfo =
487 this->variableInformation.getBooleanArrayVariableReplacement(assignmentIt->getLValue().getVariable().getExpressionVariable(), arrayIndices);
488 state.
set(boolInfo.bitOffset, expressionEvaluator.asBool(assignmentIt->getAssignedExpression()));
490 STORM_LOG_THROW(
false, storm::exceptions::UnexpectedException,
"Unhandled type of base variable.");
495 STORM_LOG_ASSERT(assignmentIt == assignmentIte,
"Not all assignments were consumed.");
498template<
typename ValueType,
typename StateType>
499void JaniNextStateGenerator<ValueType, StateType>::applyTransientUpdate(TransientVariableValuation<ValueType>& transientValuation,
501 storm::expressions::ExpressionEvaluator<ValueType>
const& expressionEvaluator)
const {
502 auto assignmentIt = transientAssignments.
begin();
503 auto assignmentIte = transientAssignments.
end();
506 auto boolIt = this->transientVariableInformation.booleanVariableInformation.begin();
507 for (; assignmentIt != assignmentIte && assignmentIt->lValueIsVariable() && assignmentIt->getExpressionVariable().hasBooleanType(); ++assignmentIt) {
508 while (assignmentIt->getExpressionVariable() != boolIt->variable) {
511 transientValuation.booleanValues.emplace_back(&(*boolIt), expressionEvaluator.asBool(assignmentIt->getAssignedExpression()));
514 auto integerIt = this->transientVariableInformation.integerVariableInformation.begin();
515 for (; assignmentIt != assignmentIte && assignmentIt->lValueIsVariable() && assignmentIt->getExpressionVariable().hasIntegerType(); ++assignmentIt) {
516 while (assignmentIt->getExpressionVariable() != integerIt->variable) {
519 int64_t assignedValue = expressionEvaluator.asInt(assignmentIt->getAssignedExpression());
521 STORM_LOG_THROW(!integerIt->lowerBound || assignedValue >= integerIt->lowerBound.get(), storm::exceptions::WrongFormatException,
522 "The update " << assignmentIt->getExpressionVariable().getName() <<
" := " << assignmentIt->getAssignedExpression()
523 <<
" leads to an out-of-bounds value (" << assignedValue <<
") for the variable '"
524 << assignmentIt->getExpressionVariable().getName() <<
"'.");
525 STORM_LOG_THROW(!integerIt->upperBound || assignedValue <= integerIt->upperBound.get(), storm::exceptions::WrongFormatException,
526 "The update " << assignmentIt->getExpressionVariable().getName() <<
" := " << assignmentIt->getAssignedExpression()
527 <<
" leads to an out-of-bounds value (" << assignedValue <<
") for the variable '"
528 << assignmentIt->getExpressionVariable().getName() <<
"'.");
530 transientValuation.integerValues.emplace_back(&(*integerIt), assignedValue);
533 auto rationalIt = this->transientVariableInformation.rationalVariableInformation.begin();
534 for (; assignmentIt != assignmentIte && assignmentIt->lValueIsVariable() && assignmentIt->getExpressionVariable().hasRationalType(); ++assignmentIt) {
535 while (assignmentIt->getExpressionVariable() != rationalIt->variable) {
538 transientValuation.rationalValues.emplace_back(&(*rationalIt), expressionEvaluator.asRational(assignmentIt->getAssignedExpression()));
542 for (; assignmentIt != assignmentIte && assignmentIt->lValueIsArrayAccess(); ++assignmentIt) {
543 auto const& arrayIndicesAsExpr = assignmentIt->getLValue().getArrayIndexVector();
544 std::vector<uint64_t> arrayIndices;
545 arrayIndices.reserve(arrayIndicesAsExpr.size());
546 for (
auto const& i : arrayIndicesAsExpr) {
547 arrayIndices.push_back(
static_cast<uint64_t
>(expressionEvaluator.asInt(i)));
549 storm::expressions::Type
const& baseType = assignmentIt->getLValue().getVariable().getExpressionVariable().getType();
551 auto const& intInfo = this->transientVariableInformation.getIntegerArrayVariableReplacement(
552 assignmentIt->getLValue().getVariable().getExpressionVariable(), arrayIndices);
553 int64_t assignedValue = expressionEvaluator.asInt(assignmentIt->getAssignedExpression());
555 STORM_LOG_THROW(assignedValue >= intInfo.lowerBound, storm::exceptions::WrongFormatException,
556 "The update " << assignmentIt->getLValue() <<
" := " << assignmentIt->getAssignedExpression()
557 <<
" leads to an out-of-bounds value (" << assignedValue <<
") for the variable '"
558 << assignmentIt->getExpressionVariable().getName() <<
"'.");
559 STORM_LOG_THROW(assignedValue <= intInfo.upperBound, storm::exceptions::WrongFormatException,
560 "The update " << assignmentIt->getLValue() <<
" := " << assignmentIt->getAssignedExpression()
561 <<
" leads to an out-of-bounds value (" << assignedValue <<
") for the variable '"
562 << assignmentIt->getExpressionVariable().getName() <<
"'.");
564 transientValuation.integerValues.emplace_back(&intInfo, assignedValue);
566 auto const& boolInfo = this->transientVariableInformation.getBooleanArrayVariableReplacement(
567 assignmentIt->getLValue().getVariable().getExpressionVariable(), arrayIndices);
568 transientValuation.booleanValues.emplace_back(&boolInfo, expressionEvaluator.asBool(assignmentIt->getAssignedExpression()));
570 auto const& rationalInfo = this->transientVariableInformation.getRationalArrayVariableReplacement(
571 assignmentIt->getLValue().getVariable().getExpressionVariable(), arrayIndices);
572 transientValuation.rationalValues.emplace_back(&rationalInfo, expressionEvaluator.asRational(assignmentIt->getAssignedExpression()));
574 STORM_LOG_THROW(
false, storm::exceptions::UnexpectedException,
"Unhandled type of base variable.");
579 STORM_LOG_ASSERT(assignmentIt == assignmentIte,
"Not all assignments were consumed.");
582template<
typename ValueType,
typename StateType>
583TransientVariableValuation<ValueType> JaniNextStateGenerator<ValueType, StateType>::getTransientVariableValuationAtLocations(
584 std::vector<uint64_t>
const& locations, storm::expressions::ExpressionEvaluator<ValueType>
const& evaluator)
const {
585 TransientVariableValuation<ValueType> transientVariableValuation;
586 getTransientVariableValuationAtLocations(locations, evaluator, transientVariableValuation);
587 return transientVariableValuation;
590template<
typename ValueType,
typename StateType>
591void JaniNextStateGenerator<ValueType, StateType>::getTransientVariableValuationAtLocations(
592 std::vector<uint64_t>
const& locations, storm::expressions::ExpressionEvaluator<ValueType>
const& evaluator,
593 TransientVariableValuation<ValueType>& transientVariableValuation)
const {
594 transientVariableValuation.clear();
595 uint64_t automatonIndex = 0;
596 for (
auto const& automatonRef : this->parallelAutomata) {
597 auto const& automaton = automatonRef.get();
598 uint64_t currentLocationIndex = locations[automatonIndex];
599 storm::jani::Location
const& location = automaton.getLocation(currentLocationIndex);
606template<
typename ValueType,
typename StateType>
609 transientVariableInformation.setDefaultValuesInEvaluator(
evaluator);
610 auto transientVariableValuation = getTransientVariableValuationAtLocations(getLocations(
state),
evaluator);
611 transientVariableValuation.setInEvaluator(
evaluator, this->
getOptions().isExplorationChecksSet());
614template<
typename ValueType,
typename StateType>
621 builder.addIntegerVariable(v.variable, 0, v.highestValue);
624 builder.addBooleanVariable(v.variable);
627 builder.addIntegerVariable(v.variable, v.lowerBound, v.upperBound);
630 for (
auto const& varInfo : transientVariableInformation.booleanVariableInformation) {
631 builder.addBooleanVariable(varInfo.variable);
633 for (
auto const& varInfo : transientVariableInformation.integerVariableInformation) {
634 builder.addIntegerVariable(varInfo.variable, varInfo.lowerBound.value_or(std::numeric_limits<int64_t>::min()),
635 varInfo.upperBound.value_or(std::numeric_limits<int64_t>::max()));
637 for (
auto const& varInfo : transientVariableInformation.rationalVariableInformation) {
638 if (std::is_same_v<ValueType, storm::RationalNumber>) {
639 uint64_t
const bitSize = std::max<uint64_t>(64, this->
getOptions().getReservedBitsForUnboundedVariables());
640 builder.addRationalVariable(varInfo.variable, bitSize * 2);
642 STORM_LOG_THROW((std::is_same_v<ValueType, double>), storm::exceptions::NotSupportedException,
643 "State valuations for transient variables of the given value type are not supported.");
644 builder.addDoubleVariable(varInfo.variable);
650template<
typename ValueType,
typename StateType>
656 auto transientVariableValuation = getTransientVariableValuationAtLocations(getLocations(*this->state), *this->evaluator);
657 transientVariableValuation.setInValuations(currentStateIndex, transientVariableInformation, valuations.
getStorage());
660template<
typename ValueType,
typename StateType>
661bool JaniNextStateGenerator<ValueType, StateType>::evaluatorHoldsState(
CompressedState const& state)
const {
662 auto const& info = this->variableInformation;
664 if (scratch->variableExpressionsForAssertions.empty()) {
665 for (
auto const& v : info.locationVariables) {
666 scratch->variableExpressionsForAssertions.push_back(v.variable.getExpression());
668 for (
auto const& v : info.booleanVariables) {
669 scratch->variableExpressionsForAssertions.push_back(v.variable.getExpression());
671 for (
auto const& v : info.integerVariables) {
672 scratch->variableExpressionsForAssertions.push_back(v.variable.getExpression());
677 auto const exactlyRepresentable = [](int64_t value) {
return value > -(int64_t(1) << 52) && value < (int64_t(1) << 52); };
678 auto const holdsInteger = [&](storm::expressions::Variable
const& variable, storm::expressions::Expression
const& expression) {
679 int64_t
const expectedValue = expected.getIntegerValue(variable);
680 return !exactlyRepresentable(expectedValue) || this->evaluator->asInt(expression) == expectedValue;
682 auto expressionIt = scratch->variableExpressionsForAssertions.begin();
683 for (
auto const& v : info.locationVariables) {
684 if (!holdsInteger(v.variable, *expressionIt++)) {
688 for (
auto const& v : info.booleanVariables) {
689 if (this->evaluator->asBool(*expressionIt++) != expected.getBooleanValue(v.variable)) {
693 for (
auto const& v : info.integerVariables) {
694 if (!holdsInteger(v.variable, *expressionIt++)) {
701template<
typename ValueType,
typename StateType>
702void JaniNextStateGenerator<ValueType, StateType>::setEvaluatorState(CompressedState
const& state) {
703 STORM_LOG_ASSERT(state.size() == scratch->evaluatorState.size(),
"Unexpected state size.");
704 STORM_LOG_ASSERT(evaluatorHoldsState(scratch->evaluatorState),
"The evaluator does not hold the expected state.");
706 scratch->evaluatorState = state;
709template<
typename ValueType,
typename StateType>
718 scratch->evaluatorState = *this->state;
719 STORM_LOG_ASSERT(evaluatorHoldsState(*this->state),
"The state to expand must be loaded into the evaluator (see load).");
722 std::vector<uint64_t>& locations = scratch->locations;
723 getLocations(*this->state, locations);
727 getTransientVariableValuationAtLocations(locations, *this->evaluator, scratch->transientValuation);
728 scratch->transientValuation.setInEvaluator(*this->evaluator, this->
getOptions().isExplorationChecksSet());
735 if (this->evaluator->asBool(expressionBool.first) == expressionBool.second) {
737 this->transientVariableInformation.setDefaultValuesInEvaluator(*this->evaluator);
744 this->transientVariableInformation.setDefaultValuesInEvaluator(*this->evaluator);
748 if (this->
getOptions().isApplyMaximalProgressAssumptionSet()) {
751 if (result.
empty()) {
756 getActionChoices(locations, *this->state, stateToIdCallback,
EdgeFilter::All, result);
762 if (totalNumberOfChoices == 0) {
779 for (
auto const& choice : result) {
780 for (
auto const& stateProbabilityPair : choice) {
782 globalChoice.
addProbability(stateProbabilityPair.first, stateProbabilityPair.second / totalNumberOfChoices);
784 globalChoice.
addProbability(stateProbabilityPair.first, stateProbabilityPair.second);
789 totalExitRate += choice.getTotalMass();
794 for (
auto const& choice : result) {
795 if (hasStateActionRewards) {
796 for (uint_fast64_t rewardVariableIndex = 0; rewardVariableIndex < rewardExpressions.size(); ++rewardVariableIndex) {
797 stateActionRewards[rewardVariableIndex] += choice.getRewards()[rewardVariableIndex] * choice.getTotalMass() / totalExitRate;
805 globalChoice.
addRewards(std::move(stateActionRewards));
808 result.clearChoices();
809 result.addChoice(std::move(globalChoice));
817template<
typename ValueType,
typename StateType>
823 boost::optional<ValueType> exitRate = boost::none;
825 exitRate = this->evaluator->asRational(edge.
getRate());
828 Choice<ValueType>& choice = behavior.
startNewChoice(outputActionIndex,
static_cast<bool>(exitRate));
829 std::vector<ValueType>& stateActionRewards = choice.getRewards();
832 TransientVariableValuation<ValueType>& transientVariableValuation = scratch->transientValuation;
833 transientVariableValuation.clear();
839 transientVariableValuation.clear();
841 transientVariableValuation.setInEvaluator(*this->evaluator, this->getOptions().isExplorationChecksSet());
843 evaluateRewardExpressions(stateActionRewards);
844 transientVariableInformation.setDefaultValuesInEvaluator(*this->evaluator);
853 bool evaluatorChanged =
false;
861 applyUpdate(newState, destination, this->variableInformation.locationVariables[automatonIndex], assignmentLevel, *this->evaluator);
862 if (hasTransientAssignments) {
864 "Transition rewards are not supported and scaling to action rewards is disabled.");
865 transientVariableValuation.clear();
868 transientVariableValuation.setInEvaluator(*this->evaluator, this->getOptions().isExplorationChecksSet());
869 evaluatorChanged =
true;
871 if (assignmentLevel < highestLevel) {
872 while (assignmentLevel < highestLevel) {
874 setEvaluatorState(newState);
875 evaluatorChanged =
true;
876 applyUpdate(newState, destination, this->variableInformation.locationVariables[automatonIndex], assignmentLevel, *this->evaluator);
877 if (hasTransientAssignments) {
878 transientVariableValuation.clear();
881 transientVariableValuation.setInEvaluator(*this->evaluator, this->getOptions().isExplorationChecksSet());
882 evaluatorChanged =
true;
886 if (evaluateRewardExpressionsAtDestinations) {
887 setEvaluatorState(newState);
888 evaluatorChanged =
true;
889 addEvaluatedRewardExpressions(stateActionRewards, probability);
892 if (evaluatorChanged) {
894 setEvaluatorState(state);
895 if (hasTransientAssignments) {
896 this->transientVariableInformation.setDefaultValuesInEvaluator(*this->evaluator);
900 StateType stateIndex = stateToIdCallback(newState);
903 probability = exitRate ? exitRate.get() * probability : probability;
904 choice.addProbability(stateIndex, probability);
907 probabilitySum += probability;
915 storm::exceptions::WrongFormatException,
"Probabilities do not sum to one for edge (actually sum to " << probabilitySum <<
").");
921template<
typename ValueType,
typename StateType>
922void JaniNextStateGenerator<ValueType, StateType>::generateSynchronizedDistribution(storm::storage::BitVector
const& state,
923 AutomataEdgeSets
const& edgeCombination,
924 std::vector<EdgeSetWithIndices::const_iterator>
const& iteratorList,
925 storm::generator::Distribution<StateType, ValueType>& distribution,
926 std::vector<ValueType>& stateActionRewards, EdgeIndexSet& edgeIndices,
927 StateToIdCallback
const& stateToIdCallback) {
929 int64_t lowestDestinationAssignmentLevel = std::numeric_limits<int64_t>::max();
930 int64_t highestDestinationAssignmentLevel = std::numeric_limits<int64_t>::min();
931 int64_t lowestEdgeAssignmentLevel = std::numeric_limits<int64_t>::max();
932 int64_t highestEdgeAssignmentLevel = std::numeric_limits<int64_t>::min();
933 uint64_t numDestinations = 1;
934 for (uint_fast64_t i = 0;
i < iteratorList.size(); ++
i) {
935 if (this->getOptions().isBuildChoiceOriginsSet()) {
936 auto automatonIndex = model.
getAutomatonIndex(parallelAutomata[edgeCombination[i].first].get().getName());
939 storm::jani::Edge
const& edge = *iteratorList[
i]->second;
950 TransientVariableValuation<ValueType>& transientVariableValuation = scratch->transientValuation;
951 transientVariableValuation.clear();
952 if (evaluateRewardExpressionsAtEdges && lowestEdgeAssignmentLevel <= highestEdgeAssignmentLevel) {
953 for (int64_t assignmentLevel = lowestEdgeAssignmentLevel; assignmentLevel <= highestEdgeAssignmentLevel; ++assignmentLevel) {
954 transientVariableValuation.clear();
955 for (uint_fast64_t i = 0;
i < iteratorList.size(); ++
i) {
956 storm::jani::Edge
const& edge = *iteratorList[
i]->second;
959 transientVariableValuation.setInEvaluator(*this->evaluator, this->getOptions().isExplorationChecksSet());
962 transientVariableInformation.setDefaultValuesInEvaluator(*this->evaluator);
965 std::vector<storm::jani::EdgeDestination const*>& destinations = scratch->destinations;
966 std::vector<LocationVariableInformation const*>& locationVars = scratch->locationVars;
968 for (uint64_t destinationId = 0; destinationId < numDestinations; ++destinationId) {
970 destinations.clear();
971 locationVars.clear();
972 transientVariableValuation.clear();
974 successorState = state;
977 uint64_t destinationIndex = destinationId;
978 for (uint64_t i = 0;
i < iteratorList.size(); ++
i) {
979 storm::jani::Edge
const& edge = *iteratorList[
i]->second;
982 destinations.push_back(&edge.
getDestination(localDestinationIndex));
983 locationVars.push_back(&this->variableInformation.locationVariables[edgeCombination[i].first]);
985 ValueType probability = this->evaluator->asRational(destinations.back()->getProbability());
987 successorProbability *= probability * this->evaluator->asRational(edge.
getRate());
989 successorProbability *= probability;
995 applyUpdate(successorState, *destinations.back(), *locationVars.back(), lowestDestinationAssignmentLevel, *this->evaluator);
996 applyTransientUpdate(transientVariableValuation,
997 destinations.back()->getOrderedAssignments().getTransientAssignments(lowestDestinationAssignmentLevel), *this->evaluator);
1001 bool evaluatorChanged =
false;
1003 for (int64_t assignmentLevel = lowestDestinationAssignmentLevel + 1; assignmentLevel <= highestDestinationAssignmentLevel; ++assignmentLevel) {
1004 setEvaluatorState(successorState);
1005 transientVariableValuation.setInEvaluator(*this->evaluator, this->getOptions().isExplorationChecksSet());
1006 transientVariableValuation.clear();
1007 evaluatorChanged =
true;
1008 auto locationVarIt = locationVars.begin();
1009 for (
auto const& destPtr : destinations) {
1010 applyUpdate(successorState, *destPtr, **locationVarIt, assignmentLevel, *this->evaluator);
1011 applyTransientUpdate(transientVariableValuation, destinations.back()->getOrderedAssignments().getTransientAssignments(assignmentLevel),
1016 if (!transientVariableValuation.empty()) {
1017 evaluatorChanged =
true;
1018 transientVariableValuation.setInEvaluator(*this->evaluator, this->getOptions().isExplorationChecksSet());
1020 if (evaluateRewardExpressionsAtDestinations) {
1021 setEvaluatorState(successorState);
1022 evaluatorChanged =
true;
1023 addEvaluatedRewardExpressions(stateActionRewards, successorProbability);
1025 if (evaluatorChanged) {
1027 setEvaluatorState(state);
1028 this->transientVariableInformation.setDefaultValuesInEvaluator(*this->evaluator);
1031 StateType
id = stateToIdCallback(successorState);
1032 distribution.
add(
id, successorProbability);
1037template<
typename ValueType,
typename StateType>
1038void JaniNextStateGenerator<ValueType, StateType>::expandSynchronizingEdgeCombination(AutomataEdgeSets
const& edgeCombination, uint64_t outputActionIndex,
1039 CompressedState
const& state, StateToIdCallback
const& stateToIdCallback,
1040 StateBehavior<ValueType, StateType>& behavior) {
1043 checkGlobalVariableWritesValid(edgeCombination);
1046 std::vector<EdgeSetWithIndices::const_iterator>& iteratorList = scratch->iteratorList;
1047 iteratorList.resize(edgeCombination.size());
1050 for (
size_t i = 0;
i < edgeCombination.size(); ++
i) {
1051 iteratorList[
i] = edgeCombination[
i].second.cbegin();
1054 storm::generator::Distribution<StateType, ValueType>& distribution = scratch->distribution;
1059 distribution.
clear();
1061 EdgeIndexSet edgeIndices;
1062 Choice<ValueType>& choice = behavior.startNewChoice(outputActionIndex);
1063 std::vector<ValueType>& stateActionRewards = choice.getRewards();
1067 generateSynchronizedDistribution(state, edgeCombination, iteratorList, distribution, stateActionRewards, edgeIndices, stateToIdCallback);
1076 if (this->getOptions().isBuildChoiceOriginsSet()) {
1077 choice.addOriginData(boost::any(std::move(edgeIndices)));
1082 choice.reserve(std::distance(distribution.
begin(), distribution.
end()));
1083 for (
auto const& stateProbability : distribution) {
1084 choice.addProbability(stateProbability.getState(), stateProbability.getValue());
1087 probabilitySum += stateProbability.getValue();
1094 storm::exceptions::WrongFormatException,
1095 "Sum of update probabilities do not sum to one for some edge (actually sum to " << probabilitySum <<
").");
1105 bool movedIterator =
false;
1106 for (uint64_t j = 0; !movedIterator && j < iteratorList.size(); ++j) {
1108 if (iteratorList[j] != edgeCombination[j].second.end()) {
1109 movedIterator =
true;
1112 iteratorList[j] = edgeCombination[j].second.begin();
1116 done = !movedIterator;
1120template<
typename ValueType,
typename StateType>
1121void JaniNextStateGenerator<ValueType, StateType>::getActionChoices(std::vector<uint64_t>
const& locations, CompressedState
const& state,
1122 StateToIdCallback
const& stateToIdCallback, EdgeFilter
const& edgeFilter,
1123 StateBehavior<ValueType, StateType>& behavior) {
1124 scratch->automataEdgeSets.resize(edges.size());
1128 std::vector<EdgeSetWithIndices const*>& edgeSetsMemory = scratch->edgeSets;
1130 std::vector<typename EdgeSetWithIndices::const_iterator>& edgeIteratorMemory = scratch->firstEnabledEdgeIterators;
1132 uint64_t outputAndEdgesIndex = 0;
1133 for (OutputAndEdges
const& outputAndEdges : edges) {
1134 auto const& edges = outputAndEdges.second;
1135 AutomataEdgeSets& automataEdgeSets = scratch->automataEdgeSets[outputAndEdgesIndex++];
1136 if (edges.size() == 1) {
1138 auto const& nonsychingEdges = edges.front();
1139 uint64_t automatonIndex = nonsychingEdges.first;
1141 auto edgesIt = nonsychingEdges.second.find(locations[automatonIndex]);
1142 if (edgesIt != nonsychingEdges.second.end()) {
1143 for (
auto const& indexAndEdge : edgesIt->second) {
1144 if (edgeFilter != EdgeFilter::All) {
1145 STORM_LOG_ASSERT(edgeFilter == EdgeFilter::WithRate || edgeFilter == EdgeFilter::WithoutRate,
"Unexpected edge filter.");
1146 if ((edgeFilter == EdgeFilter::WithRate) != indexAndEdge.second->hasRate()) {
1150 if (!this->evaluator->asBool(indexAndEdge.second->getGuard())) {
1154 uint64_t actionIndex = outputAndEdges.first ? outputAndEdges.first.get() : indexAndEdge.second->getActionIndex();
1155 Choice<ValueType>& choice =
1156 expandNonSynchronizingEdge(*indexAndEdge.second, actionIndex, automatonIndex, state, stateToIdCallback, behavior);
1158 if (this->getOptions().isBuildChoiceOriginsSet()) {
1159 auto modelAutomatonIndex = model.
getAutomatonIndex(parallelAutomata[automatonIndex].get().getName());
1161 choice.addOriginData(boost::any(std::move(edgeIndex)));
1164 if (this->getOptions().isBuildChoiceLabelsSet()) {
1175 STORM_LOG_ASSERT(outputAndEdges.first,
"Need output action index for synchronization.");
1177 uint64_t outputActionIndex = outputAndEdges.first.get();
1180 bool productiveCombination =
true;
1183 edgeSetsMemory.clear();
1184 for (
auto const& automatonAndEdges : outputAndEdges.second) {
1185 uint64_t automatonIndex = automatonAndEdges.first;
1186 LocationsAndEdges
const& locationsAndEdges = automatonAndEdges.second;
1187 auto edgesIt = locationsAndEdges.find(locations[automatonIndex]);
1188 if (edgesIt == locationsAndEdges.end()) {
1189 productiveCombination =
false;
1192 edgeSetsMemory.push_back(&edgesIt->second);
1195 if (productiveCombination) {
1197 edgeIteratorMemory.clear();
1198 for (
auto const& edgesIt : edgeSetsMemory) {
1199 bool atLeastOneEdge =
false;
1200 EdgeSetWithIndices
const& edgeSetWithIndices = *edgesIt;
1201 for (
auto indexAndEdgeIt = edgeSetWithIndices.begin(), indexAndEdgeIte = edgeSetWithIndices.end(); indexAndEdgeIt != indexAndEdgeIte;
1204 if (edgeFilter != EdgeFilter::All) {
1205 STORM_LOG_ASSERT(edgeFilter == EdgeFilter::WithRate || edgeFilter == EdgeFilter::WithoutRate,
"Unexpected edge filter.");
1206 if ((edgeFilter == EdgeFilter::WithRate) != indexAndEdgeIt->second->hasRate()) {
1211 if (!this->evaluator->asBool(indexAndEdgeIt->second->getGuard())) {
1216 atLeastOneEdge =
true;
1217 edgeIteratorMemory.push_back(indexAndEdgeIt);
1222 if (!atLeastOneEdge) {
1223 productiveCombination =
false;
1230 if (productiveCombination) {
1232 automataEdgeSets.resize(outputAndEdges.second.size());
1233 STORM_LOG_ASSERT(edgeSetsMemory.size() == outputAndEdges.second.size(),
"Unexpected number of edge sets stored.");
1234 STORM_LOG_ASSERT(edgeIteratorMemory.size() == outputAndEdges.second.size(),
"Unexpected number of edge iterators stored.");
1235 auto edgeSetIt = edgeSetsMemory.begin();
1236 auto edgeIteratorIt = edgeIteratorMemory.begin();
1237 auto automatonEdgeSetsIt = automataEdgeSets.begin();
1238 for (
auto const& automatonAndEdges : outputAndEdges.second) {
1239 EdgeSetWithIndices& enabledEdgesOfAutomaton = automatonEdgeSetsIt->second;
1240 enabledEdgesOfAutomaton.clear();
1241 automatonEdgeSetsIt->first = automatonAndEdges.first;
1242 EdgeSetWithIndices
const& edgeSetWithIndices = **edgeSetIt;
1243 auto indexAndEdgeIt = *edgeIteratorIt;
1245 enabledEdgesOfAutomaton.emplace_back(*indexAndEdgeIt);
1246 auto indexAndEdgeIte = edgeSetWithIndices.end();
1247 for (++indexAndEdgeIt; indexAndEdgeIt != indexAndEdgeIte; ++indexAndEdgeIt) {
1249 if (edgeFilter != EdgeFilter::All) {
1250 STORM_LOG_ASSERT(edgeFilter == EdgeFilter::WithRate || edgeFilter == EdgeFilter::WithoutRate,
"Unexpected edge filter.");
1251 if ((edgeFilter == EdgeFilter::WithRate) != indexAndEdgeIt->second->hasRate()) {
1256 if (!this->evaluator->asBool(indexAndEdgeIt->second->getGuard())) {
1260 enabledEdgesOfAutomaton.emplace_back(*indexAndEdgeIt);
1262 ++automatonEdgeSetsIt;
1267 expandSynchronizingEdgeCombination(automataEdgeSets, outputActionIndex, state, stateToIdCallback, behavior);
1273template<
typename ValueType,
typename StateType>
1274void JaniNextStateGenerator<ValueType, StateType>::checkGlobalVariableWritesValid(AutomataEdgeSets
const& enabledEdges)
const {
1277 std::map<storm::expressions::Variable, uint64_t> writtenGlobalVariables;
1278 for (
auto edgeSetIt = enabledEdges.begin(), edgeSetIte = enabledEdges.end(); edgeSetIt != edgeSetIte; ++edgeSetIt) {
1279 for (
auto const& indexAndEdge : edgeSetIt->second) {
1280 for (
auto const& globalVariable : indexAndEdge.second->getWrittenGlobalVariables()) {
1281 auto it = writtenGlobalVariables.find(globalVariable);
1283 auto index = std::distance(enabledEdges.begin(), edgeSetIt);
1284 if (it != writtenGlobalVariables.end()) {
1285 STORM_LOG_THROW(it->second ==
static_cast<uint64_t
>(index), storm::exceptions::WrongFormatException,
1286 "Multiple writes to global variable '" << globalVariable.getName() <<
"' in synchronizing edges.");
1288 writtenGlobalVariables.emplace(globalVariable, index);
1295template<
typename ValueType,
typename StateType>
1297 return rewardExpressions.size();
1300template<
typename ValueType,
typename StateType>
1302 return rewardModelInformation[index];
1305template<
typename ValueType,
typename StateType>
1307 std::vector<StateType>
const& initialStateIndices,
1308 std::vector<StateType>
const& deadlockStateIndices,
1309 std::vector<StateType>
const& unexploredStateIndices) {
1312 std::vector<std::pair<std::string, storm::expressions::Expression>> transientVariableExpressions;
1313 for (
auto const& variable : model.getGlobalVariables().getTransientVariables()) {
1315 if (this->options.
isBuildAllLabelsSet() || this->options.getLabelNames().find(variable.
getName()) != this->options.getLabelNames().end()) {
1316 transientVariableExpressions.emplace_back(variable.
getName(), variable.getExpressionVariable().
getExpression());
1321 transientVariableExpressions);
1324template<
typename ValueType,
typename StateType>
1325std::vector<ValueType> JaniNextStateGenerator<ValueType, StateType>::evaluateRewardExpressions()
const {
1326 std::vector<ValueType> result;
1327 evaluateRewardExpressions(result);
1331template<
typename ValueType,
typename StateType>
1332void JaniNextStateGenerator<ValueType, StateType>::evaluateRewardExpressions(std::vector<ValueType>& result)
const {
1334 result.reserve(rewardExpressions.size());
1335 for (
auto const& rewardExpression : rewardExpressions) {
1336 result.push_back(this->evaluator->asRational(rewardExpression.second));
1340template<
typename ValueType,
typename StateType>
1341void JaniNextStateGenerator<ValueType, StateType>::addEvaluatedRewardExpressions(std::vector<ValueType>& rewards, ValueType
const& factor)
const {
1342 STORM_LOG_ASSERT(rewards.size() == rewardExpressions.size(),
"Reward count mismatch.");
1343 auto rewIt = rewards.begin();
1344 for (
auto const& rewardExpression : rewardExpressions) {
1345 (*rewIt) += factor * this->evaluator->asRational(rewardExpression.second);
1350template<
typename ValueType,
typename StateType>
1351void JaniNextStateGenerator<ValueType, StateType>::buildRewardModelInformation() {
1352 for (
auto const& rewardModel : rewardExpressions) {
1353 storm::jani::RewardModelInformation info(this->model, rewardModel.second);
1354 rewardModelInformation.emplace_back(rewardModel.first, info.hasStateRewards(),
false,
false);
1356 "Transition rewards are not supported and a reduction to action-based rewards was not possible.");
1357 if (info.hasTransitionRewards()) {
1358 evaluateRewardExpressionsAtDestinations =
true;
1360 if (info.hasActionRewards() || (this->options.isScaleAndLiftTransitionRewardsSet() && info.hasTransitionRewards())) {
1361 hasStateActionRewards =
true;
1362 rewardModelInformation.back().setHasStateActionRewards();
1365 if (!hasStateActionRewards) {
1366 evaluateRewardExpressionsAtDestinations =
false;
1367 evaluateRewardExpressionsAtEdges =
false;
1371template<
typename ValueType,
typename StateType>
1372void JaniNextStateGenerator<ValueType, StateType>::createSynchronizationInformation() {
1377 this->parallelAutomata.push_back(automaton);
1379 LocationsAndEdges locationsAndEdges;
1380 uint64_t edgeIndex = 0;
1381 for (
auto const& edge : automaton.getEdges()) {
1386 AutomataAndEdges automataAndEdges;
1387 automataAndEdges.emplace_back(std::make_pair(0, std::move(locationsAndEdges)));
1389 this->edges.emplace_back(std::make_pair(boost::none, std::move(automataAndEdges)));
1392 storm::jani::ParallelComposition
const& parallelComposition = topLevelComposition.
asParallelComposition();
1394 uint64_t automatonIndex = 0;
1396 STORM_LOG_THROW(composition->isAutomatonComposition(), storm::exceptions::WrongFormatException,
"Expected flat parallel composition.");
1397 STORM_LOG_THROW(composition->asAutomatonComposition().getInputEnabledActions().empty(), storm::exceptions::NotSupportedException,
1398 "Input-enabled actions are not supported right now.");
1400 this->parallelAutomata.push_back(this->model.
getAutomaton(composition->asAutomatonComposition().getAutomatonName()));
1403 LocationsAndEdges locationsAndEdges;
1404 uint64_t edgeIndex = 0;
1405 for (
auto const& edge : parallelAutomata.back().get().getEdges()) {
1412 if (!locationsAndEdges.empty()) {
1413 AutomataAndEdges automataAndEdges;
1414 automataAndEdges.emplace_back(std::make_pair(automatonIndex, std::move(locationsAndEdges)));
1415 this->edges.emplace_back(std::make_pair(boost::none, std::move(automataAndEdges)));
1421 uint64_t outputActionIndex = this->model.
getActionIndex(vector.getOutput());
1423 AutomataAndEdges automataAndEdges;
1424 bool atLeastOneEdge =
true;
1425 uint64_t automatonIndex = 0;
1426 for (
auto const& element : vector.getInput()) {
1428 LocationsAndEdges locationsAndEdges;
1430 uint64_t edgeIndex = 0;
1431 for (
auto const& edge : parallelAutomata[automatonIndex].get().getEdges()) {
1437 if (locationsAndEdges.empty()) {
1438 atLeastOneEdge =
false;
1441 automataAndEdges.emplace_back(std::make_pair(automatonIndex, std::move(locationsAndEdges)));
1446 if (atLeastOneEdge) {
1447 this->edges.emplace_back(std::make_pair(outputActionIndex, std::move(automataAndEdges)));
1452 STORM_LOG_TRACE(
"Number of synchronizations: " << this->edges.size() <<
".");
1455template<
typename ValueType,
typename StateType>
1457 std::vector<boost::any>& dataForChoiceOrigins)
const {
1458 if (!this->
getOptions().isBuildChoiceOriginsSet()) {
1462 std::vector<uint_fast64_t> identifiers;
1463 identifiers.reserve(dataForChoiceOrigins.size());
1465 std::map<EdgeIndexSet, uint_fast64_t> edgeIndexSetToIdentifierMap;
1468 edgeIndexSetToIdentifierMap.insert(std::make_pair(
EdgeIndexSet(), 0));
1469 uint_fast64_t currentIdentifier = 1;
1470 for (boost::any& originData : dataForChoiceOrigins) {
1471 STORM_LOG_ASSERT(originData.empty() || boost::any_cast<EdgeIndexSet>(&originData) !=
nullptr,
1472 "Origin data has unexpected type: " << originData.type().name() <<
".");
1474 EdgeIndexSet currentEdgeIndexSet = originData.empty() ?
EdgeIndexSet() : boost::any_cast<EdgeIndexSet>(std::move(originData));
1475 auto insertionRes = edgeIndexSetToIdentifierMap.emplace(std::move(currentEdgeIndexSet), currentIdentifier);
1476 identifiers.push_back(insertionRes.first->second);
1477 if (insertionRes.second) {
1478 ++currentIdentifier;
1482 std::vector<EdgeIndexSet> identifierToEdgeIndexSetMapping(currentIdentifier);
1483 for (
auto const& setIdPair : edgeIndexSetToIdentifierMap) {
1484 identifierToEdgeIndexSetMapping[setIdPair.second] = setIdPair.first;
1487 return std::make_shared<storm::storage::sparse::JaniChoiceOrigins>(std::make_shared<storm::jani::Model>(model), std::move(identifiers),
1488 std::move(identifierToEdgeIndexSetMapping));
1491template<
typename ValueType,
typename StateType>
1493 STORM_LOG_WARN(
"There are no observation labels in JANI currenty");
1497template<
typename ValueType,
typename StateType>
1498void JaniNextStateGenerator<ValueType, StateType>::checkValid()
const {
1501 std::vector<std::reference_wrapper<storm::jani::Constant const>> undefinedConstants = model.
getUndefinedConstants();
1502 std::stringstream stream;
1503 bool printComma =
false;
1504 for (
auto const& constant : undefinedConstants) {
1510 stream << constant.get().getName() <<
" (" << constant.get().getType() <<
")";
1513 STORM_LOG_THROW(
false, storm::exceptions::InvalidArgumentException,
"Program still contains these undefined constants: " + stream.str() +
".");
1516 "The input model contains undefined constants that influence the graph structure of the underlying model, which is not allowed.");
1520template class JaniNextStateGenerator<double>;
1521template class JaniNextStateGenerator<storm::RationalNumber>;
1522template class JaniNextStateGenerator<storm::RationalFunction>;
uint64_t getReservedBitsForUnboundedVariables() const
std::set< std::string > const & getRewardModelNames() const
Which reward models are built.
bool isScaleAndLiftTransitionRewardsSet() const
bool isBuildAllRewardModelsSet() const
bool isBuildChoiceLabelsSet() const
bool isBuildChoiceOriginsSet() const
std::vector< std::pair< LabelOrExpression, bool > > const & getTerminalStates() const
bool isExplorationChecksSet() const
bool isBuildAllLabelsSet() const
bool hasTerminalStates() const
bool isAddOverlappingGuardLabelSet() const
bool isAddOutOfBoundsStateSet() const
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.
bool isIntegerType() const
Checks whether this type is an integral type.
bool isRationalType() const
Checks whether this type is a rational type.
Type const & getType() const
Retrieves the type of the variable.
storm::expressions::Expression getExpression() const
Retrieves an expression that represents the variable.
std::string const & getName() const
Retrieves the name of the variable.
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 bool isDiscreteTimeModel() const 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 StateBehavior< ValueType, StateType > const & expand(StateToIdCallback const &stateToIdCallback) override
virtual bool isDeterministicModel() const override
virtual bool isPartiallyObservable() const override
virtual std::size_t getNumberOfRewardModels() const override
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 addStateValuation(storm::storage::sparse::state_type const ¤tStateIndex, storm::storage::sparse::Valuations &valuations) const override
Adds the valuation for the currently loaded state to the given builder.
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.
virtual storm::storage::sparse::Valuations initializeStateValuations() const override
Initializes state valuations by adding the appropriate variables.
std::unique_ptr< storm::expressions::ExpressionEvaluator< BaseValueType > > evaluator
void postprocess(StateBehavior< ValueType, uint32_t > &result)
StateBehavior< ValueType, uint32_t > currentStateBehavior
boost::optional< std::vector< uint64_t > > overlappingGuardStates
CompressedState const * state
NextStateGeneratorOptions const & getOptions() const
std::vector< std::pair< storm::expressions::Expression, bool > > terminalStates
NextStateGeneratorOptions options
VariableInformation variableInformation
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
bool empty() const
Retrieves whether the behavior is empty in the sense that there are no available choices.
std::vector< ValueType > const & getStateRewards() const
Retrieves the list of state rewards under selected reward models.
void clear()
Resets this to an empty behavior, i.e.
std::size_t getNumberOfChoices() const
Retrieves the number of choices in the behavior.
void setExpanded(bool newValue=true)
Sets whether the state was expanded.
Choice< ValueType, StateType > & startNewChoice(uint_fast64_t actionIndex=0, bool markovian=false)
Adds a new empty choice with the given action index and returns a reference to it.
std::string const & getName() const
Returns the name of the location.
std::string const & getAutomatonName() const
Retrieves the name of the automaton this composition element refers to.
bool isBooleanType() const
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.
std::vector< EdgeDestination > const & getDestinations() const
Retrieves the destinations of this edge.
bool hasRate() const
Retrieves whether this edge has an associated rate.
uint64_t getSourceLocationIndex() const
Retrieves the index of the source location.
OrderedAssignments const & getAssignments() const
Retrieves the assignments of this edge.
storm::expressions::Expression const & getRate() const
Retrieves the rate of this edge.
int64_t const & getHighestAssignmentLevel() const
Retrieves the highest assignment level occurring in a destination assignment If no assignment exists,...
std::size_t getNumberOfDestinations() const
Retrieves the number of destinations of this edge.
int64_t const & getLowestAssignmentLevel() const
Retrieves the lowest assignment level occurring in a destination assignment.
EdgeDestination const & getDestination(uint64_t index) const
Retrieves the destination with the given index.
virtual bool isBasicType() const
BasicType const & asBasicType() const
OrderedAssignments const & getAssignments() const
Retrieves the assignments of this location.
ModelFeatures & add(ModelFeature const &modelFeature)
void remove(ModelFeature const &modelFeature)
bool hasUndefinedConstants() const
Retrieves whether the model still has undefined constants.
storm::expressions::ExpressionManager & getManager() const
Retrieves the expression manager responsible for the expressions in the model.
VariableSet & getGlobalVariables()
Retrieves the variables of this automaton.
storm::expressions::Expression getRewardModelExpression(std::string const &identifier) const
Retrieves the defining reward expression of the reward model with the given identifier.
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.
Composition const & getSystemComposition() const
Retrieves the system composition expression.
void liftTransientEdgeDestinationAssignments(int64_t maxLevel=0)
Lifts the common edge destination assignments of transient variables to edge assignments.
static const uint64_t SILENT_ACTION_INDEX
The index of the silent action.
bool hasNonTrivialRewardExpression() const
Returns true iff there is a non-trivial reward model, i.e., a reward model that does not consist of a...
bool undefinedConstantsAreGraphPreserving() const
Checks that undefined constants (parameters) of the model preserve the graph of the underlying model.
void pushEdgeAssignmentsToDestinations()
Action const & getAction(uint64_t index) const
Retrieves the action with the given index.
std::vector< std::pair< std::string, storm::expressions::Expression > > getAllRewardModelExpressions() const
Retrieves all available reward model names and expressions of the model.
bool isNonTrivialRewardModelExpression(std::string const &identifier) const
Returns true iff the given identifier corresponds to a non-trivial reward expression i....
void simplifyComposition()
Attempts to simplify the composition.
ModelFeatures const & getModelFeatures() const
Retrieves the enabled model features.
Automaton & getAutomaton(std::string const &name)
Retrieves the automaton with the given name.
bool hasNonTrivialInitialStates() const
Retrieves whether there are non-trivial initial states in the model or any of the contained automata.
uint64_t getActionIndex(std::string const &name) const
Get the index of the action.
bool usesAssignmentLevels(bool onlyTransient=false) const
Retrieves whether the model uses an assignment level other than zero.
uint64_t getAutomatonIndex(std::string const &name) const
Retrieves the index of the given automaton.
std::vector< std::reference_wrapper< Constant const > > getUndefinedConstants() const
Retrieves all undefined constants of the model.
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.
std::vector< SynchronizationVector > const & getSynchronizationVectors() const
Retrieves the synchronization vectors of the parallel composition.
std::vector< std::shared_ptr< Composition > > const & getSubcompositions() const
Retrieves the subcompositions of the parallel composition.
static bool isNoActionInput(std::string const &action)
storm::expressions::Variable const & getExpressionVariable() const
Retrieves the associated expression variable.
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.
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.
void setFromInt(uint64_t bitIndex, uint64_t numberOfBits, uint64_t value)
Sets the selected number of lowermost bits of the provided value at the given bit index.
void set(uint64_t index, bool value=true)
Sets the given truth value at the given index.
uint64_t getAsInt(uint64_t bitIndex, uint64_t numberOfBits) const
Retrieves the content of the current bit vector at the given index for the given number of bits as an...
static uint_fast64_t getIdentifierForChoicesWithNoOrigin()
Helper to incrementally build a ValuationClassDescription, i.e.
Provides access to valuations of variables for a set of entities (e.g.
ValuationsStorage const & getStorage() const
virtual std::unique_ptr< storm::solver::SmtSolver > create(storm::expressions::ExpressionManager &manager) const
Creates a new SMT solver instance.
#define STORM_LOG_INFO(message)
#define STORM_LOG_WARN(message)
#define STORM_LOG_DEBUG(message)
#define STORM_LOG_TRACE(message)
#define STORM_LOG_ASSERT(cond, message)
#define STORM_LOG_THROW(cond, exception, message)
SFTBDDChecker::ValueType ValueType
void unpackStateAppendToValuations(CompressedState const &state, VariableInformation const &variableInformation, storm::storage::sparse::ValuationsStorage &valuations)
Appends the values of the variables in the given state to the valuations object.
storm::expressions::SimpleValuation unpackStateIntoValuation(CompressedState const &state, VariableInformation const &variableInformation, storm::expressions::ExpressionManager const &manager)
Converts the compressed state into an explicit representation in the form of a valuation.
void unpackStateDifferenceIntoEvaluator(CompressedState const &newState, CompressedState const &oldState, VariableInformation const &variableInformation, storm::expressions::ExpressionEvaluator< ValueType > &evaluator)
Updates the (non-transient) variable values in the given evaluator from the values of oldState to the...
storm::storage::BitVector CompressedState
storm::builder::BuilderOptions NextStateGeneratorOptions
storm::adapters::DereferenceIteratorAdapter< std::vector< std::shared_ptr< Assignment > > const > ConstAssignments
@ MultiObjectiveProperties
bool isDiscreteTimeModel(ModelType const &modelType)
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)
std::vector< T > buildVectorForRange(T min, T max)
Constructs a vector [min, min+1, ...., max-1].
bool isConstant(ValueType const &)
bool isZero(ValueType const &a)
void addOriginData(boost::any const &data)
Adds the given data that specifies the origin of this choice w.r.t.
void addRewards(std::vector< ValueType > &&values)
Adds the given choices rewards to this choice.
void addProbability(StateType const &state, ValueType const &value)
Adds the given probability value to the given state in the underlying distribution.
The actual (private) implementation of JaniNextStateGeneratorScratchMemory, see the corresponding mem...
TransientVariableValuation< ValueType > transientValuation
std::vector< typename Generator::EdgeSetWithIndices const * > edgeSets
CompressedState successorState
std::vector< typename Generator::AutomataEdgeSets > automataEdgeSets
JaniNextStateGenerator< ValueType, StateType > Generator
std::vector< typename Generator::EdgeSetWithIndices::const_iterator > iteratorList
std::vector< typename Generator::EdgeSetWithIndices::const_iterator > firstEnabledEdgeIterators
std::vector< LocationVariableInformation const * > locationVars
storm::generator::Distribution< StateType, ValueType > distribution
CompressedState evaluatorState
std::vector< storm::jani::EdgeDestination const * > destinations
std::vector< storm::expressions::Expression > variableExpressionsForAssertions
std::vector< uint64_t > locations