Storm 1.13.0.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)
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
38 return operatorInformation.bound.get().threshold;
39}
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
69template<>
71 STORM_LOG_THROW(!operatorInformation.bound.get().threshold.containsVariables(), storm::exceptions::InvalidOperationException,
72 "Cannot evaluate threshold '" << operatorInformation.bound.get().threshold << "' as it contains undefined constants.");
73 return storm::utility::convertNumber<storm::RationalInterval>(operatorInformation.bound.get().threshold.evaluateAsRational());
74}
75
77 operatorInformation.bound.get().threshold = newThreshold;
78}
79
81 return operatorInformation.bound.get();
82}
83
84void OperatorFormula::setBound(Bound const& newBound) {
85 operatorInformation.bound = newBound;
86}
87
89 operatorInformation.bound = boost::none;
90}
91
93 return static_cast<bool>(operatorInformation.optimalityType);
94}
95
97 return operatorInformation.optimalityType.get();
98}
99
101 operatorInformation.optimalityType = newOptimalityType;
102}
103
105 operatorInformation.optimalityType = boost::none;
106}
107
109 return true;
110}
111
115
117 return this->hasBound();
118}
119
121 return !this->hasBound();
122}
123
124void OperatorFormula::gatherUsedVariables(std::set<storm::expressions::Variable>& usedVariables) const {
126 if (this->hasBound()) {
127 this->getThreshold().gatherVariables(usedVariables);
128 }
129}
130
131std::ostream& OperatorFormula::writeToStream(std::ostream& out, bool /* allowParentheses */) const {
132 // No parentheses necessary
133 if (hasOptimalityType()) {
134 out << (getOptimalityType() == OptimizationDirection::Minimize ? "min" : "max");
135 }
136 if (hasBound()) {
137 out << getBound();
138 } else {
139 out << "=?";
140 }
141 out << " [";
142 this->getSubformula().writeToStream(out);
143 out << "]";
144 return out;
145}
146} // namespace logic
147} // 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
UnaryStateFormula(std::shared_ptr< Formula const > subformula)
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
TargetType convertNumber(SourceType const &number)
carl::Interval< storm::RationalNumber > RationalInterval
carl::Interval< double > Interval
Interval type.
solver::OptimizationDirection OptimizationDirection
carl::RationalFunction< Polynomial, true > RationalFunction
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