43template<
typename ValueType,
typename StateType>
49template<
typename ValueType,
typename StateType>
54 hasStateActionRewards(false),
55 evaluateRewardExpressionsAtEdges(false),
56 evaluateRewardExpressionsAtDestinations(false) {
62 if (features.hasArrays()) {
67 STORM_LOG_THROW(features.empty(), storm::exceptions::NotSupportedException,
68 "The explicit next-state generator does not support the following model feature(s): " << features.toString() <<
".");
73 bool hasNonTrivialRewardExpressions =
false;
79 for (
auto const& rewardModelName : this->
options.getRewardModelNames()) {
87 if (!hasNonTrivialRewardExpressions) {
88 for (
auto const& rewExpr : rewardExpressions) {
89 STORM_LOG_ASSERT(rewExpr.second.isVariable(),
"Expected trivial reward expression to be a variable. Got " << rewExpr.second <<
" instead.");
91 if (var.isTransient() && var.hasInitExpression() && !
storm::utility::isZero(var.getInitExpression().evaluateAsRational())) {
92 hasNonTrivialRewardExpressions =
true;
104 evaluateRewardExpressionsAtEdges =
true;
108 this->createSynchronizationInformation();
115 this->transientVariableInformation = TransientVariableInformation<ValueType>(this->model, this->parallelAutomata);
116 this->transientVariableInformation.registerArrayVariableReplacements(arrayEliminatorData);
120 this->
evaluator = std::make_unique<storm::expressions::ExpressionEvaluator<ValueType>>(this->model.
getManager());
121 this->transientVariableInformation.setDefaultValuesInEvaluator(*this->
evaluator);
124 buildRewardModelInformation();
128 for (
auto const& expressionOrLabelAndBool : this->
options.getTerminalStates()) {
129 if (expressionOrLabelAndBool.first.isExpression()) {
130 this->
terminalStates.emplace_back(expressionOrLabelAndBool.first.getExpression(), expressionOrLabelAndBool.second);
133 if (!this->
isSpecialLabel(expressionOrLabelAndBool.first.getLabel())) {
135 storm::exceptions::InvalidArgumentException,
136 "Terminal states refer to illegal label '" << expressionOrLabelAndBool.first.getLabel() <<
"'.");
140 storm::exceptions::InvalidArgumentException,
141 "Terminal states refer to non-boolean variable '" << expressionOrLabelAndBool.first.getLabel() <<
"'.");
143 "Terminal states refer to non-transient variable '" << expressionOrLabelAndBool.first.getLabel() <<
"'.");
152template<
typename ValueType,
typename StateType>
164template<
typename ValueType,
typename StateType>
172 if (!features.empty()) {
173 STORM_LOG_INFO(
"The model can not be build as it contains these unsupported features: " << features.toString());
181template<
typename ValueType,
typename StateType>
193 STORM_LOG_THROW(
false, storm::exceptions::WrongFormatException,
"Invalid model type.");
197template<
typename ValueType,
typename StateType>
202template<
typename ValueType,
typename StateType>
207template<
typename ValueType,
typename StateType>
212template<
typename ValueType,
typename StateType>
214 if (locationVariable.
bitWidth == 0) {
221template<
typename ValueType,
typename StateType>
222void JaniNextStateGenerator<ValueType, StateType>::setLocation(
CompressedState& state, LocationVariableInformation
const& locationVariable,
223 uint64_t locationIndex)
const {
224 if (locationVariable.bitWidth != 0) {
225 state.setFromInt(locationVariable.bitOffset, locationVariable.bitWidth, locationIndex);
229template<
typename ValueType,
typename StateType>
230std::vector<uint64_t> JaniNextStateGenerator<ValueType, StateType>::getLocations(
CompressedState const& state)
const {
231 std::vector<uint64_t> result(this->variableInformation.locationVariables.size());
233 auto resultIt = result.begin();
234 for (
auto it = this->variableInformation.locationVariables.begin(), ite = this->variableInformation.locationVariables.end(); it !=
ite; ++it, ++resultIt) {
235 if (it->bitWidth == 0) {
238 *resultIt = state.getAsInt(it->bitOffset, it->bitWidth);
245template<
typename ValueType,
typename StateType>
247 std::vector<StateType> initialStateIndices;
254 std::vector<storm::expressions::Expression> rangeExpressions = model.
getAllRangeExpressions(this->parallelAutomata);
255 for (
auto const& expression : rangeExpressions) {
256 solver->add(expression);
263 CompressedState initialState(this->variableInformation.getTotalBitOffset(
true));
268 std::shared_ptr<storm::solver::SmtSolver::ModelReference> model = solver->getModel();
269 for (
auto const& booleanVariable : this->variableInformation.booleanVariables) {
270 bool variableValue = model->getBooleanValue(booleanVariable.variable);
272 blockingExpression = blockingExpression.
isInitialized() ? blockingExpression || localBlockingExpression : localBlockingExpression;
273 initialState.
set(booleanVariable.bitOffset, variableValue);
275 for (
auto const& integerVariable : this->variableInformation.integerVariables) {
276 int_fast64_t variableValue = model->getIntegerValue(integerVariable.variable);
277 if (integerVariable.forceOutOfBoundsCheck || this->getOptions().isExplorationChecksSet()) {
278 STORM_LOG_THROW(variableValue >= integerVariable.lowerBound, storm::exceptions::WrongFormatException,
279 "The initial value for variable " << integerVariable.variable.getName() <<
" is lower than the lower bound.");
280 STORM_LOG_THROW(variableValue <= integerVariable.upperBound, storm::exceptions::WrongFormatException,
281 "The initial value for variable " << integerVariable.variable.getName() <<
" is higher than the upper bound");
284 blockingExpression = blockingExpression.
isInitialized() ? blockingExpression || localBlockingExpression : localBlockingExpression;
285 initialState.
setFromInt(integerVariable.bitOffset, integerVariable.bitWidth,
286 static_cast<uint_fast64_t
>(variableValue - integerVariable.lowerBound));
290 std::vector<std::set<uint64_t>::const_iterator> initialLocationsIts;
291 std::vector<std::set<uint64_t>::const_iterator> initialLocationsItes;
292 for (
auto const& automatonRef : this->parallelAutomata) {
293 auto const& automaton = automatonRef.get();
294 initialLocationsIts.push_back(automaton.getInitialLocationIndices().cbegin());
295 initialLocationsItes.push_back(automaton.getInitialLocationIndices().cend());
298 initialLocationsIts, initialLocationsItes,
299 [
this, &initialState](uint64_t index, uint64_t value) { setLocation(initialState, this->variableInformation.locationVariables[index], value); },
300 [&stateToIdCallback, &initialStateIndices, &initialState]() {
302 StateType
id = stateToIdCallback(initialState);
303 initialStateIndices.push_back(
id);
311 solver->add(blockingExpression);
314 STORM_LOG_DEBUG(
"Enumerated " << initialStateIndices.size() <<
" initial states using SMT solving.");
317 std::vector<std::vector<uint64_t>> allValues;
318 for (
auto const& aRef : this->parallelAutomata) {
319 auto const& aInitLocs = aRef.get().getInitialLocationIndices();
320 allValues.emplace_back(aInitLocs.begin(), aInitLocs.end());
322 uint64_t locEndIndex = allValues.size();
323 for (
auto const& intVar : this->variableInformation.integerVariables) {
324 STORM_LOG_ASSERT(intVar.lowerBound <= intVar.upperBound,
"Expecting variable with non-empty set of possible values.");
326 allValues.push_back(storm::utility::vector::buildVectorForRange<uint64_t>(
static_cast<uint64_t
>(0), intVar.upperBound + 1 - intVar.lowerBound));
328 uint64_t intEndIndex = allValues.size();
330 allValues.resize(allValues.size() + this->variableInformation.booleanVariables.size(),
331 std::vector<uint64_t>({static_cast<uint64_t>(0), static_cast<uint64_t>(1)}));
333 std::vector<std::vector<uint64_t>::const_iterator> its;
334 std::vector<std::vector<uint64_t>::const_iterator> ites;
335 for (
auto const& valVec : allValues) {
336 its.push_back(valVec.cbegin());
337 ites.push_back(valVec.cend());
341 CompressedState initialState(this->variableInformation.getTotalBitOffset(
true));
344 [
this, &initialState, &locEndIndex, &intEndIndex](uint64_t index, uint64_t value) {
346 if (index < locEndIndex) {
348 setLocation(initialState, this->variableInformation.locationVariables[index], value);
349 }
else if (index < intEndIndex) {
351 auto const& intVar = this->variableInformation.integerVariables[index - locEndIndex];
352 initialState.
setFromInt(intVar.bitOffset, intVar.bitWidth, value);
355 STORM_LOG_ASSERT(index - intEndIndex < this->variableInformation.booleanVariables.size(),
"Unexpected index");
356 auto const& boolVar = this->variableInformation.booleanVariables[index - intEndIndex];
358 initialState.
set(boolVar.bitOffset,
static_cast<bool>(value));
361 [&stateToIdCallback, &initialStateIndices, &initialState]() {
363 StateType
id = stateToIdCallback(initialState);
364 initialStateIndices.push_back(
id);
367 STORM_LOG_DEBUG(
"Enumerated " << initialStateIndices.size() <<
" initial states using brute force enumeration.");
369 return initialStateIndices;
372template<
typename ValueType,
typename StateType>
381 auto assignmentIt = assignments.
begin();
382 auto assignmentIte = assignments.end();
385 auto boolIt = this->variableInformation.booleanVariables.begin();
386 for (; assignmentIt != assignmentIte && assignmentIt->lValueIsVariable() && assignmentIt->getExpressionVariable().hasBooleanType(); ++assignmentIt) {
387 while (assignmentIt->getExpressionVariable() != boolIt->variable) {
390 state.
set(boolIt->bitOffset, expressionEvaluator.asBool(assignmentIt->getAssignedExpression()));
394 auto integerIt = this->variableInformation.integerVariables.begin();
395 for (; assignmentIt != assignmentIte && assignmentIt->lValueIsVariable() && assignmentIt->getExpressionVariable().hasIntegerType(); ++assignmentIt) {
396 while (assignmentIt->getExpressionVariable() != integerIt->variable) {
399 int_fast64_t assignedValue = expressionEvaluator.asInt(assignmentIt->getAssignedExpression());
401 if (assignedValue < integerIt->lowerBound || assignedValue > integerIt->upperBound) {
402 state = this->outOfBoundsState;
404 }
else if (integerIt->forceOutOfBoundsCheck || this->options.isExplorationChecksSet()) {
405 STORM_LOG_THROW(assignedValue >= integerIt->lowerBound, storm::exceptions::WrongFormatException,
406 "The update " << assignmentIt->getExpressionVariable().getName() <<
" := " << assignmentIt->getAssignedExpression()
407 <<
" leads to an out-of-bounds value (" << assignedValue <<
") for the variable '"
408 << assignmentIt->getExpressionVariable().getName() <<
"'.");
409 STORM_LOG_THROW(assignedValue <= integerIt->upperBound, storm::exceptions::WrongFormatException,
410 "The update " << assignmentIt->getExpressionVariable().getName() <<
" := " << assignmentIt->getAssignedExpression()
411 <<
" leads to an out-of-bounds value (" << assignedValue <<
") for the variable '"
412 << assignmentIt->getExpressionVariable().getName() <<
"'.");
414 state.
setFromInt(integerIt->bitOffset, integerIt->bitWidth, assignedValue - integerIt->lowerBound);
415 STORM_LOG_ASSERT(
static_cast<int_fast64_t
>(state.
getAsInt(integerIt->bitOffset, integerIt->bitWidth)) + integerIt->lowerBound == assignedValue,
416 "Writing to the bit vector bucket failed (read " << state.
getAsInt(integerIt->bitOffset, integerIt->bitWidth) <<
" but wrote "
417 << assignedValue <<
").");
420 for (; assignmentIt != assignmentIte && assignmentIt->lValueIsArrayAccess(); ++assignmentIt) {
421 auto const& arrayIndicesAsExpr = assignmentIt->getLValue().getArrayIndexVector();
422 std::vector<uint64_t> arrayIndices;
423 arrayIndices.reserve(arrayIndicesAsExpr.size());
424 for (
auto const& i : arrayIndicesAsExpr) {
425 arrayIndices.push_back(
static_cast<uint64_t
>(expressionEvaluator.asInt(i)));
427 if (assignmentIt->getAssignedExpression().hasIntegerType()) {
428 IntegerVariableInformation
const& intInfo =
429 this->variableInformation.getIntegerArrayVariableReplacement(assignmentIt->getLValue().getVariable().getExpressionVariable(), arrayIndices);
430 int_fast64_t assignedValue = expressionEvaluator.asInt(assignmentIt->getAssignedExpression());
433 if (assignedValue < intInfo.lowerBound || assignedValue > intInfo.upperBound) {
434 state = this->outOfBoundsState;
437 STORM_LOG_THROW(assignedValue >= intInfo.lowerBound, storm::exceptions::WrongFormatException,
438 "The update " << assignmentIt->getLValue() <<
" := " << assignmentIt->getAssignedExpression()
439 <<
" leads to an out-of-bounds value (" << assignedValue <<
") for the variable '"
440 << assignmentIt->getExpressionVariable().getName() <<
"'.");
441 STORM_LOG_THROW(assignedValue <= intInfo.upperBound, storm::exceptions::WrongFormatException,
442 "The update " << assignmentIt->getLValue() <<
" := " << assignmentIt->getAssignedExpression()
443 <<
" leads to an out-of-bounds value (" << assignedValue <<
") for the variable '"
444 << assignmentIt->getExpressionVariable().getName() <<
"'.");
446 state.
setFromInt(intInfo.bitOffset, intInfo.bitWidth, assignedValue - intInfo.lowerBound);
447 STORM_LOG_ASSERT(
static_cast<int_fast64_t
>(state.
getAsInt(intInfo.bitOffset, intInfo.bitWidth)) + intInfo.lowerBound == assignedValue,
448 "Writing to the bit vector bucket failed (read " << state.
getAsInt(intInfo.bitOffset, intInfo.bitWidth) <<
" but wrote "
449 << assignedValue <<
").");
450 }
else if (assignmentIt->getAssignedExpression().hasBooleanType()) {
451 BooleanVariableInformation
const& boolInfo =
452 this->variableInformation.getBooleanArrayVariableReplacement(assignmentIt->getLValue().getVariable().getExpressionVariable(), arrayIndices);
453 state.
set(boolInfo.bitOffset, expressionEvaluator.asBool(assignmentIt->getAssignedExpression()));
455 STORM_LOG_THROW(
false, storm::exceptions::UnexpectedException,
"Unhandled type of base variable.");
460 STORM_LOG_ASSERT(assignmentIt == assignmentIte,
"Not all assignments were consumed.");
463template<
typename ValueType,
typename StateType>
464void JaniNextStateGenerator<ValueType, StateType>::applyTransientUpdate(TransientVariableValuation<ValueType>& transientValuation,
467 auto assignmentIt = transientAssignments.
begin();
468 auto assignmentIte = transientAssignments.
end();
471 auto boolIt = this->transientVariableInformation.booleanVariableInformation.begin();
472 for (; assignmentIt != assignmentIte && assignmentIt->lValueIsVariable() && assignmentIt->getExpressionVariable().hasBooleanType(); ++assignmentIt) {
473 while (assignmentIt->getExpressionVariable() != boolIt->variable) {
476 transientValuation.booleanValues.emplace_back(&(*boolIt), expressionEvaluator.asBool(assignmentIt->getAssignedExpression()));
479 auto integerIt = this->transientVariableInformation.integerVariableInformation.begin();
480 for (; assignmentIt != assignmentIte && assignmentIt->lValueIsVariable() && assignmentIt->getExpressionVariable().hasIntegerType(); ++assignmentIt) {
481 while (assignmentIt->getExpressionVariable() != integerIt->variable) {
484 int64_t assignedValue = expressionEvaluator.asInt(assignmentIt->getAssignedExpression());
486 STORM_LOG_THROW(!integerIt->lowerBound || assignedValue >= integerIt->lowerBound.get(), storm::exceptions::WrongFormatException,
487 "The update " << assignmentIt->getExpressionVariable().getName() <<
" := " << assignmentIt->getAssignedExpression()
488 <<
" leads to an out-of-bounds value (" << assignedValue <<
") for the variable '"
489 << assignmentIt->getExpressionVariable().getName() <<
"'.");
490 STORM_LOG_THROW(!integerIt->upperBound || assignedValue <= integerIt->upperBound.get(), storm::exceptions::WrongFormatException,
491 "The update " << assignmentIt->getExpressionVariable().getName() <<
" := " << assignmentIt->getAssignedExpression()
492 <<
" leads to an out-of-bounds value (" << assignedValue <<
") for the variable '"
493 << assignmentIt->getExpressionVariable().getName() <<
"'.");
495 transientValuation.integerValues.emplace_back(&(*integerIt), assignedValue);
498 auto rationalIt = this->transientVariableInformation.rationalVariableInformation.begin();
499 for (; assignmentIt != assignmentIte && assignmentIt->lValueIsVariable() && assignmentIt->getExpressionVariable().hasRationalType(); ++assignmentIt) {
500 while (assignmentIt->getExpressionVariable() != rationalIt->variable) {
503 transientValuation.rationalValues.emplace_back(&(*rationalIt), expressionEvaluator.asRational(assignmentIt->getAssignedExpression()));
507 for (; assignmentIt != assignmentIte && assignmentIt->lValueIsArrayAccess(); ++assignmentIt) {
508 auto const& arrayIndicesAsExpr = assignmentIt->getLValue().getArrayIndexVector();
509 std::vector<uint64_t> arrayIndices;
510 arrayIndices.reserve(arrayIndicesAsExpr.size());
511 for (
auto const& i : arrayIndicesAsExpr) {
512 arrayIndices.push_back(
static_cast<uint64_t
>(expressionEvaluator.asInt(i)));
514 storm::expressions::Type const& baseType = assignmentIt->getLValue().getVariable().getExpressionVariable().getType();
516 auto const& intInfo = this->transientVariableInformation.getIntegerArrayVariableReplacement(
517 assignmentIt->getLValue().getVariable().getExpressionVariable(), arrayIndices);
518 int64_t assignedValue = expressionEvaluator.asInt(assignmentIt->getAssignedExpression());
520 STORM_LOG_THROW(assignedValue >= intInfo.lowerBound, storm::exceptions::WrongFormatException,
521 "The update " << assignmentIt->getLValue() <<
" := " << assignmentIt->getAssignedExpression()
522 <<
" leads to an out-of-bounds value (" << assignedValue <<
") for the variable '"
523 << assignmentIt->getExpressionVariable().getName() <<
"'.");
524 STORM_LOG_THROW(assignedValue <= intInfo.upperBound, storm::exceptions::WrongFormatException,
525 "The update " << assignmentIt->getLValue() <<
" := " << assignmentIt->getAssignedExpression()
526 <<
" leads to an out-of-bounds value (" << assignedValue <<
") for the variable '"
527 << assignmentIt->getExpressionVariable().getName() <<
"'.");
529 transientValuation.integerValues.emplace_back(&intInfo, assignedValue);
531 auto const& boolInfo = this->transientVariableInformation.getBooleanArrayVariableReplacement(
532 assignmentIt->getLValue().getVariable().getExpressionVariable(), arrayIndices);
533 transientValuation.booleanValues.emplace_back(&boolInfo, expressionEvaluator.asBool(assignmentIt->getAssignedExpression()));
535 auto const& rationalInfo = this->transientVariableInformation.getRationalArrayVariableReplacement(
536 assignmentIt->getLValue().getVariable().getExpressionVariable(), arrayIndices);
537 transientValuation.rationalValues.emplace_back(&rationalInfo, expressionEvaluator.asRational(assignmentIt->getAssignedExpression()));
539 STORM_LOG_THROW(
false, storm::exceptions::UnexpectedException,
"Unhandled type of base variable.");
544 STORM_LOG_ASSERT(assignmentIt == assignmentIte,
"Not all assignments were consumed.");
547template<
typename ValueType,
typename StateType>
548TransientVariableValuation<ValueType> JaniNextStateGenerator<ValueType, StateType>::getTransientVariableValuationAtLocations(
550 uint64_t automatonIndex = 0;
551 TransientVariableValuation<ValueType> transientVariableValuation;
552 for (
auto const& automatonRef : this->parallelAutomata) {
553 auto const& automaton = automatonRef.get();
554 uint64_t currentLocationIndex = locations[automatonIndex];
560 return transientVariableValuation;
563template<
typename ValueType,
typename StateType>
566 transientVariableInformation.setDefaultValuesInEvaluator(evaluator);
567 auto transientVariableValuation = getTransientVariableValuationAtLocations(getLocations(state), evaluator);
568 transientVariableValuation.setInEvaluator(evaluator, this->getOptions().isExplorationChecksSet());
571template<
typename ValueType,
typename StateType>
575 for (
auto const& varInfo : transientVariableInformation.booleanVariableInformation) {
576 result.addVariable(varInfo.variable);
578 for (
auto const& varInfo : transientVariableInformation.integerVariableInformation) {
579 result.addVariable(varInfo.variable);
581 for (
auto const& varInfo : transientVariableInformation.rationalVariableInformation) {
582 result.addVariable(varInfo.variable);
587template<
typename ValueType,
typename StateType>
590 std::vector<bool> booleanValues;
591 booleanValues.reserve(this->variableInformation.booleanVariables.size() + transientVariableInformation.booleanVariableInformation.size());
592 std::vector<int64_t> integerValues;
593 integerValues.reserve(this->variableInformation.locationVariables.size() + this->variableInformation.integerVariables.size() +
594 transientVariableInformation.integerVariableInformation.size());
595 std::vector<storm::RationalNumber> rationalValues;
596 rationalValues.reserve(transientVariableInformation.rationalVariableInformation.size());
599 extractVariableValues(*this->state, this->variableInformation, integerValues, booleanValues, integerValues);
602 auto transientVariableValuation = getTransientVariableValuationAtLocations(getLocations(*this->state), *this->evaluator);
604 auto varIt = transientVariableValuation.booleanValues.begin();
605 auto varIte = transientVariableValuation.booleanValues.end();
606 for (
auto const& varInfo : transientVariableInformation.booleanVariableInformation) {
607 if (varIt != varIte && varIt->first->variable == varInfo.variable) {
608 booleanValues.push_back(varIt->second);
611 booleanValues.push_back(varInfo.defaultValue);
616 auto varIt = transientVariableValuation.integerValues.begin();
617 auto varIte = transientVariableValuation.integerValues.end();
618 for (
auto const& varInfo : transientVariableInformation.integerVariableInformation) {
619 if (varIt != varIte && varIt->first->variable == varInfo.variable) {
620 integerValues.push_back(varIt->second);
623 integerValues.push_back(varInfo.defaultValue);
628 auto varIt = transientVariableValuation.rationalValues.begin();
629 auto varIte = transientVariableValuation.rationalValues.end();
630 for (
auto const& varInfo : transientVariableInformation.rationalVariableInformation) {
631 if (varIt != varIte && varIt->first->variable == varInfo.variable) {
632 rationalValues.push_back(storm::utility::convertNumber<storm::RationalNumber>(varIt->second));
635 rationalValues.push_back(storm::utility::convertNumber<storm::RationalNumber>(varInfo.defaultValue));
640 valuationsBuilder.
addState(currentStateIndex, std::move(booleanValues), std::move(integerValues), std::move(rationalValues));
643template<
typename ValueType,
typename StateType>
651 std::vector<uint64_t> locations = getLocations(*this->state);
655 auto transientVariableValuation = getTransientVariableValuationAtLocations(locations, *this->evaluator);
656 transientVariableValuation.setInEvaluator(*this->evaluator, this->getOptions().isExplorationChecksSet());
661 if (!this->terminalStates.empty()) {
662 for (
auto const& expressionBool : this->terminalStates) {
663 if (this->evaluator->asBool(expressionBool.first) == expressionBool.second) {
665 this->transientVariableInformation.setDefaultValuesInEvaluator(*this->evaluator);
672 this->transientVariableInformation.setDefaultValuesInEvaluator(*this->evaluator);
676 std::vector<Choice<ValueType>> allChoices;
677 if (this->getOptions().isApplyMaximalProgressAssumptionSet()) {
679 allChoices = getActionChoices(locations, *this->state, stateToIdCallback, EdgeFilter::WithoutRate);
680 if (allChoices.empty()) {
682 allChoices = getActionChoices(locations, *this->state, stateToIdCallback, EdgeFilter::WithRate);
685 allChoices = getActionChoices(locations, *this->state, stateToIdCallback);
687 std::size_t totalNumberOfChoices = allChoices.size();
691 if (totalNumberOfChoices == 0) {
696 if (this->isDeterministicModel() && totalNumberOfChoices > 1) {
700 this->overlappingGuardStates->push_back(stateToIdCallback(*this->state));
705 ValueType totalExitRate = this->isDiscreteTimeModel() ?
static_cast<ValueType
>(totalNumberOfChoices) : storm::utility::zero<ValueType>();
708 for (
auto const& choice : allChoices) {
709 for (
auto const& stateProbabilityPair : choice) {
710 if (this->isDiscreteTimeModel()) {
711 globalChoice.
addProbability(stateProbabilityPair.first, stateProbabilityPair.second / totalNumberOfChoices);
713 globalChoice.
addProbability(stateProbabilityPair.first, stateProbabilityPair.second);
717 if (hasStateActionRewards && !this->isDiscreteTimeModel()) {
718 totalExitRate += choice.getTotalMass();
722 std::vector<ValueType> stateActionRewards(rewardExpressions.size(), storm::utility::zero<ValueType>());
723 for (
auto const& choice : allChoices) {
724 if (hasStateActionRewards) {
725 for (uint_fast64_t rewardVariableIndex = 0; rewardVariableIndex < rewardExpressions.size(); ++rewardVariableIndex) {
726 stateActionRewards[rewardVariableIndex] += choice.getRewards()[rewardVariableIndex] * choice.getTotalMass() / totalExitRate;
734 globalChoice.
addRewards(std::move(stateActionRewards));
738 allChoices.push_back(std::move(globalChoice));
742 for (
auto& choice : allChoices) {
746 this->postprocess(result);
751template<
typename ValueType,
typename StateType>
754 StateToIdCallback stateToIdCallback) {
756 boost::optional<ValueType> exitRate = boost::none;
758 exitRate = this->evaluator->asRational(edge.
getRate());
761 Choice<ValueType> choice(edge.
getActionIndex(),
static_cast<bool>(exitRate));
762 std::vector<ValueType> stateActionRewards;
765 TransientVariableValuation<ValueType> transientVariableValuation;
767 stateActionRewards.resize(rewardModelInformation.size(), storm::utility::zero<ValueType>());
771 transientVariableValuation.clear();
773 transientVariableValuation.setInEvaluator(*this->evaluator, this->getOptions().isExplorationChecksSet());
775 stateActionRewards = evaluateRewardExpressions();
776 transientVariableInformation.setDefaultValuesInEvaluator(*this->evaluator);
780 ValueType probabilitySum = storm::utility::zero<ValueType>();
781 for (
auto const& destination : edge.getDestinations()) {
784 if (probability != storm::utility::zero<ValueType>()) {
785 bool evaluatorChanged =
false;
792 applyUpdate(newState, destination, this->variableInformation.locationVariables[automatonIndex], assignmentLevel, *this->evaluator);
793 if (hasTransientAssignments) {
795 "Transition rewards are not supported and scaling to action rewards is disabled.");
796 transientVariableValuation.clear();
799 transientVariableValuation.setInEvaluator(*this->evaluator, this->getOptions().isExplorationChecksSet());
800 evaluatorChanged =
true;
802 if (assignmentLevel < highestLevel) {
803 while (assignmentLevel < highestLevel) {
806 evaluatorChanged =
true;
807 applyUpdate(newState, destination, this->variableInformation.locationVariables[automatonIndex], assignmentLevel, *this->evaluator);
808 if (hasTransientAssignments) {
809 transientVariableValuation.clear();
812 transientVariableValuation.setInEvaluator(*this->evaluator, this->getOptions().isExplorationChecksSet());
813 evaluatorChanged =
true;
817 if (evaluateRewardExpressionsAtDestinations) {
819 evaluatorChanged =
true;
820 addEvaluatedRewardExpressions(stateActionRewards, probability);
823 if (evaluatorChanged) {
826 if (hasTransientAssignments) {
827 this->transientVariableInformation.setDefaultValuesInEvaluator(*this->evaluator);
831 StateType stateIndex = stateToIdCallback(newState);
834 probability = exitRate ? exitRate.get() * probability : probability;
835 choice.addProbability(stateIndex, probability);
838 probabilitySum += probability;
844 choice.addRewards(std::move(stateActionRewards));
849 storm::exceptions::WrongFormatException,
"Probabilities do not sum to one for edge (actually sum to " << probabilitySum <<
").");
855template<
typename ValueType,
typename StateType>
856void JaniNextStateGenerator<ValueType, StateType>::generateSynchronizedDistribution(
storm::storage::BitVector const& state,
857 AutomataEdgeSets
const& edgeCombination,
858 std::vector<EdgeSetWithIndices::const_iterator>
const& iteratorList,
860 std::vector<ValueType>& stateActionRewards, EdgeIndexSet& edgeIndices,
861 StateToIdCallback stateToIdCallback) {
863 int64_t lowestDestinationAssignmentLevel = std::numeric_limits<int64_t>::max();
864 int64_t highestDestinationAssignmentLevel = std::numeric_limits<int64_t>::min();
865 int64_t lowestEdgeAssignmentLevel = std::numeric_limits<int64_t>::max();
866 int64_t highestEdgeAssignmentLevel = std::numeric_limits<int64_t>::min();
867 uint64_t numDestinations = 1;
868 for (uint_fast64_t i = 0;
i < iteratorList.size(); ++
i) {
869 if (this->getOptions().isBuildChoiceOriginsSet()) {
870 auto automatonIndex = model.
getAutomatonIndex(parallelAutomata[edgeCombination[i].first].get().getName());
884 TransientVariableValuation<ValueType> transientVariableValuation;
885 if (evaluateRewardExpressionsAtEdges && lowestEdgeAssignmentLevel <= highestEdgeAssignmentLevel) {
886 for (int64_t assignmentLevel = lowestEdgeAssignmentLevel; assignmentLevel <= highestEdgeAssignmentLevel; ++assignmentLevel) {
887 transientVariableValuation.clear();
888 for (uint_fast64_t i = 0;
i < iteratorList.size(); ++
i) {
892 transientVariableValuation.setInEvaluator(*this->evaluator, this->getOptions().isExplorationChecksSet());
894 addEvaluatedRewardExpressions(stateActionRewards, storm::utility::one<ValueType>());
895 transientVariableInformation.setDefaultValuesInEvaluator(*this->evaluator);
898 std::vector<storm::jani::EdgeDestination const*> destinations;
899 std::vector<LocationVariableInformation const*> locationVars;
900 destinations.reserve(iteratorList.size());
901 locationVars.reserve(iteratorList.size());
903 for (uint64_t destinationId = 0; destinationId < numDestinations; ++destinationId) {
905 destinations.clear();
906 locationVars.clear();
907 transientVariableValuation.clear();
909 ValueType successorProbability = storm::utility::one<ValueType>();
911 uint64_t destinationIndex = destinationId;
912 for (uint64_t i = 0;
i < iteratorList.size(); ++
i) {
916 destinations.push_back(&edge.
getDestination(localDestinationIndex));
917 locationVars.push_back(&this->variableInformation.locationVariables[edgeCombination[i].first]);
919 ValueType probability = this->evaluator->asRational(destinations.back()->getProbability());
921 successorProbability *= probability * this->evaluator->asRational(edge.
getRate());
923 successorProbability *= probability;
929 applyUpdate(successorState, *destinations.back(), *locationVars.back(), lowestDestinationAssignmentLevel, *this->evaluator);
930 applyTransientUpdate(transientVariableValuation,
931 destinations.back()->getOrderedAssignments().getTransientAssignments(lowestDestinationAssignmentLevel), *this->evaluator);
935 bool evaluatorChanged =
false;
937 for (int64_t assignmentLevel = lowestDestinationAssignmentLevel + 1; assignmentLevel <= highestDestinationAssignmentLevel; ++assignmentLevel) {
939 transientVariableValuation.setInEvaluator(*this->evaluator, this->getOptions().isExplorationChecksSet());
940 transientVariableValuation.clear();
941 evaluatorChanged =
true;
942 auto locationVarIt = locationVars.begin();
943 for (
auto const& destPtr : destinations) {
944 applyUpdate(successorState, *destPtr, **locationVarIt, assignmentLevel, *this->evaluator);
945 applyTransientUpdate(transientVariableValuation, destinations.back()->getOrderedAssignments().getTransientAssignments(assignmentLevel),
950 if (!transientVariableValuation.empty()) {
951 evaluatorChanged =
true;
952 transientVariableValuation.setInEvaluator(*this->evaluator, this->getOptions().isExplorationChecksSet());
954 if (evaluateRewardExpressionsAtDestinations) {
956 evaluatorChanged =
true;
957 addEvaluatedRewardExpressions(stateActionRewards, successorProbability);
959 if (evaluatorChanged) {
962 this->transientVariableInformation.setDefaultValuesInEvaluator(*this->evaluator);
965 StateType
id = stateToIdCallback(successorState);
966 distribution.
add(
id, successorProbability);
971template<
typename ValueType,
typename StateType>
972void JaniNextStateGenerator<ValueType, StateType>::expandSynchronizingEdgeCombination(AutomataEdgeSets
const& edgeCombination, uint64_t outputActionIndex,
974 std::vector<Choice<ValueType>>& newChoices) {
977 checkGlobalVariableWritesValid(edgeCombination);
980 std::vector<EdgeSetWithIndices::const_iterator> iteratorList(edgeCombination.size());
983 for (
size_t i = 0;
i < edgeCombination.size(); ++
i) {
984 iteratorList[
i] = edgeCombination[
i].second.cbegin();
992 distribution.
clear();
994 EdgeIndexSet edgeIndices;
995 std::vector<ValueType> stateActionRewards(rewardExpressions.size(), storm::utility::zero<ValueType>());
998 generateSynchronizedDistribution(state, edgeCombination, iteratorList, distribution, stateActionRewards, edgeIndices, stateToIdCallback);
1004 newChoices.emplace_back(outputActionIndex);
1007 Choice<ValueType>& choice = newChoices.back();
1010 if (this->getOptions().isBuildChoiceOriginsSet()) {
1011 choice.addOriginData(boost::any(std::move(edgeIndices)));
1015 choice.addRewards(std::move(stateActionRewards));
1018 ValueType probabilitySum = storm::utility::zero<ValueType>();
1019 choice.reserve(std::distance(distribution.
begin(), distribution.
end()));
1020 for (
auto const& stateProbability : distribution) {
1021 choice.addProbability(stateProbability.getState(), stateProbability.getValue());
1024 probabilitySum += stateProbability.getValue();
1031 storm::exceptions::WrongFormatException,
1032 "Sum of update probabilities do not sum to one for some edge (actually sum to " << probabilitySum <<
").");
1042 bool movedIterator =
false;
1043 for (uint64_t j = 0; !movedIterator && j < iteratorList.size(); ++j) {
1045 if (iteratorList[j] != edgeCombination[j].second.end()) {
1046 movedIterator =
true;
1049 iteratorList[j] = edgeCombination[j].second.begin();
1053 done = !movedIterator;
1057template<
typename ValueType,
typename StateType>
1058std::vector<Choice<ValueType>> JaniNextStateGenerator<ValueType, StateType>::getActionChoices(std::vector<uint64_t>
const& locations,
1060 EdgeFilter
const& edgeFilter) {
1061 std::vector<Choice<ValueType>> result;
1065 std::vector<EdgeSetWithIndices const*> edgeSetsMemory;
1067 std::vector<typename EdgeSetWithIndices::const_iterator> edgeIteratorMemory;
1069 for (OutputAndEdges
const& outputAndEdges : edges) {
1070 auto const& edges = outputAndEdges.second;
1071 if (edges.size() == 1) {
1073 auto const& nonsychingEdges = edges.front();
1074 uint64_t automatonIndex = nonsychingEdges.first;
1076 auto edgesIt = nonsychingEdges.second.find(locations[automatonIndex]);
1077 if (edgesIt != nonsychingEdges.second.end()) {
1078 for (
auto const& indexAndEdge : edgesIt->second) {
1079 if (edgeFilter != EdgeFilter::All) {
1080 STORM_LOG_ASSERT(edgeFilter == EdgeFilter::WithRate || edgeFilter == EdgeFilter::WithoutRate,
"Unexpected edge filter.");
1081 if ((edgeFilter == EdgeFilter::WithRate) != indexAndEdge.second->hasRate()) {
1085 if (!this->evaluator->asBool(indexAndEdge.second->getGuard())) {
1089 uint64_t actionIndex = outputAndEdges.first ? outputAndEdges.first.get() : indexAndEdge.second->getActionIndex();
1090 result.push_back(expandNonSynchronizingEdge(*indexAndEdge.second, actionIndex, automatonIndex, state, stateToIdCallback));
1092 if (this->getOptions().isBuildChoiceOriginsSet()) {
1093 auto modelAutomatonIndex = model.
getAutomatonIndex(parallelAutomata[automatonIndex].get().getName());
1095 result.back().addOriginData(boost::any(std::move(edgeIndex)));
1098 if (this->getOptions().isBuildChoiceLabelsSet()) {
1109 STORM_LOG_ASSERT(outputAndEdges.first,
"Need output action index for synchronization.");
1111 uint64_t outputActionIndex = outputAndEdges.first.get();
1114 bool productiveCombination =
true;
1117 edgeSetsMemory.clear();
1118 for (
auto const& automatonAndEdges : outputAndEdges.second) {
1119 uint64_t automatonIndex = automatonAndEdges.first;
1120 LocationsAndEdges
const& locationsAndEdges = automatonAndEdges.second;
1121 auto edgesIt = locationsAndEdges.find(locations[automatonIndex]);
1122 if (edgesIt == locationsAndEdges.end()) {
1123 productiveCombination =
false;
1126 edgeSetsMemory.push_back(&edgesIt->second);
1129 if (productiveCombination) {
1131 edgeIteratorMemory.clear();
1132 for (
auto const& edgesIt : edgeSetsMemory) {
1133 bool atLeastOneEdge =
false;
1134 EdgeSetWithIndices
const& edgeSetWithIndices = *edgesIt;
1135 for (
auto indexAndEdgeIt = edgeSetWithIndices.begin(), indexAndEdgeIte = edgeSetWithIndices.end(); indexAndEdgeIt != indexAndEdgeIte;
1138 if (edgeFilter != EdgeFilter::All) {
1139 STORM_LOG_ASSERT(edgeFilter == EdgeFilter::WithRate || edgeFilter == EdgeFilter::WithoutRate,
"Unexpected edge filter.");
1140 if ((edgeFilter == EdgeFilter::WithRate) != indexAndEdgeIt->second->hasRate()) {
1145 if (!this->evaluator->asBool(indexAndEdgeIt->second->getGuard())) {
1150 atLeastOneEdge =
true;
1151 edgeIteratorMemory.push_back(indexAndEdgeIt);
1156 if (!atLeastOneEdge) {
1157 productiveCombination =
false;
1164 if (productiveCombination) {
1165 AutomataEdgeSets automataEdgeSets;
1166 automataEdgeSets.reserve(outputAndEdges.second.size());
1167 STORM_LOG_ASSERT(edgeSetsMemory.size() == outputAndEdges.second.size(),
"Unexpected number of edge sets stored.");
1168 STORM_LOG_ASSERT(edgeIteratorMemory.size() == outputAndEdges.second.size(),
"Unexpected number of edge iterators stored.");
1169 auto edgeSetIt = edgeSetsMemory.begin();
1170 auto edgeIteratorIt = edgeIteratorMemory.begin();
1171 for (
auto const& automatonAndEdges : outputAndEdges.second) {
1172 EdgeSetWithIndices enabledEdgesOfAutomaton;
1173 uint64_t automatonIndex = automatonAndEdges.first;
1174 EdgeSetWithIndices
const& edgeSetWithIndices = **edgeSetIt;
1175 auto indexAndEdgeIt = *edgeIteratorIt;
1177 enabledEdgesOfAutomaton.emplace_back(*indexAndEdgeIt);
1178 auto indexAndEdgeIte = edgeSetWithIndices.end();
1179 for (++indexAndEdgeIt; indexAndEdgeIt != indexAndEdgeIte; ++indexAndEdgeIt) {
1181 if (edgeFilter != EdgeFilter::All) {
1182 STORM_LOG_ASSERT(edgeFilter == EdgeFilter::WithRate || edgeFilter == EdgeFilter::WithoutRate,
"Unexpected edge filter.");
1183 if ((edgeFilter == EdgeFilter::WithRate) != indexAndEdgeIt->second->hasRate()) {
1188 if (!this->evaluator->asBool(indexAndEdgeIt->second->getGuard())) {
1192 enabledEdgesOfAutomaton.emplace_back(*indexAndEdgeIt);
1194 automataEdgeSets.emplace_back(std::move(automatonIndex), std::move(enabledEdgesOfAutomaton));
1199 expandSynchronizingEdgeCombination(automataEdgeSets, outputActionIndex, state, stateToIdCallback, result);
1207template<
typename ValueType,
typename StateType>
1208void JaniNextStateGenerator<ValueType, StateType>::checkGlobalVariableWritesValid(AutomataEdgeSets
const& enabledEdges)
const {
1211 std::map<storm::expressions::Variable, uint64_t> writtenGlobalVariables;
1212 for (
auto edgeSetIt = enabledEdges.begin(), edgeSetIte = enabledEdges.end(); edgeSetIt != edgeSetIte; ++edgeSetIt) {
1213 for (
auto const& indexAndEdge : edgeSetIt->second) {
1214 for (
auto const& globalVariable : indexAndEdge.second->getWrittenGlobalVariables()) {
1215 auto it = writtenGlobalVariables.find(globalVariable);
1217 auto index = std::distance(enabledEdges.begin(), edgeSetIt);
1218 if (it != writtenGlobalVariables.end()) {
1219 STORM_LOG_THROW(it->second ==
static_cast<uint64_t
>(index), storm::exceptions::WrongFormatException,
1220 "Multiple writes to global variable '" << globalVariable.getName() <<
"' in synchronizing edges.");
1222 writtenGlobalVariables.emplace(globalVariable, index);
1229template<
typename ValueType,
typename StateType>
1231 return rewardExpressions.size();
1234template<
typename ValueType,
typename StateType>
1236 return rewardModelInformation[index];
1239template<
typename ValueType,
typename StateType>
1241 std::vector<StateType>
const& initialStateIndices,
1242 std::vector<StateType>
const& deadlockStateIndices,
1243 std::vector<StateType>
const& unexploredStateIndices) {
1246 std::vector<std::pair<std::string, storm::expressions::Expression>> transientVariableExpressions;
1248 if (variable.getType().isBasicType() && variable.getType().asBasicType().isBooleanType()) {
1250 transientVariableExpressions.emplace_back(variable.getName(), variable.getExpressionVariable().getExpression());
1255 transientVariableExpressions);
1258template<
typename ValueType,
typename StateType>
1260 std::vector<ValueType> result;
1261 result.reserve(rewardExpressions.size());
1262 for (
auto const& rewardExpression : rewardExpressions) {
1263 result.push_back(this->evaluator->asRational(rewardExpression.second));
1268template<
typename ValueType,
typename StateType>
1269void JaniNextStateGenerator<ValueType, StateType>::addEvaluatedRewardExpressions(std::vector<ValueType>& rewards, ValueType
const& factor)
const {
1270 assert(rewards.size() == rewardExpressions.size());
1271 auto rewIt = rewards.begin();
1272 for (
auto const& rewardExpression : rewardExpressions) {
1273 (*rewIt) += factor * this->evaluator->asRational(rewardExpression.second);
1278template<
typename ValueType,
typename StateType>
1279void JaniNextStateGenerator<ValueType, StateType>::buildRewardModelInformation() {
1280 for (
auto const& rewardModel : rewardExpressions) {
1282 rewardModelInformation.emplace_back(rewardModel.first, info.hasStateRewards(),
false,
false);
1284 "Transition rewards are not supported and a reduction to action-based rewards was not possible.");
1285 if (info.hasTransitionRewards()) {
1286 evaluateRewardExpressionsAtDestinations =
true;
1288 if (info.hasActionRewards() || (this->options.isScaleAndLiftTransitionRewardsSet() && info.hasTransitionRewards())) {
1289 hasStateActionRewards =
true;
1290 rewardModelInformation.back().setHasStateActionRewards();
1293 if (!hasStateActionRewards) {
1294 evaluateRewardExpressionsAtDestinations =
false;
1295 evaluateRewardExpressionsAtEdges =
false;
1299template<
typename ValueType,
typename StateType>
1300void JaniNextStateGenerator<ValueType, StateType>::createSynchronizationInformation() {
1305 this->parallelAutomata.push_back(automaton);
1307 LocationsAndEdges locationsAndEdges;
1308 uint64_t edgeIndex = 0;
1309 for (
auto const& edge : automaton.getEdges()) {
1314 AutomataAndEdges automataAndEdges;
1315 automataAndEdges.emplace_back(std::make_pair(0, std::move(locationsAndEdges)));
1317 this->edges.emplace_back(std::make_pair(boost::none, std::move(automataAndEdges)));
1322 uint64_t automatonIndex = 0;
1323 for (
auto const& composition : parallelComposition.getSubcompositions()) {
1324 STORM_LOG_THROW(composition->isAutomatonComposition(), storm::exceptions::WrongFormatException,
"Expected flat parallel composition.");
1325 STORM_LOG_THROW(composition->asAutomatonComposition().getInputEnabledActions().empty(), storm::exceptions::NotSupportedException,
1326 "Input-enabled actions are not supported right now.");
1328 this->parallelAutomata.push_back(this->model.
getAutomaton(composition->asAutomatonComposition().getAutomatonName()));
1331 LocationsAndEdges locationsAndEdges;
1332 uint64_t edgeIndex = 0;
1333 for (
auto const& edge : parallelAutomata.back().get().getEdges()) {
1340 if (!locationsAndEdges.empty()) {
1341 AutomataAndEdges automataAndEdges;
1342 automataAndEdges.emplace_back(std::make_pair(automatonIndex, std::move(locationsAndEdges)));
1343 this->edges.emplace_back(std::make_pair(boost::none, std::move(automataAndEdges)));
1348 for (
auto const& vector : parallelComposition.getSynchronizationVectors()) {
1349 uint64_t outputActionIndex = this->model.
getActionIndex(vector.getOutput());
1351 AutomataAndEdges automataAndEdges;
1352 bool atLeastOneEdge =
true;
1353 uint64_t automatonIndex = 0;
1354 for (
auto const& element : vector.getInput()) {
1356 LocationsAndEdges locationsAndEdges;
1358 uint64_t edgeIndex = 0;
1359 for (
auto const& edge : parallelAutomata[automatonIndex].get().getEdges()) {
1365 if (locationsAndEdges.empty()) {
1366 atLeastOneEdge =
false;
1369 automataAndEdges.emplace_back(std::make_pair(automatonIndex, std::move(locationsAndEdges)));
1374 if (atLeastOneEdge) {
1375 this->edges.emplace_back(std::make_pair(outputActionIndex, std::move(automataAndEdges)));
1380 STORM_LOG_TRACE(
"Number of synchronizations: " << this->edges.size() <<
".");
1383template<
typename ValueType,
typename StateType>
1385 std::vector<boost::any>& dataForChoiceOrigins)
const {
1386 if (!this->getOptions().isBuildChoiceOriginsSet()) {
1390 std::vector<uint_fast64_t> identifiers;
1391 identifiers.reserve(dataForChoiceOrigins.size());
1393 std::map<EdgeIndexSet, uint_fast64_t> edgeIndexSetToIdentifierMap;
1396 edgeIndexSetToIdentifierMap.insert(std::make_pair(
EdgeIndexSet(), 0));
1397 uint_fast64_t currentIdentifier = 1;
1398 for (boost::any& originData : dataForChoiceOrigins) {
1399 STORM_LOG_ASSERT(originData.empty() || boost::any_cast<EdgeIndexSet>(&originData) !=
nullptr,
1400 "Origin data has unexpected type: " << originData.type().name() <<
".");
1402 EdgeIndexSet currentEdgeIndexSet = originData.empty() ?
EdgeIndexSet() : boost::any_cast<EdgeIndexSet>(std::move(originData));
1403 auto insertionRes = edgeIndexSetToIdentifierMap.emplace(std::move(currentEdgeIndexSet), currentIdentifier);
1404 identifiers.push_back(insertionRes.first->second);
1405 if (insertionRes.second) {
1406 ++currentIdentifier;
1410 std::vector<EdgeIndexSet> identifierToEdgeIndexSetMapping(currentIdentifier);
1411 for (
auto const& setIdPair : edgeIndexSetToIdentifierMap) {
1412 identifierToEdgeIndexSetMapping[setIdPair.second] = setIdPair.first;
1415 return std::make_shared<storm::storage::sparse::JaniChoiceOrigins>(std::make_shared<storm::jani::Model>(model), std::move(identifiers),
1416 std::move(identifierToEdgeIndexSetMapping));
1419template<
typename ValueType,
typename StateType>
1421 STORM_LOG_WARN(
"There are no observation labels in JANI currenty");
1425template<
typename ValueType,
typename StateType>
1426void JaniNextStateGenerator<ValueType, StateType>::checkValid()
const {
1428#ifdef STORM_HAVE_CARL
1433 std::vector<std::reference_wrapper<storm::jani::Constant const>> undefinedConstants = model.
getUndefinedConstants();
1434 std::stringstream stream;
1435 bool printComma =
false;
1436 for (
auto const& constant : undefinedConstants) {
1442 stream << constant.get().getName() <<
" (" << constant.get().getType() <<
")";
1445 STORM_LOG_THROW(
false, storm::exceptions::InvalidArgumentException,
"Program still contains these undefined constants: " + stream.str());
1447#ifdef STORM_HAVE_CARL
1450 "The input model contains undefined constants that influence the graph structure of the underlying model, which is not allowed.");
1455template class JaniNextStateGenerator<double>;
1457#ifdef STORM_HAVE_CARL
1458template class JaniNextStateGenerator<storm::RationalNumber>;
1459template class JaniNextStateGenerator<storm::RationalFunction>;
uint64_t getReservedBitsForUnboundedVariables() const
bool isScaleAndLiftTransitionRewardsSet() const
bool isBuildAllRewardModelsSet() const
bool isBuildChoiceLabelsSet() const
bool isBuildChoiceOriginsSet() const
BuilderOptions & substituteExpressions(std::function< storm::expressions::Expression(storm::expressions::Expression const &)> const &substitutionFunction)
Substitutes all expressions occurring in these options.
bool isExplorationChecksSet() const
bool isBuildAllLabelsSet() const
bool hasTerminalStates() const
bool isAddOverlappingGuardLabelSet() const
bool isAddOutOfBoundsStateSet() const
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.
bool isIntegerType() const
Checks whether this type is an integral type.
bool isRationalType() const
Checks whether this type is a rational type.
storm::expressions::Expression getExpression() const
Retrieves an expression that represents 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 void addStateValuation(storm::storage::sparse::state_type const ¤tStateIndex, 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 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 bool isDeterministicModel() 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 & 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.
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.
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.
VariableSet & getGlobalVariables()
Retrieves the variables of this automaton.
storm::expressions::ExpressionManager & getExpressionManager() const
Retrieves the manager responsible for the expressions in the JANI model.
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.
storm::expressions::Expression getInitialStatesExpression() const
Retrieves the expression defining the legal initial values of the variables.
static const uint64_t SILENT_ACTION_INDEX
The index of the silent action.
ModelType const & getModelType() const
Retrieves the type of the model.
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....
bool isDeterministicModel() const
Determines whether this model is a deterministic one in the sense that each state only has one choice...
void simplifyComposition()
Attempts to simplify the composition.
bool isDiscreteTimeModel() const
Determines whether this model is a discrete-time model.
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.
ArrayEliminatorData eliminateArrays(bool keepNonTrivialArrayAccess=false)
Eliminates occurring array variables and expressions by replacing array variables by multiple basic v...
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.
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.
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.
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.
#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
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)
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 &)
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.
storm::expressions::Expression transformExpression(storm::expressions::Expression const &arrayExpression) const