Storm 1.10.0.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
OperatorFormula.cpp
Go to the documentation of this file.
2#include <ostream>
4#include "storm/logic/Bound.h"
5
7
8namespace storm {
9namespace logic {
10OperatorInformation::OperatorInformation(boost::optional<storm::solver::OptimizationDirection> const& optimizationDirection,
11 boost::optional<Bound> const& bound)
12 : optimalityType(optimizationDirection), bound(bound) {
13 // Intentionally left empty.
14}
15
16OperatorFormula::OperatorFormula(std::shared_ptr<Formula const> const& subformula, OperatorInformation const& operatorInformation)
17 : UnaryStateFormula(subformula), operatorInformation(operatorInformation) {
18 // Intentionally left empty.
19}
20
22 return static_cast<bool>(operatorInformation.bound);
23}
24
26 STORM_LOG_ASSERT(operatorInformation.bound.is_initialized(), "Cannot get Formula comparison type (has no bound?)");
27 return operatorInformation.bound.get().comparisonType;
28}
29
31 operatorInformation.bound.get().comparisonType = newComparisonType;
32}
33
37
38template<>
40 STORM_LOG_THROW(!operatorInformation.bound.get().threshold.containsVariables(), storm::exceptions::InvalidOperationException,
41 "Cannot evaluate threshold '" << operatorInformation.bound.get().threshold << "' as it contains undefined constants.");
42 return operatorInformation.bound.get().threshold.evaluateAsDouble();
43}
44
45template<>
46storm::RationalNumber OperatorFormula::getThresholdAs() const {
47 STORM_LOG_THROW(!operatorInformation.bound.get().threshold.containsVariables(), storm::exceptions::InvalidOperationException,
48 "Cannot evaluate threshold '" << operatorInformation.bound.get().threshold << "' as it contains undefined constants.");
49 return operatorInformation.bound.get().threshold.evaluateAsRational();
50}
51
52template<>
54 STORM_LOG_THROW(!operatorInformation.bound.get().threshold.containsVariables(), storm::exceptions::InvalidOperationException,
55 "Cannot evaluate threshold '" << operatorInformation.bound.get().threshold << "' as it contains undefined constants.");
56 return storm::utility::convertNumber<storm::RationalFunction>(operatorInformation.bound.get().threshold.evaluateAsRational());
57}
58
59template<>
61 STORM_LOG_THROW(!operatorInformation.bound.get().threshold.containsVariables(), storm::exceptions::InvalidOperationException,
62 "Cannot evaluate threshold '" << operatorInformation.bound.get().threshold << "' as it contains undefined constants.");
63 return storm::utility::convertNumber<storm::Interval>(operatorInformation.bound.get().threshold.evaluateAsRational());
64}
65
67 operatorInformation.bound.get().threshold = newThreshold;
68}
69
71 return operatorInformation.bound.get();
72}
73
74void OperatorFormula::setBound(Bound const& newBound) {
75 operatorInformation.bound = newBound;
76}
77
81
83 return static_cast<bool>(operatorInformation.optimalityType);
84}
85
89
93
97
99 return true;
100}
101
105
107 return this->hasBound();
108}
109
111 return !this->hasBound();
112}
113
114void OperatorFormula::gatherUsedVariables(std::set<storm::expressions::Variable>& usedVariables) const {
116 if (this->hasBound()) {
117 this->getThreshold().gatherVariables(usedVariables);
118 }
119}
120
121std::ostream& OperatorFormula::writeToStream(std::ostream& out, bool /* allowParentheses */) const {
122 // No parentheses necessary
123 if (hasOptimalityType()) {
124 out << (getOptimalityType() == OptimizationDirection::Minimize ? "min" : "max");
125 }
126 if (hasBound()) {
127 out << getBound();
128 } else {
129 out << "=?";
130 }
131 out << " [";
132 this->getSubformula().writeToStream(out);
133 out << "]";
134 return out;
135}
136} // namespace logic
137} // 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
LabParser.cpp.
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