Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
Smt2ExpressionAdapter.h
Go to the documentation of this file.
1#ifndef STORM_ADAPTERS_SMT2EXPRESSIONADAPTER_H_
2#define STORM_ADAPTERS_SMT2EXPRESSIONADAPTER_H_
3
4#include <unordered_map>
5
6#include "storm-config.h"
15
16namespace storm {
17namespace adapters {
18
20 public:
27 Smt2ExpressionAdapter(storm::expressions::ExpressionManager&, bool useReadableVarNames) : useReadableVarNames(useReadableVarNames) {
28 declaredVariables.emplace_back(std::set<std::string>());
29 }
30
38 STORM_LOG_THROW(false, storm::exceptions::NotImplementedException, "functionality not (yet) implemented");
39 }
40
49 std::string translateExpression(storm::RationalFunction const& leftHandSide, storm::CompareRelation const& relation,
50 storm::RationalFunction const& rightHandSide) {
51 return "(" + carl::toString(relation) + " (/ " + leftHandSide.nominator().toString(false, useReadableVarNames) + " " +
52 leftHandSide.denominator().toString(false, useReadableVarNames) + ") (/ " + rightHandSide.nominator().toString(false, useReadableVarNames) +
53 " " + rightHandSide.denominator().toString(false, useReadableVarNames) + ") " + ")";
54 }
55
62 std::string translateExpression(storm::RationalFunction const& leftHandSide, storm::CompareRelation const& relation) {
63 std::stringstream ss;
64 ss << "(" << relation << " " << leftHandSide.toString(false, useReadableVarNames) << " " << "0 " << ")";
65 return ss.str();
66 }
67
75 STORM_LOG_THROW(false, storm::exceptions::NotImplementedException, "functionality not (yet) implemented");
76 }
77
84 storm::expressions::Variable const& getVariable(std::string const&) {
85 STORM_LOG_THROW(false, storm::exceptions::NotImplementedException, "functionality not (yet) implemented");
86 }
87
88 void increaseScope(uint_fast64_t n = 1) {
89 for (uint_fast64_t i = 0; i < n; ++i) {
90 declaredVariables.emplace_back(std::set<std::string>());
91 }
92 }
93
94 void decreaseScope(uint_fast64_t n = 1) {
95 STORM_LOG_THROW(declaredVariables.size() >= n, storm::exceptions::InvalidArgumentException, "Scope increased too much. Too many calls of pop()?");
96 for (uint_fast64_t i = 0; i < n; ++i) {
97 declaredVariables.pop_back();
98 }
99 }
100
104 std::vector<std::string> const checkForUndeclaredVariables(std::set<storm::RationalFunctionVariable> const& variables) {
105 std::vector<std::string> result;
106 carl::VariablePool& vPool = carl::VariablePool::getInstance();
107 for (storm::RationalFunctionVariable const& variableToCheck : variables) {
108 std::string const& variableString = vPool.getName(variableToCheck, useReadableVarNames);
109 // first check if this variable is already declared
110 bool alreadyDeclared = false;
111 for (std::set<std::string> const& variables : declaredVariables) {
112 if (variables.find(variableString) != variables.end()) {
113 alreadyDeclared = true;
114 break;
115 }
116 }
117 // secondly, declare the variable if necessary
118 if (!alreadyDeclared) {
119 STORM_LOG_DEBUG("Declaring the variable " + variableString);
120 declaredVariables.back().insert(variableString);
121 std::string varDeclaration = "( declare-fun " + variableString + " () ";
122 switch (variableToCheck.type()) {
123 case carl::VariableType::VT_BOOL:
124 varDeclaration += "Bool";
125 break;
126 case carl::VariableType::VT_REAL:
127 varDeclaration += "Real";
128 break;
129 case carl::VariableType::VT_INT:
130 varDeclaration += "Int";
131 break;
132 default:
133 STORM_LOG_THROW(false, storm::exceptions::InvalidTypeException, "The type of the variable is not supported");
134 }
135 varDeclaration += " )";
136 result.push_back(varDeclaration);
137 }
138 }
139 return result;
140 }
141
142 private:
143 // The manager that can be used to build expressions.
144 // storm::expressions::ExpressionManager& manager;
145 // A flag to decide whether readable var names should be used instead of intern representation
146 bool useReadableVarNames;
147 // the declared variables for the different scopes
148 std::vector<std::set<std::string>> declaredVariables;
149};
150} // namespace adapters
151} // namespace storm
152
153#endif /* STORM_ADAPTERS_SMT2EXPRESSIONADAPTER_H_ */
std::string translateExpression(storm::expressions::Expression const &)
Translates the given expression to an equivalent expression for Smt2.
std::vector< std::string > const checkForUndeclaredVariables(std::set< storm::RationalFunctionVariable > const &variables)
Checks whether the variables in the given set are already declared and creates them if necessary.
std::string translateExpression(storm::expressions::Variable const &)
Translates the given variable to an equivalent expression for Smt2.
std::string translateExpression(storm::RationalFunction const &leftHandSide, storm::CompareRelation const &relation)
Translates the given constraint "leftHandSide relation 0" to an equivalent expression for Smt2.
std::string translateExpression(storm::RationalFunction const &leftHandSide, storm::CompareRelation const &relation, storm::RationalFunction const &rightHandSide)
Translates the given constraint "leftHandSide relation rightHandSide" to an equivalent expression for...
Smt2ExpressionAdapter(storm::expressions::ExpressionManager &, bool useReadableVarNames)
Creates an expression adapter that can translate expressions to the format of Smt2.
storm::expressions::Variable const & getVariable(std::string const &)
Finds the counterpart to the given smt2 variable declaration.
This class is responsible for managing a set of typed variables and all expressions using these varia...
#define STORM_LOG_DEBUG(message)
Definition logging.h:23
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:30
LabParser.cpp.
Definition cli.cpp:18
carl::Relation CompareRelation
carl::Variable RationalFunctionVariable