Storm 1.13.0.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
MemoryIncorporation.cpp
Go to the documentation of this file.
2
17
18namespace storm {
19namespace transformer {
20
21template<class SparseModelType>
22storm::storage::MemoryStructure getGoalMemory(SparseModelType const& model, storm::logic::Formula const& propositionalGoalStateFormula) {
23 STORM_LOG_THROW(propositionalGoalStateFormula.isInFragment(storm::logic::propositional()), storm::exceptions::NotSupportedException,
24 "The subformula " << propositionalGoalStateFormula << " should be propositional.");
25
27 storm::storage::BitVector goalStates =
28 mc.check(propositionalGoalStateFormula)->template asExplicitQualitativeCheckResult<typename SparseModelType::ValueType>().getTruthValuesVector();
29
30 // Check if the formula is already satisfied for all initial states. In such a case the trivial memory structure suffices.
31 if (model.getInitialStates().isSubsetOf(goalStates)) {
32 STORM_LOG_INFO("One objective is already satisfied for all initial states.");
33 return storm::storage::MemoryStructureBuilder<typename SparseModelType::ValueType,
34 typename SparseModelType::RewardModelType>::buildTrivialMemoryStructure(model);
35 }
36
37 // Create a memory structure that stores whether a goal state has already been reached
39 builder.setTransition(0, 0, ~goalStates);
40 builder.setTransition(0, 1, goalStates);
41 builder.setTransition(1, 1, storm::storage::BitVector(model.getNumberOfStates(), true));
42 for (auto initState : model.getInitialStates()) {
43 builder.setInitialMemoryState(initState, goalStates.get(initState) ? 1 : 0);
44 }
45 return builder.build();
46}
47
48template<class SparseModelType>
49storm::storage::MemoryStructure getUntilFormulaMemory(SparseModelType const& model, storm::logic::Formula const& leftSubFormula,
50 storm::logic::Formula const& rightSubFormula) {
51 auto notLeftOrRight = std::make_shared<storm::logic::BinaryBooleanStateFormula>(
52 storm::logic::BinaryBooleanStateFormula::OperatorType::Or,
53 std::make_shared<storm::logic::UnaryBooleanStateFormula>(storm::logic::UnaryBooleanStateFormula::OperatorType::Not, leftSubFormula.asSharedPointer()),
54 rightSubFormula.asSharedPointer());
55 return getGoalMemory<SparseModelType>(model, *notLeftOrRight);
56}
57
58template<class SparseModelType>
60 std::vector<std::shared_ptr<storm::logic::Formula const>> const& formulas) {
63 model);
64
65 for (auto const& subFormula : formulas) {
66 STORM_LOG_THROW(subFormula->isOperatorFormula(), storm::exceptions::NotSupportedException, "The given Formula " << *subFormula << " is not supported.");
67 auto const& subsubFormula = subFormula->asOperatorFormula().getSubformula();
68 if (subsubFormula.isEventuallyFormula()) {
69 memory = memory.product(getGoalMemory(model, subsubFormula.asEventuallyFormula().getSubformula()));
70 } else if (subsubFormula.isUntilFormula()) {
71 memory = memory.product(
72 getUntilFormulaMemory(model, subsubFormula.asUntilFormula().getLeftSubformula(), subsubFormula.asUntilFormula().getRightSubformula()));
73 } else if (subsubFormula.isBoundedUntilFormula()) {
74 // For bounded formulas it is only reasonable to add the goal memory if it considers a single upper step/time bound.
75 auto const& buf = subsubFormula.asBoundedUntilFormula();
76 if (!buf.isMultiDimensional() && !buf.getTimeBoundReference().isRewardBound() &&
77 (!buf.hasLowerBound() || (!buf.isLowerBoundStrict() && storm::utility::isZero(buf.template getLowerBound<storm::RationalNumber>())))) {
78 memory = memory.product(getUntilFormulaMemory(model, buf.getLeftSubformula(), buf.getRightSubformula()));
79 }
80 } else if (subsubFormula.isGloballyFormula()) {
81 auto notPhi = std::make_shared<storm::logic::UnaryBooleanStateFormula>(storm::logic::UnaryBooleanStateFormula::OperatorType::Not,
82 subsubFormula.asGloballyFormula().getSubformula().asSharedPointer());
83 memory = memory.product(getGoalMemory(model, *notPhi));
84 } else {
85 STORM_LOG_THROW(subFormula->isLongRunAverageOperatorFormula() || subsubFormula.isTotalRewardFormula() ||
86 subsubFormula.isCumulativeRewardFormula() || subsubFormula.isLongRunAverageRewardFormula(),
87 storm::exceptions::NotSupportedException, "The given Formula " << subsubFormula << " is not supported.");
88 }
89 }
90
91 return memory;
92}
93
94template<class SparseModelType>
96 SparseModelType const& model, std::vector<std::shared_ptr<storm::logic::Formula const>> const& formulas) {
97 auto memory = incorporateGoalMemoryHelper(model, formulas);
98 auto product = memory.product(model);
99 return product.build()->template as<SparseModelType>();
100}
101
102template<class SparseModelType>
103std::pair<std::shared_ptr<SparseModelType>, storm::storage::SparseModelMemoryProductReverseData>
105 std::vector<std::shared_ptr<storm::logic::Formula const>> const& formulas) {
106 auto memory = incorporateGoalMemoryHelper(model, formulas);
107 auto product = memory.product(model);
108 auto result = product.build();
109 return std::make_pair(result->template as<SparseModelType>(), product.computeReverseData());
110}
111
112template<class SparseModelType>
117
118template<class SparseModelType>
124
127
130
131} // namespace transformer
132} // namespace storm
bool isInFragment(FragmentSpecification const &fragment) const
Definition Formula.cpp:204
std::shared_ptr< Formula const > asSharedPointer()
Definition Formula.cpp:571
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:16
bool get(uint64_t index) const
Retrieves the truth value of the bit at the given index and performs a bound check.
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).
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
Data to restore memory incorporation applied with SparseModelMemoryProduct.
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::pair< std::shared_ptr< SparseModelType >, storm::storage::SparseModelMemoryProductReverseData > incorporateGoalMemoryWithReverseData(SparseModelType const &model, std::vector< std::shared_ptr< storm::logic::Formula const > > const &formulas)
Like incorporateGoalMemory, but also returns data necessary to translate results (in particular sched...
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:24
#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)
storm::storage::MemoryStructure incorporateGoalMemoryHelper(SparseModelType const &model, std::vector< std::shared_ptr< storm::logic::Formula const > > const &formulas)
bool isZero(ValueType const &a)
Definition constants.cpp:39