Storm
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
60 operatorInformation.bound.get().threshold = newThreshold;
61}
62
64 return operatorInformation.bound.get();
65}
66
67void OperatorFormula::setBound(Bound const& newBound) {
68 operatorInformation.bound = newBound;
69}
70
74
76 return static_cast<bool>(operatorInformation.optimalityType);
77}
78
82
86
90
92 return true;
93}
94
98
100 return this->hasBound();
101}
102
104 return !this->hasBound();
105}
106
107void OperatorFormula::gatherUsedVariables(std::set<storm::expressions::Variable>& usedVariables) const {
109 if (this->hasBound()) {
110 this->getThreshold().gatherVariables(usedVariables);
111 }
112}
113
114std::ostream& OperatorFormula::writeToStream(std::ostream& out, bool /* allowParentheses */) const {
115 // No parentheses necessary
116 if (hasOptimalityType()) {
117 out << (getOptimalityType() == OptimizationDirection::Minimize ? "min" : "max");
118 }
119 if (hasBound()) {
120 out << getBound();
121 } else {
122 out << "=?";
123 }
124 out << " [";
125 this->getSubformula().writeToStream(out);
126 out << "]";
127 return out;
128}
129} // namespace logic
130} // 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.
Definition cli.cpp:18
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