Storm 1.11.1.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
Smt2ExpressionAdapter.h
Go to the documentation of this file.
1#pragma once
2
3#include <unordered_map>
4
5#include "storm-config.h"
14
15namespace storm {
16namespace adapters {
17
19 public:
26 Smt2ExpressionAdapter(storm::expressions::ExpressionManager&, bool useReadableVarNames) : useReadableVarNames(useReadableVarNames) {
27 declaredVariables.emplace_back(std::set<std::string>());
28 }
29
37 STORM_LOG_THROW(false, storm::exceptions::NotImplementedException, "functionality not (yet) implemented");
38 }
39
48 std::string translateExpression(storm::RationalFunction const& leftHandSide, storm::CompareRelation const& relation,
49 storm::RationalFunction const& rightHandSide) {
50 return "(" + carl::toString(relation) + " (/ " + leftHandSide.nominator().toString(false, useReadableVarNames) + " " +
51 leftHandSide.denominator().toString(false, useReadableVarNames) + ") (/ " + rightHandSide.nominator().toString(false, useReadableVarNames) +
52 " " + rightHandSide.denominator().toString(false, useReadableVarNames) + ") " + ")";
53 }
54
61 std::string translateExpression(storm::RationalFunction const& leftHandSide, storm::CompareRelation const& relation) {
62 std::stringstream ss;
63 ss << "(" << relation << " " << leftHandSide.toString(false, useReadableVarNames) << " " << "0 " << ")";
64 return ss.str();
65 }
66
74 STORM_LOG_THROW(false, storm::exceptions::NotImplementedException, "functionality not (yet) implemented");
75 }
76
83 storm::expressions::Variable const& getVariable(std::string const&) {
84 STORM_LOG_THROW(false, storm::exceptions::NotImplementedException, "functionality not (yet) implemented");
85 }
86
87 void increaseScope(uint_fast64_t n = 1) {
88 for (uint_fast64_t i = 0; i < n; ++i) {
89 declaredVariables.emplace_back(std::set<std::string>());
90 }
91 }
92
93 void decreaseScope(uint_fast64_t n = 1) {
94 STORM_LOG_THROW(declaredVariables.size() >= n, storm::exceptions::InvalidArgumentException, "Scope increased too much. Too many calls of pop()?");
95 for (uint_fast64_t i = 0; i < n; ++i) {
96 declaredVariables.pop_back();
97 }
98 }
99
103 std::vector<std::string> const checkForUndeclaredVariables(std::set<storm::RationalFunctionVariable> const& variables) {
104 std::vector<std::string> result;
105 carl::VariablePool& vPool = carl::VariablePool::getInstance();
106 for (storm::RationalFunctionVariable const& variableToCheck : variables) {
107 std::string const& variableString = vPool.getName(variableToCheck, useReadableVarNames);
108 // first check if this variable is already declared
109 bool alreadyDeclared = false;
110 for (std::set<std::string> const& variables : declaredVariables) {
111 if (variables.find(variableString) != variables.end()) {
112 alreadyDeclared = true;
113 break;
114 }
115 }
116 // secondly, declare the variable if necessary
117 if (!alreadyDeclared) {
118 STORM_LOG_DEBUG("Declaring the variable " + variableString);
119 declaredVariables.back().insert(variableString);
120 std::string varDeclaration = "( declare-fun " + variableString + " () ";
121 switch (variableToCheck.type()) {
122 case carl::VariableType::VT_BOOL:
123 varDeclaration += "Bool";
124 break;
125 case carl::VariableType::VT_REAL:
126 varDeclaration += "Real";
127 break;
128 case carl::VariableType::VT_INT:
129 varDeclaration += "Int";
130 break;
131 default:
132 STORM_LOG_THROW(false, storm::exceptions::InvalidTypeException, "The type of the variable is not supported");
133 }
134 varDeclaration += " )";
135 result.push_back(varDeclaration);
136 }
137 }
138 return result;
139 }
140
141 private:
142 // The manager that can be used to build expressions.
143 // storm::expressions::ExpressionManager& manager;
144 // A flag to decide whether readable var names should be used instead of intern representation
145 bool useReadableVarNames;
146 // the declared variables for the different scopes
147 std::vector<std::set<std::string>> declaredVariables;
148};
149} // namespace adapters
150} // namespace storm
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:18
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:30
carl::Relation CompareRelation
carl::Variable RationalFunctionVariable