Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
MemoryIncorporation.cpp
Go to the documentation of this file.
2
15
17
20namespace storm {
21namespace transformer {
22
23template<class SparseModelType>
24storm::storage::MemoryStructure getGoalMemory(SparseModelType const& model, storm::logic::Formula const& propositionalGoalStateFormula) {
25 STORM_LOG_THROW(propositionalGoalStateFormula.isInFragment(storm::logic::propositional()), storm::exceptions::NotSupportedException,
26 "The subformula " << propositionalGoalStateFormula << " should be propositional.");
27
29 storm::storage::BitVector goalStates = mc.check(propositionalGoalStateFormula)->asExplicitQualitativeCheckResult().getTruthValuesVector();
30
31 // Check if the formula is already satisfied for all initial states. In such a case the trivial memory structure suffices.
32 if (model.getInitialStates().isSubsetOf(goalStates)) {
33 STORM_LOG_INFO("One objective is already satisfied for all initial states.");
34 return storm::storage::MemoryStructureBuilder<typename SparseModelType::ValueType,
35 typename SparseModelType::RewardModelType>::buildTrivialMemoryStructure(model);
36 }
37
38 // Create a memory structure that stores whether a goal state has already been reached
40 builder.setTransition(0, 0, ~goalStates);
41 builder.setTransition(0, 1, goalStates);
42 builder.setTransition(1, 1, storm::storage::BitVector(model.getNumberOfStates(), true));
43 for (auto initState : model.getInitialStates()) {
44 builder.setInitialMemoryState(initState, goalStates.get(initState) ? 1 : 0);
45 }
46 return builder.build();
47}
48
49template<class SparseModelType>
50storm::storage::MemoryStructure getUntilFormulaMemory(SparseModelType const& model, storm::logic::Formula const& leftSubFormula,
51 storm::logic::Formula const& rightSubFormula) {
52 auto notLeftOrRight = std::make_shared<storm::logic::BinaryBooleanStateFormula>(
53 storm::logic::BinaryBooleanStateFormula::OperatorType::Or,
54 std::make_shared<storm::logic::UnaryBooleanStateFormula>(storm::logic::UnaryBooleanStateFormula::OperatorType::Not, leftSubFormula.asSharedPointer()),
55 rightSubFormula.asSharedPointer());
56 return getGoalMemory<SparseModelType>(model, *notLeftOrRight);
57}
58
59template<class SparseModelType>
61 SparseModelType const& model, std::vector<std::shared_ptr<storm::logic::Formula const>> const& formulas) {
63
64 for (auto const& subFormula : formulas) {
65 STORM_LOG_THROW(subFormula->isOperatorFormula(), storm::exceptions::NotSupportedException, "The given Formula " << *subFormula << " is not supported.");
66 auto const& subsubFormula = subFormula->asOperatorFormula().getSubformula();
67 if (subsubFormula.isEventuallyFormula()) {
68 memory = memory.product(getGoalMemory(model, subsubFormula.asEventuallyFormula().getSubformula()));
69 } else if (subsubFormula.isUntilFormula()) {
70 memory = memory.product(
71 getUntilFormulaMemory(model, subsubFormula.asUntilFormula().getLeftSubformula(), subsubFormula.asUntilFormula().getRightSubformula()));
72 } else if (subsubFormula.isBoundedUntilFormula()) {
73 // For bounded formulas it is only reasonable to add the goal memory if it considers a single upper step/time bound.
74 auto const& buf = subsubFormula.asBoundedUntilFormula();
75 if (!buf.isMultiDimensional() && !buf.getTimeBoundReference().isRewardBound() &&
76 (!buf.hasLowerBound() || (!buf.isLowerBoundStrict() && storm::utility::isZero(buf.template getLowerBound<storm::RationalNumber>())))) {
77 memory = memory.product(getUntilFormulaMemory(model, buf.getLeftSubformula(), buf.getRightSubformula()));
78 }
79 } else if (subsubFormula.isGloballyFormula()) {
80 auto notPhi = std::make_shared<storm::logic::UnaryBooleanStateFormula>(storm::logic::UnaryBooleanStateFormula::OperatorType::Not,
81 subsubFormula.asGloballyFormula().getSubformula().asSharedPointer());
82 memory = memory.product(getGoalMemory(model, *notPhi));
83 } else {
84 STORM_LOG_THROW(subFormula->isLongRunAverageOperatorFormula() || subsubFormula.isTotalRewardFormula() ||
85 subsubFormula.isCumulativeRewardFormula() || subsubFormula.isLongRunAverageRewardFormula(),
86 storm::exceptions::NotSupportedException, "The given Formula " << subsubFormula << " is not supported.");
87 }
88 }
89
91 return std::dynamic_pointer_cast<SparseModelType>(product.build());
92}
93
94template<class SparseModelType>
99
100template<class SparseModelType>
106
109
112
113} // namespace transformer
114} // namespace storm
bool isInFragment(FragmentSpecification const &fragment) const
Definition Formula.cpp:196
std::shared_ptr< Formula const > asSharedPointer()
Definition Formula.cpp:548
virtual std::unique_ptr< CheckResult > check(Environment const &env, CheckTask< storm::logic::Formula, SolutionType > const &checkTask)
Checks the provided formula.
A bit vector that is internally represented as a vector of 64-bit values.
Definition BitVector.h:18
bool get(uint_fast64_t index) const
Retrieves the truth value of the bit at the given index and performs a bound check.
void setInitialMemoryState(uint_fast64_t initialModelState, uint_fast64_t initialMemoryState)
Specifies for the given state of the model the corresponding initial memory state.
MemoryStructure build()
Builds the memory structure.
static MemoryStructure buildTrivialMemoryStructure(storm::models::sparse::Model< ValueType, RewardModelType > const &model)
Builds a trivial memory structure for the given model (consisting of a single memory state)
void setTransition(uint_fast64_t const &startState, uint_fast64_t const &goalState, storm::storage::BitVector const &modelStates, boost::optional< storm::storage::BitVector > const &modelChoices=boost::none)
Specifies a transition of the memory structure.
This class represents a (deterministic) memory structure that can be used to encode certain events (s...
MemoryStructure product(MemoryStructure const &rhs) const
Builds the product of this memory structure and the given memory structure.
NondeterministicMemoryStructure build(NondeterministicMemoryStructurePattern pattern, uint64_t numStates) const
This class builds the product of the given sparse model and the given memory structure.
std::shared_ptr< storm::models::sparse::Model< ValueType, RewardModelType > > build()
Incorporates Memory into the state space of the given model, that is the resulting model is the cross...
static std::shared_ptr< SparseModelType > incorporateFullMemory(SparseModelType const &model, uint64_t memoryStates)
Incorporates a memory structure where the nondeterminism of the model decides which successor state t...
static std::shared_ptr< SparseModelType > incorporateGoalMemory(SparseModelType const &model, std::vector< std::shared_ptr< storm::logic::Formula const > > const &formulas)
Incorporates memory that stores whether a 'goal' state has already been reached.
static std::shared_ptr< SparseModelType > incorporateCountingMemory(SparseModelType const &model, uint64_t memoryStates)
Incorporates a memory structure where the nondeterminism of the model can increment a counter.
#define STORM_LOG_INFO(message)
Definition logging.h:29
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:30
FragmentSpecification propositional()
storm::storage::MemoryStructure getGoalMemory(SparseModelType const &model, storm::logic::Formula const &propositionalGoalStateFormula)
storm::storage::MemoryStructure getUntilFormulaMemory(SparseModelType const &model, storm::logic::Formula const &leftSubFormula, storm::logic::Formula const &rightSubFormula)
bool isZero(ValueType const &a)
Definition constants.cpp:41
LabParser.cpp.
Definition cli.cpp:18