17 changed files with 66 additions and 239 deletions
-
20src/solver/MathsatSmtSolver.cpp
-
8src/solver/MathsatSmtSolver.h
-
6src/solver/SmtSolver.cpp
-
8src/solver/SmtSolver.h
-
18src/solver/Z3SmtSolver.cpp
-
8src/solver/Z3SmtSolver.h
-
7src/storage/expressions/BaseExpression.cpp
-
1src/storage/expressions/Expression.h
-
1src/storage/expressions/ExpressionManager.h
-
127src/storage/expressions/IdentifierSubstitutionVisitor.cpp
-
49src/storage/expressions/IdentifierSubstitutionVisitor.h
-
4src/storage/expressions/LinearCoefficientVisitor.h
-
8src/storage/expressions/SimpleValuation.cpp
-
5src/storage/expressions/SimpleValuation.h
-
22src/storage/expressions/SubstitutionVisitor.cpp
-
10src/storage/expressions/SubstitutionVisitor.h
-
3src/storage/expressions/Valuation.h
@ -1,127 +0,0 @@ |
|||
#include <map>
|
|||
#include <unordered_map>
|
|||
#include <string>
|
|||
|
|||
#include "src/storage/expressions/IdentifierSubstitutionVisitor.h"
|
|||
#include "src/storage/expressions/Expressions.h"
|
|||
|
|||
namespace storm { |
|||
namespace expressions { |
|||
template<typename MapType> |
|||
IdentifierSubstitutionVisitor<MapType>::IdentifierSubstitutionVisitor(MapType const& identifierToIdentifierMap) : identifierToIdentifierMap(identifierToIdentifierMap) { |
|||
// Intentionally left empty.
|
|||
} |
|||
|
|||
template<typename MapType> |
|||
Expression IdentifierSubstitutionVisitor<MapType>::substitute(Expression const& expression) { |
|||
return Expression(boost::any_cast<std::shared_ptr<BaseExpression>>(expression.getBaseExpression().accept(*this))); |
|||
} |
|||
|
|||
template<typename MapType> |
|||
boost::any IdentifierSubstitutionVisitor<MapType>::visit(IfThenElseExpression const& expression) { |
|||
std::shared_ptr<BaseExpression const> conditionExpression = boost::any_cast<std::shared_ptr<BaseExpression>>(expression.getCondition()->accept(*this)); |
|||
std::shared_ptr<BaseExpression const> thenExpression = boost::any_cast<std::shared_ptr<BaseExpression>>(expression.getThenExpression()->accept(*this)); |
|||
std::shared_ptr<BaseExpression const> elseExpression = boost::any_cast<std::shared_ptr<BaseExpression>>(expression.getElseExpression()->accept(*this)); |
|||
|
|||
// If the arguments did not change, we simply push the expression itself.
|
|||
if (conditionExpression.get() == expression.getCondition().get() && thenExpression.get() == expression.getThenExpression().get() && elseExpression.get() == expression.getElseExpression().get()) { |
|||
return expression.getSharedPointer(); |
|||
} else { |
|||
return std::shared_ptr<BaseExpression>(new IfThenElseExpression(expression.getReturnType(), conditionExpression, thenExpression, elseExpression)); |
|||
} |
|||
} |
|||
|
|||
template<typename MapType> |
|||
boost::any IdentifierSubstitutionVisitor<MapType>::visit(BinaryBooleanFunctionExpression const& expression) { |
|||
std::shared_ptr<BaseExpression const> firstExpression = boost::any_cast<std::shared_ptr<BaseExpression>>(expression.getFirstOperand()->accept(*this)); |
|||
std::shared_ptr<BaseExpression const> secondExpression = boost::any_cast<std::shared_ptr<BaseExpression>>(expression.getSecondOperand()->accept(*this)); |
|||
|
|||
// If the arguments did not change, we simply push the expression itself.
|
|||
if (firstExpression.get() == expression.getFirstOperand().get() && secondExpression.get() == expression.getSecondOperand().get()) { |
|||
return expression.getSharedPointer(); |
|||
} else { |
|||
return std::shared_ptr<BaseExpression>(new BinaryBooleanFunctionExpression(expression.getReturnType(), firstExpression, secondExpression, expression.getOperatorType())); |
|||
} |
|||
} |
|||
|
|||
template<typename MapType> |
|||
boost::any IdentifierSubstitutionVisitor<MapType>::visit(BinaryNumericalFunctionExpression const& expression) { |
|||
std::shared_ptr<BaseExpression const> firstExpression = boost::any_cast<std::shared_ptr<BaseExpression>>(expression.getFirstOperand()->accept(*this)); |
|||
std::shared_ptr<BaseExpression const> secondExpression = boost::any_cast<std::shared_ptr<BaseExpression>>(expression.getSecondOperand()->accept(*this)); |
|||
|
|||
// If the arguments did not change, we simply push the expression itself.
|
|||
if (firstExpression.get() == expression.getFirstOperand().get() && secondExpression.get() == expression.getSecondOperand().get()) { |
|||
return expression.getSharedPointer(); |
|||
} else { |
|||
return std::shared_ptr<BaseExpression>(new BinaryNumericalFunctionExpression(expression.getReturnType(), firstExpression, secondExpression, expression.getOperatorType())); |
|||
} |
|||
} |
|||
|
|||
template<typename MapType> |
|||
boost::any IdentifierSubstitutionVisitor<MapType>::visit(BinaryRelationExpression const& expression) { |
|||
std::shared_ptr<BaseExpression const> firstExpression = boost::any_cast<std::shared_ptr<BaseExpression>>(expression.getFirstOperand()->accept(*this)); |
|||
std::shared_ptr<BaseExpression const> secondExpression = boost::any_cast<std::shared_ptr<BaseExpression>>(expression.getSecondOperand()->accept(*this)); |
|||
|
|||
// If the arguments did not change, we simply push the expression itself.
|
|||
if (firstExpression.get() == expression.getFirstOperand().get() && secondExpression.get() == expression.getSecondOperand().get()) { |
|||
return expression.getSharedPointer(); |
|||
} else { |
|||
return std::shared_ptr<BaseExpression>(new BinaryRelationExpression(expression.getReturnType(), firstExpression, secondExpression, expression.getRelationType())); |
|||
} |
|||
} |
|||
|
|||
template<typename MapType> |
|||
boost::any IdentifierSubstitutionVisitor<MapType>::visit(VariableExpression const& expression) { |
|||
// If the variable is in the key set of the substitution, we need to replace it.
|
|||
auto const& namePair = this->identifierToIdentifierMap.find(expression.getVariableName()); |
|||
if (namePair != this->identifierToIdentifierMap.end()) { |
|||
return std::shared_ptr<BaseExpression>(new VariableExpression(expression.getReturnType(), namePair->second)); |
|||
} else { |
|||
return expression.getSharedPointer(); |
|||
} |
|||
} |
|||
|
|||
template<typename MapType> |
|||
boost::any IdentifierSubstitutionVisitor<MapType>::visit(UnaryBooleanFunctionExpression const& expression) { |
|||
std::shared_ptr<BaseExpression const> operandExpression = boost::any_cast<std::shared_ptr<BaseExpression>>(expression.getOperand()->accept(*this)); |
|||
|
|||
// If the argument did not change, we simply push the expression itself.
|
|||
if (operandExpression.get() == expression.getOperand().get()) { |
|||
return expression.getSharedPointer(); |
|||
} else { |
|||
return std::shared_ptr<BaseExpression>(new UnaryBooleanFunctionExpression(expression.getReturnType(), operandExpression, expression.getOperatorType())); |
|||
} |
|||
} |
|||
|
|||
template<typename MapType> |
|||
boost::any IdentifierSubstitutionVisitor<MapType>::visit(UnaryNumericalFunctionExpression const& expression) { |
|||
std::shared_ptr<BaseExpression const> operandExpression = boost::any_cast<std::shared_ptr<BaseExpression>>(expression.getOperand()->accept(*this)); |
|||
|
|||
// If the argument did not change, we simply push the expression itself.
|
|||
if (operandExpression.get() == expression.getOperand().get()) { |
|||
return expression.getSharedPointer(); |
|||
} else { |
|||
return std::shared_ptr<BaseExpression>(new UnaryNumericalFunctionExpression(expression.getReturnType(), operandExpression, expression.getOperatorType())); |
|||
} |
|||
} |
|||
|
|||
template<typename MapType> |
|||
boost::any IdentifierSubstitutionVisitor<MapType>::visit(BooleanLiteralExpression const& expression) { |
|||
return expression.getSharedPointer(); |
|||
} |
|||
|
|||
template<typename MapType> |
|||
boost::any IdentifierSubstitutionVisitor<MapType>::visit(IntegerLiteralExpression const& expression) { |
|||
return expression.getSharedPointer(); |
|||
} |
|||
|
|||
template<typename MapType> |
|||
boost::any IdentifierSubstitutionVisitor<MapType>::visit(DoubleLiteralExpression const& expression) { |
|||
return expression.getSharedPointer(); |
|||
} |
|||
|
|||
// Explicitly instantiate the class with map and unordered_map.
|
|||
template class IdentifierSubstitutionVisitor< std::map<std::string, std::string> >; |
|||
template class IdentifierSubstitutionVisitor< std::unordered_map<std::string, std::string> >; |
|||
} |
|||
} |
@ -1,49 +0,0 @@ |
|||
#ifndef STORM_STORAGE_EXPRESSIONS_IDENTIFIERSUBSTITUTIONVISITOR_H_ |
|||
#define STORM_STORAGE_EXPRESSIONS_IDENTIFIERSUBSTITUTIONVISITOR_H_ |
|||
|
|||
#include <stack> |
|||
|
|||
#include "src/storage/expressions/Expression.h" |
|||
#include "src/storage/expressions/ExpressionVisitor.h" |
|||
|
|||
namespace storm { |
|||
namespace expressions { |
|||
template<typename MapType> |
|||
class IdentifierSubstitutionVisitor : public ExpressionVisitor { |
|||
public: |
|||
/*! |
|||
* Creates a new substitution visitor that uses the given map to replace identifiers. |
|||
* |
|||
* @param identifierToExpressionMap A mapping from identifiers to expressions. |
|||
*/ |
|||
IdentifierSubstitutionVisitor(MapType const& identifierToExpressionMap); |
|||
|
|||
/*! |
|||
* Substitutes the identifiers in the given expression according to the previously given map and returns the |
|||
* resulting expression. |
|||
* |
|||
* @param expression The expression in which to substitute the identifiers. |
|||
* @return The expression in which all identifiers in the key set of the previously given mapping are |
|||
* substituted with the mapped-to expressions. |
|||
*/ |
|||
Expression substitute(Expression const& expression); |
|||
|
|||
virtual boost::any visit(IfThenElseExpression const& expression) override; |
|||
virtual boost::any visit(BinaryBooleanFunctionExpression const& expression) override; |
|||
virtual boost::any visit(BinaryNumericalFunctionExpression const& expression) override; |
|||
virtual boost::any visit(BinaryRelationExpression const& expression) override; |
|||
virtual boost::any visit(VariableExpression const& expression) override; |
|||
virtual boost::any visit(UnaryBooleanFunctionExpression const& expression) override; |
|||
virtual boost::any visit(UnaryNumericalFunctionExpression const& expression) override; |
|||
virtual boost::any visit(BooleanLiteralExpression const& expression) override; |
|||
virtual boost::any visit(IntegerLiteralExpression const& expression) override; |
|||
virtual boost::any visit(DoubleLiteralExpression const& expression) override; |
|||
|
|||
private: |
|||
// A mapping of identifier names to expressions with which they shall be replaced. |
|||
MapType const& identifierToIdentifierMap; |
|||
}; |
|||
} |
|||
} |
|||
|
|||
#endif /* STORM_STORAGE_EXPRESSIONS_IDENTIFIERSUBSTITUTIONVISITOR_H_ */ |
Write
Preview
Loading…
Cancel
Save
Reference in new issue