Browse Source

Partly adapted code to new 'type system'.

Former-commit-id: 6c200df5f0
main
dehnert 10 years ago
parent
commit
398f6c4e86
  1. 20
      src/solver/MathsatSmtSolver.cpp
  2. 8
      src/solver/MathsatSmtSolver.h
  3. 6
      src/solver/SmtSolver.cpp
  4. 8
      src/solver/SmtSolver.h
  5. 18
      src/solver/Z3SmtSolver.cpp
  6. 8
      src/solver/Z3SmtSolver.h
  7. 7
      src/storage/expressions/BaseExpression.cpp
  8. 1
      src/storage/expressions/Expression.h
  9. 1
      src/storage/expressions/ExpressionManager.h
  10. 127
      src/storage/expressions/IdentifierSubstitutionVisitor.cpp
  11. 49
      src/storage/expressions/IdentifierSubstitutionVisitor.h
  12. 4
      src/storage/expressions/LinearCoefficientVisitor.h
  13. 8
      src/storage/expressions/SimpleValuation.cpp
  14. 5
      src/storage/expressions/SimpleValuation.h
  15. 22
      src/storage/expressions/SubstitutionVisitor.cpp
  16. 10
      src/storage/expressions/SubstitutionVisitor.h
  17. 3
      src/storage/expressions/Valuation.h

20
src/solver/MathsatSmtSolver.cpp

