Browse Source

Further work on expressions.

Former-commit-id: 4774f0136d
tempestpy_adaptions
dehnert 10 years ago
parent
commit
983a7d78c2
  1. 43
      src/adapters/MathsatExpressionAdapter.h
  2. 49
      src/adapters/Z3ExpressionAdapter.h
  3. 99
      src/solver/MathsatSmtSolver.cpp
  4. 4
      src/solver/MathsatSmtSolver.h
  5. 25
      src/solver/Z3SmtSolver.cpp
  6. 14
      src/storage/expressions/BaseExpression.cpp
  7. 32
      src/storage/expressions/BaseExpression.h
  8. 14
      src/storage/expressions/BinaryBooleanFunctionExpression.cpp
  9. 4
      src/storage/expressions/BinaryBooleanFunctionExpression.h
  10. 2
      src/storage/expressions/BinaryExpression.cpp
  11. 4
      src/storage/expressions/BinaryExpression.h
  12. 8
      src/storage/expressions/BinaryNumericalFunctionExpression.cpp
  13. 4
      src/storage/expressions/BinaryNumericalFunctionExpression.h
  14. 6
      src/storage/expressions/BinaryRelationExpression.cpp
  15. 4
      src/storage/expressions/BinaryRelationExpression.h
  16. 3
      src/storage/expressions/BooleanLiteralExpression.cpp
  17. 3
      src/storage/expressions/DoubleLiteralExpression.cpp
  18. 51
      src/storage/expressions/Expression.cpp
  19. 6
      src/storage/expressions/Expression.h
  20. 147
      src/storage/expressions/ExpressionManager.cpp
  21. 69
      src/storage/expressions/ExpressionManager.h
  22. 15
      src/storage/expressions/ExpressionReturnType.cpp
  23. 35
      src/storage/expressions/ExpressionReturnType.h
  24. 4
      src/storage/expressions/IfThenElseExpression.cpp
  25. 4
      src/storage/expressions/IfThenElseExpression.h
  26. 3
      src/storage/expressions/IntegerLiteralExpression.cpp
  27. 4
      src/storage/expressions/LinearCoefficientVisitor.h
  28. 78
      src/storage/expressions/SimpleValuation.cpp
  29. 83
      src/storage/expressions/SimpleValuation.h
  30. 156
      src/storage/expressions/Type.cpp
  31. 224
      src/storage/expressions/Type.h
  32. 10
      src/storage/expressions/UnaryBooleanFunctionExpression.cpp
  33. 4
      src/storage/expressions/UnaryBooleanFunctionExpression.h
  34. 2
      src/storage/expressions/UnaryExpression.cpp
  35. 4
      src/storage/expressions/UnaryExpression.h
  36. 8
      src/storage/expressions/UnaryNumericalFunctionExpression.cpp
  37. 4
      src/storage/expressions/UnaryNumericalFunctionExpression.h
  38. 72
      src/storage/expressions/Valuation.cpp
  39. 63
      src/storage/expressions/Valuation.h
  40. 10
      src/storage/expressions/Variable.cpp
  41. 4
      src/storage/expressions/Variable.h

43
src/adapters/MathsatExpressionAdapter.h

