Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
FormulaInformation.cpp
Go to the documentation of this file.
9
12
13namespace storm {
14namespace pomdp {
15namespace analysis {
16
18 STORM_LOG_ASSERT(states.empty() == observations.empty(), "Inconsistent StateSet.");
19 return observations.empty();
20}
21
23 // Intentionally left empty
24}
25
26FormulaInformation::FormulaInformation(Type const& type, storm::solver::OptimizationDirection const& dir, std::optional<std::string> const& rewardModelName)
27 : type(type), optimizationDirection(dir), rewardModelName(rewardModelName) {
28 STORM_LOG_ASSERT(!this->rewardModelName.has_value() || this->type == Type::NonNestedExpectedRewardFormula,
29 "Got a reward model name for a non-reward formula.");
30}
31
33 return type;
34}
35
39
43
45 return type == Type::Unsupported;
46}
47
50 "Target states requested for unexpected formula type.");
51 return targetStates.value();
52}
53
55 STORM_LOG_ASSERT(this->type == Type::NonNestedReachabilityProbability, "Sink states requested for unexpected formula type.");
56 return sinkStates.value();
57}
58
59std::string const& FormulaInformation::getRewardModelName() const {
60 STORM_LOG_ASSERT(this->type == Type::NonNestedExpectedRewardFormula, "Reward model requested for unexpected formula type.");
61 return rewardModelName.value();
62}
63
65 return optimizationDirection;
66}
67
69 return storm::solver::minimize(optimizationDirection);
70}
71
73 return storm::solver::maximize(optimizationDirection);
74}
75
76template<typename PomdpType>
79 result.states = std::move(inputStates);
80 for (auto const state : result.states) {
81 result.observations.insert(pomdp.getObservation(state));
82 }
83 // check if this set is observation-closed, i.e., whether there is a state outside of this set with one of the observations collected above
84 result.observationClosed = true;
85 for (uint64_t state = result.states.getNextUnsetIndex(0); state < result.states.size(); state = result.states.getNextUnsetIndex(state + 1)) {
86 if (result.observations.count(pomdp.getObservation(state)) > 0) {
87 result.observationClosed = false;
88 break;
89 }
90 }
91 return result;
92}
93
94template<typename PomdpType>
95void FormulaInformation::updateTargetStates(PomdpType const& pomdp, storm::storage::BitVector&& newTargetStates) {
97 "Target states updated for unexpected formula type.");
98 targetStates = getStateSet(pomdp, std::move(newTargetStates));
99}
100
101template<typename PomdpType>
102void FormulaInformation::updateSinkStates(PomdpType const& pomdp, storm::storage::BitVector&& newSinkStates) {
103 STORM_LOG_ASSERT(this->type == Type::NonNestedReachabilityProbability, "Sink states requested for unexpected formula type.");
104 sinkStates = getStateSet(pomdp, std::move(newSinkStates));
105}
106
107template<typename PomdpType>
108storm::storage::BitVector getStates(storm::logic::Formula const& propositionalFormula, bool formulaInverted, PomdpType const& pomdp) {
110 auto checkResult = mc.check(propositionalFormula);
111 storm::storage::BitVector resultBitVector(checkResult->asExplicitQualitativeCheckResult().getTruthValuesVector());
112 if (formulaInverted) {
113 resultBitVector.complement();
114 }
115 return resultBitVector;
116}
117
118template<typename PomdpType>
120 STORM_LOG_THROW(formula.hasOptimalityType(), storm::exceptions::InvalidPropertyException,
121 "The property does not specify an optimization direction (min/max)");
122 STORM_LOG_WARN_COND(!formula.hasBound(), "The probability threshold for the given property will be ignored.");
123 auto const& subformula = formula.getSubformula();
124 std::shared_ptr<storm::logic::Formula const> targetStatesFormula, constraintsStatesFormula;
125 if (subformula.isEventuallyFormula()) {
126 targetStatesFormula = subformula.asEventuallyFormula().getSubformula().asSharedPointer();
127 constraintsStatesFormula = storm::logic::Formula::getTrueFormula()->asSharedPointer();
128 } else if (subformula.isUntilFormula()) {
129 storm::logic::UntilFormula const& untilFormula = subformula.asUntilFormula();
130 targetStatesFormula = untilFormula.getRightSubformula().asSharedPointer();
131 constraintsStatesFormula = untilFormula.getLeftSubformula().asSharedPointer();
132 }
133 if (targetStatesFormula && targetStatesFormula->isInFragment(storm::logic::propositional()) && constraintsStatesFormula &&
134 constraintsStatesFormula->isInFragment(storm::logic::propositional())) {
136 result.updateTargetStates(pomdp, getStates(*targetStatesFormula, false, pomdp));
137 result.updateSinkStates(pomdp, getStates(*constraintsStatesFormula, true, pomdp));
138 return result;
139 }
140 return FormulaInformation();
141}
142
143template<typename PomdpType>
145 STORM_LOG_THROW(formula.hasOptimalityType(), storm::exceptions::InvalidPropertyException,
146 "The property does not specify an optimization direction (min/max)");
147 STORM_LOG_WARN_COND(!formula.hasBound(), "The reward threshold for the given property will be ignored.");
148 std::string rewardModelName = "";
149 if (formula.hasRewardModelName()) {
150 rewardModelName = formula.getRewardModelName();
151 STORM_LOG_THROW(pomdp.hasRewardModel(rewardModelName), storm::exceptions::InvalidPropertyException,
152 "Selected reward model with name '" << rewardModelName << "' does not exist.");
153 } else {
154 STORM_LOG_THROW(pomdp.hasUniqueRewardModel(), storm::exceptions::InvalidPropertyException,
155 "Reward operator formula does not specify a reward model and the reward model is not unique.");
156 rewardModelName = pomdp.getUniqueRewardModelName();
157 }
158 auto const& subformula = formula.getSubformula();
159 std::shared_ptr<storm::logic::Formula const> targetStatesFormula;
160 if (subformula.isEventuallyFormula()) {
161 targetStatesFormula = subformula.asEventuallyFormula().getSubformula().asSharedPointer();
162 }
163 if (targetStatesFormula && targetStatesFormula->isInFragment(storm::logic::propositional())) {
165 result.updateTargetStates(pomdp, getStates(*targetStatesFormula, false, pomdp));
166 return result;
167 }
168 return FormulaInformation();
169}
170
171template<typename PomdpType>
172FormulaInformation getFormulaInformation(PomdpType const& pomdp, storm::logic::Formula const& formula) {
173 if (formula.isProbabilityOperatorFormula()) {
175 } else if (formula.isRewardOperatorFormula()) {
176 return getFormulaInformation(pomdp, formula.asRewardOperatorFormula());
177 }
178 return FormulaInformation();
179}
180
181template void FormulaInformation::updateTargetStates<storm::models::sparse::Pomdp<double>>(storm::models::sparse::Pomdp<double> const& pomdp,
182 storm::storage::BitVector&& newTargetStates);
183template void FormulaInformation::updateSinkStates<storm::models::sparse::Pomdp<double>>(storm::models::sparse::Pomdp<double> const& pomdp,
184 storm::storage::BitVector&& newSinkStates);
185template FormulaInformation getFormulaInformation<storm::models::sparse::Pomdp<double>>(storm::models::sparse::Pomdp<double> const& pomdp,
186 storm::logic::Formula const& formula);
187template void FormulaInformation::updateTargetStates<storm::models::sparse::Pomdp<storm::RationalNumber>>(
189template void FormulaInformation::updateSinkStates<storm::models::sparse::Pomdp<storm::RationalNumber>>(
191template FormulaInformation getFormulaInformation<storm::models::sparse::Pomdp<storm::RationalNumber>>(
193
194} // namespace analysis
195} // namespace pomdp
196} // namespace storm
Formula const & getRightSubformula() const
Formula const & getLeftSubformula() const
RewardOperatorFormula & asRewardOperatorFormula()
Definition Formula.cpp:461
UntilFormula & asUntilFormula()
Definition Formula.cpp:317
static std::shared_ptr< Formula const > getTrueFormula()
Definition Formula.cpp:205
virtual bool isProbabilityOperatorFormula() const
Definition Formula.cpp:172
ProbabilityOperatorFormula & asProbabilityOperatorFormula()
Definition Formula.cpp:453
virtual bool isRewardOperatorFormula() const
Definition Formula.cpp:176
EventuallyFormula & asEventuallyFormula()
Definition Formula.cpp:333
std::shared_ptr< Formula const > asSharedPointer()
Definition Formula.cpp:548
storm::solver::OptimizationDirection const & getOptimalityType() const
std::string const & getRewardModelName() const
Retrieves the name of the reward model this property refers to (if any).
bool hasRewardModelName() const
Retrieves whether the reward model refers to a specific reward model.
Formula const & getSubformula() const
Formula const & getSubformula() const
virtual std::unique_ptr< CheckResult > check(Environment const &env, CheckTask< storm::logic::Formula, SolutionType > const &checkTask)
Checks the provided formula.
This class represents a partially observable Markov decision process.
Definition Pomdp.h:15
void updateSinkStates(PomdpType const &pomdp, storm::storage::BitVector &&newSinkStates)
storm::solver::OptimizationDirection const & getOptimizationDirection() const
Type
Possible supported formula types.
void updateTargetStates(PomdpType const &pomdp, storm::storage::BitVector &&newTargetStates)
A bit vector that is internally represented as a vector of 64-bit values.
Definition BitVector.h:18
void complement()
Negates all bits in the bit vector.
bool empty() const
Retrieves whether no bits are set to true in this bit vector.
size_t size() const
Retrieves the number of bits this bit vector can store.
uint_fast64_t getNextUnsetIndex(uint_fast64_t startingIndex) const
Retrieves the index of the bit that is the next bit set to false in the bit vector.
#define STORM_LOG_ASSERT(cond, message)
Definition macros.h:11
#define STORM_LOG_WARN_COND(cond, message)
Definition macros.h:38
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:30
FragmentSpecification propositional()
storm::storage::BitVector getStates(storm::logic::Formula const &propositionalFormula, bool formulaInverted, PomdpType const &pomdp)
FormulaInformation::StateSet getStateSet(PomdpType const &pomdp, storm::storage::BitVector &&inputStates)
FormulaInformation getFormulaInformation(PomdpType const &pomdp, storm::logic::ProbabilityOperatorFormula const &formula)
bool constexpr maximize(OptimizationDirection d)
bool constexpr minimize(OptimizationDirection d)
LabParser.cpp.
Definition cli.cpp:18