Storm 1.11.1.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
OperatorFormula.cpp
Go to the documentation of this file.
2
3#include <ostream>
4
9#include "storm/logic/Bound.h"
10
11namespace storm {
12namespace logic {
13OperatorInformation::OperatorInformation(boost::optional<storm::solver::OptimizationDirection> const& optimizationDirection,
14 boost::optional<Bound> const& bound)
15 : optimalityType(optimizationDirection), bound(bound) {
16 // Intentionally left empty.
17}
18
19OperatorFormula::OperatorFormula(std::shared_ptr<Formula const> const& subformula, OperatorInformation const& operatorInformation)
20 : UnaryStateFormula(subformula), operatorInformation(operatorInformation) {
21 // Intentionally left empty.
22}
23
25 return static_cast<bool>(operatorInformation.bound);
26}
27
29 STORM_LOG_ASSERT(operatorInformation.bound.is_initialized(), "Cannot get Formula comparison type (has no bound?)");
30 return operatorInformation.bound.get().comparisonType;
31}
32
34 operatorInformation.bound.get().comparisonType = newComparisonType;
35}
36
40
41template<>
43 STORM_LOG_THROW(!operatorInformation.bound.get().threshold.containsVariables(), storm::exceptions::InvalidOperationException,
44 "Cannot evaluate threshold '" << operatorInformation.bound.get().threshold << "' as it contains undefined constants.");
45 return operatorInformation.bound.get().threshold.evaluateAsDouble();
46}
47
48template<>
49storm::RationalNumber OperatorFormula::getThresholdAs() const {
50 STORM_LOG_THROW(!operatorInformation.bound.get().threshold.containsVariables(), storm::exceptions::InvalidOperationException,
51 "Cannot evaluate threshold '" << operatorInformation.bound.get().threshold << "' as it contains undefined constants.");
52 return operatorInformation.bound.get().threshold.evaluateAsRational();
53}
54
55template<>
57 STORM_LOG_THROW(!operatorInformation.bound.get().threshold.containsVariables(), storm::exceptions::InvalidOperationException,
58 "Cannot evaluate threshold '" << operatorInformation.bound.get().threshold << "' as it contains undefined constants.");
59 return storm::utility::convertNumber<storm::RationalFunction>(operatorInformation.bound.get().threshold.evaluateAsRational());
60}
61
62template<>
64 STORM_LOG_THROW(!operatorInformation.bound.get().threshold.containsVariables(), storm::exceptions::InvalidOperationException,
65 "Cannot evaluate threshold '" << operatorInformation.bound.get().threshold << "' as it contains undefined constants.");
66 return storm::utility::convertNumber<storm::Interval>(operatorInformation.bound.get().threshold.evaluateAsRational());
67}
68
70 operatorInformation.bound.get().threshold = newThreshold;
71}
72
74 return operatorInformation.bound.get();
75}
76
77void OperatorFormula::setBound(Bound const& newBound) {
78 operatorInformation.bound = newBound;
79}
80
84
86 return static_cast<bool>(operatorInformation.optimalityType);
87}
88
92
96
100
102 return true;
103}
104
108
110 return this->hasBound();
111}
112
114 return !this->hasBound();
115}
116
117void OperatorFormula::gatherUsedVariables(std::set<storm::expressions::Variable>& usedVariables) const {
119 if (this->hasBound()) {
120 this->getThreshold().gatherVariables(usedVariables);
121 }
122}
123
124std::ostream& OperatorFormula::writeToStream(std::ostream& out, bool /* allowParentheses */) const {
125 // No parentheses necessary
126 if (hasOptimalityType()) {
127 out << (getOptimalityType() == OptimizationDirection::Minimize ? "min" : "max");
128 }
129 if (hasBound()) {
130 out << getBound();
131 } else {
132 out << "=?";
133 }
134 out << " [";
135 this->getSubformula().writeToStream(out);
136 out << "]";
137 return out;
138}
139} // namespace logic
140} // namespace storm
void gatherVariables(std::set< storm::expressions::Variable > &variables) const
Retrieves the set of all variables that appear in the expression.
virtual std::ostream & writeToStream(std::ostream &out, bool allowParentheses=false) const =0
Writes the forumla to the given output stream.
void setComparisonType(ComparisonType newComparisonType)
Bound const & getBound() const
ComparisonType getComparisonType() const
OperatorInformation operatorInformation
virtual void gatherUsedVariables(std::set< storm::expressions::Variable > &usedVariables) const override
OperatorFormula(std::shared_ptr< Formula const > const &subformula, OperatorInformation const &operatorInformation=OperatorInformation())
storm::expressions::Expression const & getThreshold() const
OperatorInformation const & getOperatorInformation() const
virtual bool hasQualitativeResult() const override
virtual bool isOperatorFormula() const override
void setOptimalityType(storm::solver::OptimizationDirection newOptimalityType)
virtual std::ostream & writeToStream(std::ostream &out, bool allowParentheses=false) const override
Writes the forumla to the given output stream.
void setBound(Bound const &newBound)
storm::solver::OptimizationDirection const & getOptimalityType() const
void setThreshold(storm::expressions::Expression const &newThreshold)
virtual bool hasQuantitativeResult() const override
ValueType getThresholdAs() const
Formula const & getSubformula() const
virtual void gatherUsedVariables(std::set< storm::expressions::Variable > &usedVariables) const override
#define STORM_LOG_ASSERT(cond, message)
Definition macros.h:11
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:30
boost::optional< Bound > bound
OperatorInformation(boost::optional< storm::solver::OptimizationDirection > const &optimizationDirection=boost::none, boost::optional< Bound > const &bound=boost::none)
boost::optional< storm::solver::OptimizationDirection > optimalityType