@ -17,10 +17,26 @@
#include "src/exceptions/InvalidArgumentException.h"
#include "src/exceptions/NotImplementedException.h"
namespace std {
// Define hashing operator for MathSAT's declarations.
template <>
struct std::hash<msat_decl> {
std::size_t operator()(msat_decl const& declaration) const {
return std::hash<void*>()(declaration.repr);
}
};
}
// Define equality operator to make hashing work.
bool operator==(msat_decl decl1, msat_decl decl2) {
return decl1.repr == decl2.repr;
}
namespace storm {
namespace adapters {
#ifdef STORM_HAVE_MSAT
class MathsatExpressionAdapter : public storm::expressions::ExpressionVisitor {
public:
/*!
@ -29,7 +45,7 @@ namespace storm {
* @param manager The manager that can be used to build expressions.
* @param env The MathSAT environment in which to build the expressions.
*/
MathsatExpressionAdapter(storm::expressions::ExpressionManager& manager, msat_env& env) : manager(manager), env(env), variableToDeclarationMap() {
MathsatExpressionAdapter(storm::expressions::ExpressionManager& manager, msat_env& env) : manager(manager), env(env), variableToDeclarationMapping() {
// Intentionally left empty.
}
@ -52,7 +68,19 @@ namespace storm {
* @return An equivalent term for MathSAT.
*/
msat_term translateExpression(storm::expressions::Variable const& variable) {
return msat_make_constant(env, variableToDeclarationMap[variable]);
return msat_make_constant(env, variableToDeclarationMapping[variable]);
}
/*!
* Retrieves the variable that is associated with the given MathSAT variable declaration.
*
* @param msatVariableDeclaration The MathSAT variable declaration.
* @return The variable associated with the given declaration.
*/
storm::expressions::Variable const& getVariable(msat_decl msatVariableDeclaration) const {
auto const& declarationVariablePair = declarationToVariableMapping.find(msatVariableDeclaration);
STORM_LOG_ASSERT(declarationVariablePair != declarationToVariableMapping.end(), "Unknown variable declaration.");
return declarationVariablePair->second;
}
virtual boost::any visit(expressions::BinaryBooleanFunctionExpression const& expression) override {
@ -101,13 +129,13 @@ namespace storm {
switch (expression.getRelationType()) {
case storm::expressions::BinaryRelationExpression::RelationType::Equal:
if (expression.getFirstOperand()->getReturnType() == storm::expressions::ExpressionReturnType::Bool && expression.getSecondOperand()->getReturnType() == storm::expressions::ExpressionReturnType::Bool) {
if (expression.getFirstOperand()->getType().isBooleanType() && expression.getSecondOperand()->getType().isBooleanType()) {
return msat_make_iff(env, leftResult, rightResult);
} else {
return msat_make_equal(env, leftResult, rightResult);
}
case storm::expressions::BinaryRelationExpression::RelationType::NotEqual:
if (expression.getFirstOperand()->getReturnType() == storm::expressions::ExpressionReturnType::Bool && expression.getSecondOperand()->getReturnType() == storm::expressions::ExpressionReturnType::Bool) {
if (expression.getFirstOperand()->getType().isBooleanType() && expression.getSecondOperand()->getType().isBooleanType()) {
return msat_make_not(env, msat_make_iff(env, leftResult, rightResult));
} else {
return msat_make_not(env, msat_make_equal(env, leftResult, rightResult));
@ -176,7 +204,7 @@ namespace storm {
}
virtual boost::any visit(expressions::VariableExpression const& expression) override {
return msat_make_constant(env, variableToDeclarationMap[expression.getVariable()]);
return msat_make_constant(env, variableToDeclarationMapping[expression.getVariable()]);
}
storm::expressions::Expression translateExpression(msat_term const& term) {
@ -229,7 +257,10 @@ namespace storm {
msat_env& env;
// A mapping of variable names to their declaration in the MathSAT environment.
std::unordered_map<storm::expressions::Variable, msat_decl> variableToDeclarationMap;
std::unordered_map<storm::expressions::Variable, msat_decl> variableToDeclarationMapping;
// A mapping from MathSAT variable declaration to our variables.
std::unordered_map<msat_decl, storm::expressions::Variable> declarationToVariableMapping;
};
#endif
} // namespace adapters

49
src/adapters/Z3ExpressionAdapter.h

@ -30,15 +30,23 @@ namespace storm {
* @param context A reference to the Z3 context over which to build the expressions. The lifetime of the
* context needs to be guaranteed as long as the instance of this adapter is used.
*/
Z3ExpressionAdapter(storm::expressions::ExpressionManager& manager, z3::context& context) : manager(manager), context(context), additionalAssertions(), variableToExpressionMap() {
Z3ExpressionAdapter(storm::expressions::ExpressionManager& manager, z3::context& context) : manager(manager), context(context), additionalAssertions(), variableToExpressionMapping() {
// Here, we need to create the mapping from all variables known to the manager to their z3 counterparts.
for (auto const& variableTypePair : manager) {
switch (variableTypePair.second) {
case storm::expressions::ExpressionReturnType::Bool: variableToExpressionMap.insert(std::make_pair(variableTypePair.first, context.bool_const(variableTypePair.first.getName().c_str()))); break;
case storm::expressions::ExpressionReturnType::Int: variableToExpressionMap.insert(std