@ -219,7 +219,7 @@ namespace storm {
#endif
}
storm::expressions::Valuation MathsatSmtSolver::getModelAsValuation()
storm::expressions::SimpleValuation MathsatSmtSolver::getModelAsValuation()
{
#ifdef STORM_HAVE_MSAT
STORM_LOG_THROW(this->lastResult == SmtSolver::CheckResult::Sat, storm::exceptions::InvalidStateException, "Unable to create model for formula that was not determined to be satisfiable.");
@ -239,8 +239,8 @@ namespace storm {
}
#ifdef STORM_HAVE_MSAT
storm::expressions::Valuation MathsatSmtSolver::convertMathsatModelToValuation() {
storm::expressions::Valuation stormModel(this->getManager());
storm::expressions::SimpleValuation MathsatSmtSolver::convertMathsatModelToValuation() {
storm::expressions::SimpleValuation stormModel(this->getManager());
msat_model_iterator modelIterator = msat_create_model_iterator(env);
STORM_LOG_THROW(!MSAT_ERROR_MODEL_ITERATOR(modelIterator), storm::exceptions::UnexpectedException, "MathSat returned an illegal model iterator.");
@ -267,11 +267,11 @@ namespace storm {
}
#endif
std::vector<storm::expressions::Valuation> MathsatSmtSolver::allSat(std::vector<storm::expressions::Variable> const& important)
std::vector<storm::expressions::SimpleValuation> MathsatSmtSolver::allSat(std::vector<storm::expressions::Variable> const& important)
{
#ifdef STORM_HAVE_MSAT
std::vector<storm::expressions::Valuation> valuations;
this->allSat(important, [&valuations](storm::expressions::Valuation const& valuation) -> bool { valuations.push_back(valuation); return true; });
std::vector<storm::expressions::SimpleValuation> valuations;
this->allSat(important, [&valuations](storm::expressions::SimpleValuation const& valuation) -> bool { valuations.push_back(valuation); return true; });
return valuations;
#else
STORM_LOG_THROW(false, storm::exceptions::NotSupportedException, "StoRM is compiled without MathSAT support.");
@ -282,14 +282,14 @@ namespace storm {
#ifdef STORM_HAVE_MSAT
class AllsatValuationCallbackUserData {
public:
AllsatValuationCallbackUserData(storm::expressions::ExpressionManager const& manager, storm::adapters::MathsatExpressionAdapter& adapter, msat_env& env, std::function<bool(storm::expressions::Valuation&)> const& callback) : manager(manager), adapter(adapter), env(env), callback(callback) {
AllsatValuationCallbackUserData(storm::expressions::ExpressionManager const& manager, storm::adapters::MathsatExpressionAdapter& adapter, msat_env& env, std::function<bool(storm::expressions::SimpleValuation&)> const& callback) : manager(manager), adapter(adapter), env(env), callback(callback) {
// Intentionally left empty.
}
static int allsatValuationsCallback(msat_term* model, int size, void* user_data) {
AllsatValuationCallbackUserData* user = reinterpret_cast<AllsatValuationCallbackUserData*>(user_data);
storm::expressions::Valuation valuation(user->manager);
storm::expressions::SimpleValuation valuation(user->manager);
for (int i = 0; i < size; ++i) {
bool currentTermValue = true;
msat_term currentTerm = model[i];
@ -319,7 +319,7 @@ namespace storm {
msat_env& env;
// The function that is to be called when the MathSAT model has been translated to a valuation.
std::function<bool(storm::expressions::Valuation&)> const& callback;
std::function<bool(storm::expressions::SimpleValuation&)> const& callback;
};
class AllsatModelReferenceCallbackUserData {
@ -354,7 +354,7 @@ namespace storm {
#endif
uint_fast64_t MathsatSmtSolver::allSat(std::vector<storm::expressions::Variable> const& important, std::function<bool(storm::expressions::Valuation&)> const& callback) {
uint_fast64_t MathsatSmtSolver::allSat(std::vector<storm::expressions::Variable> const& important, std::function<bool(storm::expressions::SimpleValuation&)> const& callback) {
#ifdef STORM_HAVE_MSAT
// Create a backtracking point, because MathSAT will modify the assertions stack during its AllSat procedure.
this->push();

8
src/solver/MathsatSmtSolver.h

@ -81,13 +81,13 @@ namespace storm {
virtual CheckResult checkWithAssumptions(std::initializer_list<storm::expressions::Expression> const& assumptions) override;
virtual storm::expressions::Valuation getModelAsValuation() override;
virtual storm::expressions::SimpleValuation getModelAsValuation() override;
virtual std::shared_ptr<SmtSolver::ModelReference> getModel() override;
virtual std::vector<storm::expressions::Valuation> allSat(std::vector<storm::expressions::Variable> const& important) override;
virtual std::vector<storm::expressions::SimpleValuation> allSat(std::vector<storm::expressions::Variable> const& important) override;
virtual uint_fast64_t allSat(std::vector<storm::expressions::Variable> const& important, std::function<bool(storm::expressions::Valuation&)> const& callback) override;
virtual uint_fast64_t allSat(std::vector<storm::expressions::Variable> const& important, std::function<bool(storm::expressions::SimpleValuation&)> const& callback) override;
virtual uint_fast64_t allSat(std::vector<storm::expressions::Variable> const& important, std::function<bool(ModelReference&)> const& callback) override;
@ -98,7 +98,7 @@ namespace storm {
virtual storm::expressions::Expression getInterpolant(std::vector<uint_fast64_t> const& groupsA) override;
private:
storm::expressions::Valuation convertMathsatModelToValuation();
storm::expressions::SimpleValuation convertMathsatModelToValuation();
#ifdef STORM_HAVE_MSAT
// The MathSAT environment.

6
src/solver/SmtSolver.cpp

@ -40,7 +40,7 @@ namespace storm {
}
}
storm::expressions::Valuation SmtSolver::getModelAsValuation() {
storm::expressions::SimpleValuation SmtSolver::getModelAsValuation() {
STORM_LOG_THROW(false, storm::exceptions::NotSupportedException, "This solver does not support model generation.");
}
@ -48,11 +48,11 @@ namespace storm {
STORM_LOG_THROW(false, storm::exceptions::NotSupportedException, "This solver does not support model generation.");
}
std::vector<storm::expressions::Valuation> SmtSolver::allSat(std::vector<storm::expressions::Variable> const& important) {
std::vector<storm::expressions::SimpleValuation> SmtSolver::allSat(std::vector<storm::expressions::Variable> const& important) {
STORM_LOG_THROW(false, storm::exceptions::NotSupportedException, "This solver does not support model generation.");
}
uint_fast64_t SmtSolver::allSat(std::vector<storm::expressions::Variable> const& important, std::function<bool(storm::expressions::Valuation&)> const& callback) {
uint_fast64_t SmtSolver::allSat(std::vector<storm::expressions::Variable> const& important, std::function<bool(storm::expressions::SimpleValuation&)> const& callback) {
STORM_LOG_THROW(false, storm::exceptions::NotSupportedException, "This solver does not support model generation.");
}

8
src/solver/SmtSolver.h

@ -4,7 +4,7 @@
#include <cstdint>
#include "src/storage/expressions/Expressions.h"
#include "src/storage/expressions/Valuation.h"
#include "src/storage/expressions/SimpleValuation.h"
#include "src/storage/expressions/ExpressionManager.h"
#include <set>
@ -158,7 +158,7 @@ namespace storm {
*
* @return A valuation that holds the values of the variables in the current model.
*/
virtual storm::expressions::Valuation getModelAsValuation();
virtual storm::expressions::SimpleValuation getModelAsValuation();
/*!
* If the last call to check() or checkWithAssumptions() returned Sat, this method retrieves a model that
@ -181,7 +181,7 @@ namespace storm {
*
* @returns the set of all valuations of the important atoms, such that the currently asserted formulas are satisfiable
*/
virtual std::vector<storm::expressions::Valuation> allSat(std::vector<storm::expressions::Variable> const& important);
virtual std::vector<storm::expressions::SimpleValuation> allSat(std::vector<storm::expressions::Variable> const& important);
/*!
* Performs AllSat over the (provided) important atoms. That is, this function determines all models of the
@ -194,7 +194,7 @@ namespace storm {
*
* @return The number of models of the important atoms that where found.
*/
virtual uint_fast64_t allSat(std::vector<storm::expressions::Variable> const& important, std::function<bool(storm::expressions::Valuation&)> const& callback);
virtual uint_fast64_t allSat(std::vector<storm::expressions::Variable> const& important, std::function<bool(storm::expressions::SimpleValuation&)> const& callback);
/*!
* Performs AllSat over the (provided) important atoms. That is, this function determines all models of the

18
src/solver/Z3SmtSolver.cpp

@ -180,7 +180,7 @@ namespace storm {
#endif
}
storm::expressions::Valuation Z3SmtSolver::getModelAsValuation()
storm::expressions::SimpleValuation Z3SmtSolver::getModelAsValuation()
{
#ifdef STORM_HAVE_Z3
STORM_LOG_THROW(this->lastResult == SmtSolver::CheckResult::Sat, storm::exceptions::InvalidStateException, "Unable to create model for formula that was not determined to be satisfiable.");
@ -200,8 +200,8 @@ namespace storm {
}
#ifdef STORM_HAVE_Z3
storm::expressions::Valuation Z3SmtSolver::convertZ3ModelToValuation(z3::model const& model) {
storm::expressions::Valuation stormModel(this->getManager());
storm::expressions::SimpleValuation Z3SmtSolver::convertZ3ModelToValuation(z3::model const& model) {
storm::expressions::SimpleValuation stormModel(this->getManager());
for (unsigned i = 0; i < model.num_consts(); ++i) {
z3::func_decl variableI = model.get_const_decl(i);
@ -223,18 +223,18 @@ namespace storm {
}
#endif
std::vector<storm::expressions::Valuation> Z3SmtSolver::allSat(std::vector<storm::expressions::Variable> const& important)
std::vector<storm::expressions::SimpleValuation> Z3SmtSolver::allSat(std::vector<storm::expressions::Variable> const& important)
{
#ifdef STORM_HAVE_Z3
std::vector<storm::expressions::Valuation> valuations;
this->allSat(important, [&valuations](storm::expressions::Valuation const& valuation) -> bool { valuations.push_back(valuation); return true; });
std::vector<storm::expressions::SimpleValuation> valuations;
this->allSat(important, [&valuations](storm::expressions::SimpleValuation const& valuation) -> bool { valuations.push_back(valuation); return true; });
return valuations;
#else
STORM_LOG_THROW(false, storm::exceptions::NotSupportedException, "StoRM is compiled without Z3 support.");
#endif
}
uint_fast64_t Z3SmtSolver::allSat(std::vector<storm::expressions::Variable> const& important, std::function<bool(storm::expressions::Valuation&)> const& callback) {
uint_fast64_t Z3SmtSolver::allSat(std::vector<storm::expressions::Variable> const& important, std::function<bool(storm::expressions::SimpleValuation&)> const& callback) {
#ifdef STORM_HAVE_Z3
for (storm::expressions::Variable const& variable : important) {
STORM_LOG_THROW(variable.hasBooleanType(), storm::exceptions::InvalidArgumentException, "The important atoms for AllSat must be boolean variables.");
@ -252,7 +252,7 @@ namespace storm {
z3::model model = this->solver->get_model();
z3::expr modelExpr = this->context->bool_val(true);
storm::expressions::Valuation valuation(this->getManager());
storm::expressions::SimpleValuation valuation(this->getManager());
for (storm::expressions::Variable const& importantAtom : important) {
z3::expr z3ImportantAtom = this->expressionAdapter->translateExpression(importantAtom.getExpression());
@ -294,7 +294,7 @@ namespace storm {
z3::model model = this->solver->get_model();
z3::expr modelExpr = this->context->bool_val(true);
storm::expressions::Valuation valuation(this->getManager());
storm::expressions::SimpleValuation valuation(this->getManager());
for (storm::expressions::Variable const& importantAtom : important) {
z3::expr z3ImportantAtom = this->expressionAdapter->translateExpression(importantAtom.getExpression());

8
src/solver/Z3SmtSolver.h

@ -53,13 +53,13 @@ namespace storm {
virtual CheckResult checkWithAssumptions(std::initializer_list<storm::expressions::Expression> const& assumptions) override;
virtual storm::expressions::Valuation getModelAsValuation() override;
virtual storm::expressions::SimpleValuation getModelAsValuation() override;
virtual std::shared_ptr<SmtSolver::ModelReference> getModel() override;
virtual std::vector<storm::expressions::Valuation> allSat(std::vector<storm::expressions::Variable> const& important) override;
virtual std::vector<storm::expressions::SimpleValuation> allSat(std::vector<storm::expressions::Variable> const& important) override;
virtual uint_fast64_t allSat(std::vector<storm::expressions::Variable> const& important, std::function<bool(storm::expressions::Valuation&)> const& callback) override;
virtual uint_fast64_t allSat(std::vector<storm::expressions::Variable> const& important, std::function<bool(storm::expressions::SimpleValuation&)> const& callback) override;
virtual uint_fast64_t allSat(std::vector<storm::expressions::Variable> const& important, std::function<bool(ModelReference&)> const& callback) override;
@ -73,7 +73,7 @@ namespace storm {
* @param model The Z3 model to convert.
* @return The valuation of variables corresponding to the given model.
*/
storm::expressions::Valuation convertZ3ModelToValuation(z3::model const& model);
storm::expressions::SimpleValuation convertZ3ModelToValuation(z3::model const& model);
// The context used by the solver.
std::unique_ptr<z3::context> context;

7
src/storage/expressions/BaseExpression.cpp

@ -1,4 +1,5 @@
#include "src/storage/expressions/BaseExpression.h"
#include "src/storage/expressions/ExpressionManager.h"
#include "src/utility/macros.h"
#include "src/exceptions/InvalidTypeException.h"
#include "src/exceptions/InvalidAccessException.h"
@ -14,15 +15,15 @@ namespace storm {
}
bool BaseExpression::hasIntegralType() const {
return this->getType() == manager.getIntegerType();
return this->getType().isIntegralType();
}
bool BaseExpression::hasNumericalType() const {
return this->getReturnType() == ExpressionReturnType::Double || this->getReturnType() == ExpressionReturnType::Int;
return this->getType().isNumericalType();
}
bool BaseExpression::hasBooleanType() const {
return this->getReturnType() == ExpressionReturnType::Bool;
return this->getType().isBooleanType();
}
int_fast64_t BaseExpression::evaluateAsInt(Valuation const* valuation) const {

1
src/storage/expressions/Expression.h

@ -19,6 +19,7 @@ namespace storm {
public:
friend class ExpressionManager;
friend class Variable;
template<typename MapType> friend class SubstitutionVisitor;
Expression() = default;

1
src/storage/expressions/ExpressionManager.h

@ -7,6 +7,7 @@
#include <unordered_map>
#include <unordered_set>
#include "src/storage/expressions/Variable.h"
#include "src/storage/expressions/Expression.h"
#include "src/utility/OsDetection.h"

127
src/storage/expressions/IdentifierSubstitutionVisitor.cpp

@ -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> >;
}
}

49
src/storage/expressions/IdentifierSubstitutionVisitor.h

@ -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_ */

4
src/storage/expressions/LinearCoefficientVisitor.h

@ -5,7 +5,7 @@
#include "src/storage/expressions/Expression.h"
#include "src/storage/expressions/ExpressionVisitor.h"
#include "src/storage/expressions/Valuation.h"
#include "src/storage/expressions/SimpleValuation.h"
namespace storm {
namespace expressions {
@ -24,7 +24,7 @@ namespace storm {
* @return A pair consisting of a mapping from identifiers to their coefficients and the coefficient of
* the constant atom.
*/
std::pair<Valuation, double> getLinearCoefficients(Expression const& expression);
std::pair<SimpleValuation, double> getLinearCoefficients(Expression const& expression);
virtual boost::any visit(IfThenElseExpression const& expression) override;
virtual boost::any visit(BinaryBooleanFunctionExpression const& expression) override;

8
src/storage/expressions/SimpleValuation.cpp

@ -59,11 +59,11 @@ namespace storm {
(*rationalValues)[rationalVariable.getOffset()] = value;
}
std::size_t SimpleValuationPointerHash::operator()(SimpleValuation* SimpleValuation) const {
std::size_t SimpleValuationPointerHash::operator()(SimpleValuation* valuation) const {
size_t seed = 0;
boost::hash_combine(seed, SimpleValuation->booleanValues);
boost::hash_combine(seed, SimpleValuation->integerValues);
boost::hash_combine(seed, SimpleValuation->rationalValues);
boost::hash_combine(seed, valuation->booleanValues);
boost::hash_combine(seed, valuation->integerValues);
boost::hash_combine(seed, valuation->rationalValues);
return seed;
}

5
src/storage/expressions/SimpleValuation.h

@ -14,6 +14,9 @@ namespace storm {
*/
class SimpleValuation : public Valuation {
public:
friend class SimpleValuationPointerHash;
friend class SimpleValuationPointerLess;
/*!
* Creates a new valuation over the non-auxiliary variables of the given manager.
*/
@ -34,7 +37,7 @@ namespace storm {
*/
bool operator==(SimpleValuation const& other) const;
//
// Override virtual functions of base class.
virtual bool getBooleanValue(Variable const& booleanVariable) const override;
virtual void setBooleanValue(Variable const& booleanVariable, bool value) override;
virtual int_fast64_t getIntegerValue(Variable const& integerVariable) const override;

22
src/storage/expressions/SubstitutionVisitor.cpp

@ -8,7 +8,7 @@
namespace storm {
namespace expressions {
template<typename MapType>
SubstitutionVisitor<MapType>::SubstitutionVisitor(MapType const& identifierToExpressionMap) : identifierToExpressionMap(identifierToExpressionMap) {
SubstitutionVisitor<MapType>::SubstitutionVisitor(MapType const& variableToExpressionMapping) : variableToExpressionMapping(variableToExpressionMapping) {
// Intentionally left empty.
}
@ -27,7 +27,7 @@ namespace storm {
if (conditionExpression.get() == expression.getCondition().get() && thenExpression.get() == expression.getThenExpression().get() && elseExpression.get() == expression.getElseExpression().get()) {
return expression.getSharedPointer();
} else {
return static_cast<std::shared_ptr<BaseExpression const>>(std::shared_ptr<BaseExpression>(new IfThenElseExpression(expression.getReturnType(), conditionExpression, thenExpression, elseExpression)));
return static_cast<std::shared_ptr<BaseExpression const>>(std::shared_ptr<BaseExpression>(new IfThenElseExpression(expression.getManager(), expression.getType(), conditionExpression, thenExpression, elseExpression)));
}
}
@ -40,7 +40,7 @@ namespace storm {
if (firstExpression.get() == expression.getFirstOperand().get() && secondExpression.get() == expression.getSecondOperand().get()) {
return expression.getSharedPointer();
} else {
return static_cast<std::shared_ptr<BaseExpression const>>(std::shared_ptr<BaseExpression>(new BinaryBooleanFunctionExpression(expression.getReturnType(), firstExpression, secondExpression, expression.getOperatorType())));
return static_cast<std::shared_ptr<BaseExpression const>>(std::shared_ptr<BaseExpression>(new BinaryBooleanFunctionExpression(expression.getManager(), expression.getType(), firstExpression, secondExpression, expression.getOperatorType())));
}
}
@ -53,7 +53,7 @@ namespace storm {
if (firstExpression.get() == expression.getFirstOperand().get() && secondExpression.get() == expression.getSecondOperand().get()) {
return expression.getSharedPointer();
} else {
return static_cast<std::shared_ptr<BaseExpression const>>(std::shared_ptr<BaseExpression>(new BinaryNumericalFunctionExpression(expression.getReturnType(), firstExpression, secondExpression, expression.getOperatorType())));
return static_cast<std::shared_ptr<BaseExpression const>>(std::shared_ptr<BaseExpression>(new BinaryNumericalFunctionExpression(expression.getManager(), expression.getType(), firstExpression, secondExpression, expression.getOperatorType())));
}
}
@ -66,15 +66,15 @@ namespace storm {
if (firstExpression.get() == expression.getFirstOperand().get() && secondExpression.get() == expression.getSecondOperand().get()) {
return expression.getSharedPointer();
} else {
return static_cast<std::shared_ptr<BaseExpression const>>(std::shared_ptr<BaseExpression>(new BinaryRelationExpression(expression.getReturnType(), firstExpression, secondExpression, expression.getRelationType())));
return static_cast<std::shared_ptr<BaseExpression const>>(std::shared_ptr<BaseExpression>(new BinaryRelationExpression(expression.getManager(), expression.getType(), firstExpression, secondExpression, expression.getRelationType())));
}
}
template<typename MapType>
boost::any SubstitutionVisitor<MapType>::visit(VariableExpression const& expression) {
// If the variable is in the key set of the substitution, we need to replace it.
auto const& nameExpressionPair = this->identifierToExpressionMap.find(expression.getVariableName());
if (nameExpressionPair != this->identifierToExpressionMap.end()) {
auto const& nameExpressionPair = this->variableToExpressionMapping.find(expression.getVariable());
if (nameExpressionPair != this->variableToExpressionMapping.end()) {
return nameExpressionPair->second.getBaseExpressionPointer();
} else {
return expression.getSharedPointer();
@ -89,7 +89,7 @@ namespace storm {
if (operandExpression.get() == expression.getOperand().get()) {
return expression.getSharedPointer();
} else {
return static_cast<std::shared_ptr<BaseExpression const>>(std::shared_ptr<BaseExpression>(new UnaryBooleanFunctionExpression(expression.getReturnType(), operandExpression, expression.getOperatorType())));
return static_cast<std::shared_ptr<BaseExpression const>>(std::shared_ptr<BaseExpression>(new UnaryBooleanFunctionExpression(expression.getManager(), expression.getType(), operandExpression, expression.getOperatorType())));
}
}
@ -101,7 +101,7 @@ namespace storm {
if (operandExpression.get() == expression.getOperand().get()) {
return expression.getSharedPointer();
} else {
return static_cast<std::shared_ptr<BaseExpression const>>(std::shared_ptr<BaseExpression>(new UnaryNumericalFunctionExpression(expression.getReturnType(), operandExpression, expression.getOperatorType())));
return static_cast<std::shared_ptr<BaseExpression const>>(std::shared_ptr<BaseExpression>(new UnaryNumericalFunctionExpression(expression.getManager(), expression.getType(), operandExpression, expression.getOperatorType())));
}
}
@ -121,7 +121,7 @@ namespace storm {
}
// Explicitly instantiate the class with map and unordered_map.
template class SubstitutionVisitor<std::map<std::string, Expression>>;
template class SubstitutionVisitor<std::unordered_map<std::string, Expression>>;
template class SubstitutionVisitor<std::map<Variable, Expression>>;
template class SubstitutionVisitor<std::unordered_map<Variable, Expression>>;
}
}

10
src/storage/expressions/SubstitutionVisitor.h

@ -12,11 +12,11 @@ namespace storm {
class SubstitutionVisitor : public ExpressionVisitor {
public:
/*!
* Creates a new substitution visitor that uses the given map to replace identifiers.
* Creates a new substitution visitor that uses the given map to replace variables.
*
* @param identifierToExpressionMap A mapping from identifiers to expressions.
* @param variableToExpressionMapping A mapping from variables to expressions.
*/
SubstitutionVisitor(MapType const& identifierToExpressionMap);
SubstitutionVisitor(MapType const& variableToExpressionMapping);
/*!
* Substitutes the identifiers in the given expression according to the previously given map and returns the
@ -40,8 +40,8 @@ namespace storm {
virtual boost::any visit(DoubleLiteralExpression const& expression) override;
private:
// A mapping of identifier names to expressions with which they shall be replaced.
MapType const& identifierToExpressionMap;
// A mapping of variables to expressions with which they shall be replaced.
MapType const& variableToExpressionMapping;
};
}
}

3
src/storage/expressions/Valuation.h

@ -14,9 +14,6 @@ namespace storm {
*/
class Valuation {
public:
friend class ValuationPointerHash;
friend class ValuationPointerLess;
/*!
* Creates a valuation of all non-auxiliary variables managed by the given manager. If the manager is
* modified in the sense that additional variables are added, all valuations over its variables are

Loading…
Cancel
Save