41 changed files with 896 additions and 482 deletions
-
43src/adapters/MathsatExpressionAdapter.h
-
49src/adapters/Z3ExpressionAdapter.h
-
99src/solver/MathsatSmtSolver.cpp
-
4src/solver/MathsatSmtSolver.h
-
25src/solver/Z3SmtSolver.cpp
-
14src/storage/expressions/BaseExpression.cpp
-
32src/storage/expressions/BaseExpression.h
-
14src/storage/expressions/BinaryBooleanFunctionExpression.cpp
-
4src/storage/expressions/BinaryBooleanFunctionExpression.h
-
2src/storage/expressions/BinaryExpression.cpp
-
4src/storage/expressions/BinaryExpression.h
-
8src/storage/expressions/BinaryNumericalFunctionExpression.cpp
-
4src/storage/expressions/BinaryNumericalFunctionExpression.h
-
6src/storage/expressions/BinaryRelationExpression.cpp
-
4src/storage/expressions/BinaryRelationExpression.h
-
3src/storage/expressions/BooleanLiteralExpression.cpp
-
3src/storage/expressions/DoubleLiteralExpression.cpp
-
51src/storage/expressions/Expression.cpp
-
6src/storage/expressions/Expression.h
-
147src/storage/expressions/ExpressionManager.cpp
-
69src/storage/expressions/ExpressionManager.h
-
15src/storage/expressions/ExpressionReturnType.cpp
-
35src/storage/expressions/ExpressionReturnType.h
-
4src/storage/expressions/IfThenElseExpression.cpp
-
4src/storage/expressions/IfThenElseExpression.h
-
3src/storage/expressions/IntegerLiteralExpression.cpp
-
4src/storage/expressions/LinearCoefficientVisitor.h
-
78src/storage/expressions/SimpleValuation.cpp
-
83src/storage/expressions/SimpleValuation.h
-
156src/storage/expressions/Type.cpp
-
224src/storage/expressions/Type.h
-
10src/storage/expressions/UnaryBooleanFunctionExpression.cpp
-
4src/storage/expressions/UnaryBooleanFunctionExpression.h
-
2src/storage/expressions/UnaryExpression.cpp
-
4src/storage/expressions/UnaryExpression.h
-
8src/storage/expressions/UnaryNumericalFunctionExpression.cpp
-
4src/storage/expressions/UnaryNumericalFunctionExpression.h
-
72src/storage/expressions/Valuation.cpp
-
63src/storage/expressions/Valuation.h
-
10src/storage/expressions/Variable.cpp
-
4src/storage/expressions/Variable.h
@ -1,15 +0,0 @@ |
|||
#include "src/storage/expressions/ExpressionReturnType.h"
|
|||
|
|||
namespace storm { |
|||
namespace expressions { |
|||
std::ostream& operator<<(std::ostream& stream, ExpressionReturnType const& enumValue) { |
|||
switch (enumValue) { |
|||
case ExpressionReturnType::Undefined: stream << "undefined"; break; |
|||
case ExpressionReturnType::Bool: stream << "bool"; break; |
|||
case ExpressionReturnType::Int: stream << "int"; break; |
|||
case ExpressionReturnType::Double: stream << "double"; break; |
|||
} |
|||
return stream; |
|||
} |
|||
} |
|||
} |
@ -1,35 +0,0 @@ |
|||
#ifndef STORM_STORAGE_EXPRESSIONS_EXPRESSIONRETURNTYPE_H_ |
|||
#define STORM_STORAGE_EXPRESSIONS_EXPRESSIONRETURNTYPE_H_ |
|||
|
|||
#include <iostream> |
|||
|
|||
namespace storm { |
|||
namespace expressions { |
|||
/*! |
|||
* Each node in an expression tree has a uniquely defined type from this enum. |
|||
*/ |
|||
enum class ExpressionReturnType { Undefined = 0, Bool = 1, Int = 2, Double = 3}; |
|||
|
|||
std::ostream& operator<<(std::ostream& stream, ExpressionReturnType const& enumValue); |
|||
} |
|||
} |
|||
|
|||
namespace std { |
|||
// Provide a hashing operator, so we can put variables in unordered collections. |
|||
template <> |
|||
struct hash<storm::expressions::ExpressionReturnType> { |
|||
std::size_t operator()(storm::expressions::ExpressionReturnType const& type) const { |
|||
return static_cast<std::size_t>(type); |
|||
} |
|||
}; |
|||
|
|||
// Provide a less operator, so we can put variables in ordered collections. |
|||
template <> |
|||
struct less<storm::expressions::ExpressionReturnType> { |
|||
std::size_t operator()(storm::expressions::ExpressionReturnType const& type1, storm::expressions::ExpressionReturnType const& type2) const { |
|||
return static_cast<std::size_t>(type1) < static_cast<std::size_t>(type2); |
|||
} |
|||
}; |
|||
} |
|||
|
|||
#endif /* STORM_STORAGE_EXPRESSIONS_EXPRESSIONRETURNTYPE_H_ */ |
@ -0,0 +1,78 @@ |
|||
#include "src/storage/expressions/SimpleValuation.h"
|
|||
|
|||
#include <boost/functional/hash.hpp>
|
|||
|
|||
#include "src/storage/expressions/ExpressionManager.h"
|
|||
#include "src/storage/expressions/Variable.h"
|
|||
|
|||
namespace storm { |
|||
namespace expressions { |
|||
SimpleValuation::SimpleValuation(ExpressionManager const& manager) : Valuation(manager), booleanValues(nullptr), integerValues(nullptr), rationalValues(nullptr) { |
|||
if (manager.getNumberOfBooleanVariables() > 0) { |
|||
booleanValues = std::unique_ptr<std::vector<bool>>(new std::vector<bool>(manager.getNumberOfBooleanVariables())); |
|||
} |
|||
if (manager.getNumberOfIntegerVariables() > 0) { |
|||
integerValues = std::unique_ptr<std::vector<int_fast64_t>>(new std::vector<int_fast64_t>(manager.getNumberOfIntegerVariables())); |
|||
} |
|||
if (manager.getNumberOfRationalVariables() > 0) { |
|||
rationalValues = std::unique_ptr<std::vector<double>>(new std::vector<double>(manager.getNumberOfRationalVariables())); |
|||
} |
|||
} |
|||
|
|||
SimpleValuation::SimpleValuation(SimpleValuation const& other) : Valuation(other.getManager()) { |
|||
if (other.booleanValues != nullptr) { |
|||
booleanValues = std::unique_ptr<std::vector<bool>>(new std::vector<bool>(*other.booleanValues)); |
|||
} |
|||
if (other.integerValues != nullptr) { |
|||
integerValues = std::unique_ptr<std::vector<int_fast64_t>>(new std::vector<int_fast64_t>(*other.integerValues)); |
|||
} |
|||
if (other.booleanValues != nullptr) { |
|||
rationalValues = std::unique_ptr<std::vector<double>>(new std::vector<double>(*other.rationalValues)); |
|||
} |
|||
} |
|||
|
|||
bool SimpleValuation::operator==(SimpleValuation const& other) const { |
|||
return this->getManager() == other.getManager() && booleanValues == other.booleanValues && integerValues == other.integerValues && rationalValues == other.rationalValues; |
|||
} |
|||
|
|||
bool SimpleValuation::getBooleanValue(Variable const& booleanVariable) const { |
|||
return (*booleanValues)[booleanVariable.getOffset()]; |
|||
} |
|||
|
|||
int_fast64_t SimpleValuation::getIntegerValue(Variable const& integerVariable) const { |
|||
return (*integerValues)[integerVariable.getOffset()]; |
|||
} |
|||
|
|||
double SimpleValuation::getRationalValue(Variable const& rationalVariable) const { |
|||
return (*rationalValues)[rationalVariable.getOffset()]; |
|||
} |
|||
|
|||
void SimpleValuation::setBooleanValue(Variable const& booleanVariable, bool value) { |
|||
(*booleanValues)[booleanVariable.getOffset()] = value; |
|||
} |
|||
|
|||
void SimpleValuation::setIntegerValue(Variable const& integerVariable, int_fast64_t value) { |
|||
(*integerValues)[integerVariable.getOffset()] = value; |
|||
} |
|||
|
|||
void SimpleValuation::setRationalValue(Variable const& rationalVariable, double value) { |
|||
(*rationalValues)[rationalVariable.getOffset()] = value; |
|||
} |
|||
|
|||
std::size_t SimpleValuationPointerHash::operator()(SimpleValuation* SimpleValuation) const { |
|||
size_t seed = 0; |
|||
boost::hash_combine(seed, SimpleValuation->booleanValues); |
|||
boost::hash_combine(seed, SimpleValuation->integerValues); |
|||
boost::hash_combine(seed, SimpleValuation->rationalValues); |
|||
return seed; |
|||
} |
|||
|
|||
bool SimpleValuationPointerCompare::operator()(SimpleValuation* SimpleValuation1, SimpleValuation* SimpleValuation2) const { |
|||
return *SimpleValuation1 == *SimpleValuation2; |
|||
} |
|||
|
|||
bool SimpleValuationPointerLess::operator()(SimpleValuation* SimpleValuation1, SimpleValuation* SimpleValuation2) const { |
|||
return SimpleValuation1->booleanValues < SimpleValuation2->booleanValues || SimpleValuation1->integerValues < SimpleValuation2->integerValues || SimpleValuation1->rationalValues < SimpleValuation2->rationalValues; |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,83 @@ |
|||
#ifndef STORM_STORAGE_EXPRESSIONS_SIMPLEVALUATION_H_ |
|||
#define STORM_STORAGE_EXPRESSIONS_SIMPLEVALUATION_H_ |
|||
|
|||
#include <cstdint> |
|||
#include <vector> |
|||
|
|||
#include "src/storage/expressions/Valuation.h" |
|||
|
|||
namespace storm { |
|||
namespace expressions { |
|||
|
|||
/*! |
|||
* A simple implementation of the valuation interface. |
|||
*/ |
|||
class SimpleValuation : public Valuation { |
|||
public: |
|||
/*! |
|||
* Creates a new valuation over the non-auxiliary variables of the given manager. |
|||
*/ |
|||
SimpleValuation(storm::expressions::ExpressionManager const& manager); |
|||
|
|||
/*! |
|||
* Deep-copies the valuation. |
|||
* |
|||
* @param other The valuation to copy |
|||
*/ |
|||
SimpleValuation(SimpleValuation const& other); |
|||
|
|||
/*! |
|||
* Checks whether the two valuations are semantically equivalent. |
|||
* |
|||
* @param other The valuation with which to compare. |
|||
* @return True iff the two valuations are semantically equivalent. |
|||
*/ |
|||
bool operator==(SimpleValuation const& other) const; |
|||
|
|||
// |
|||
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; |
|||
virtual void setIntegerValue(Variable const& integerVariable, int_fast64_t value) override; |
|||
virtual double getRationalValue(Variable const& rationalVariable) const override; |
|||
virtual void setRationalValue(Variable const& rationalVariable, double value) override; |
|||
|
|||
private: |
|||
// Containers that store the values of the variables of the appropriate type. |
|||
std::unique_ptr<std::vector<bool>> booleanValues; |
|||
std::unique_ptr<std::vector<int_fast64_t>> integerValues; |
|||
std::unique_ptr<std::vector<double>> rationalValues; |
|||
}; |
|||
|
|||
/*! |
|||
* A helper class that can pe used as the hash functor for data structures that need to hash valuations given |
|||
* via pointers. |
|||
*/ |
|||
class SimpleValuationPointerHash { |
|||
public: |
|||
std::size_t operator()(SimpleValuation* valuation) const; |
|||
}; |
|||
|
|||
/*! |
|||
* A helper class that can be used as the comparison functor wrt. equality for data structures that need to |
|||
* store pointers to valuations and need to compare the elements wrt. their content (rather than pointer |
|||
* equality). |
|||
*/ |
|||
class SimpleValuationPointerCompare { |
|||
public: |
|||
bool operator()(SimpleValuation* valuation1, SimpleValuation* valuation2) const; |
|||
}; |
|||
|
|||
/*! |
|||
* A helper class that can be used as the comparison functor wrt. "<" for data structures that need to |
|||
* store pointers to valuations and need to compare the elements wrt. their content (rather than pointer |
|||
* equality). |
|||
*/ |
|||
class SimpleValuationPointerLess { |
|||
public: |
|||
bool operator()(SimpleValuation* valuation1, SimpleValuation* valuation2) const; |
|||
}; |
|||
} |
|||
} |
|||
|
|||
#endif /* STORM_STORAGE_EXPRESSIONS_SIMPLEVALUATION_H_ */ |
@ -0,0 +1,156 @@ |
|||
#include "src/storage/expressions/Type.h"
|
|||
|
|||
#include "src/storage/expressions/ExpressionManager.h"
|
|||
#include "src/utility/macros.h"
|
|||
|
|||
namespace storm { |
|||
namespace expressions { |
|||
|
|||
bool BaseType::operator==(BaseType const& other) const { |
|||
return this->getMask() == other.getMask(); |
|||
} |
|||
|
|||
uint64_t BooleanType::getMask() const { |
|||
return BooleanType::mask; |
|||
} |
|||
|
|||
std::string BooleanType::getStringRepresentation() const { |
|||
return "bool"; |
|||
} |
|||
|
|||
uint64_t IntegerType::getMask() const { |
|||
return IntegerType::mask; |
|||
} |
|||
|
|||
std::string IntegerType::getStringRepresentation() const { |
|||
return "int"; |
|||
} |
|||
|
|||
uint64_t BoundedIntegerType::getMask() const { |
|||
return BoundedIntegerType::mask; |
|||
} |
|||
|
|||
std::string BoundedIntegerType::getStringRepresentation() const { |
|||
return "int[" + std::to_string(width) + "]"; |
|||
} |
|||
|
|||
std::size_t BoundedIntegerType::getWidth() const { |
|||
return width; |
|||
} |
|||
|
|||
bool BoundedIntegerType::operator==(BaseType const& other) const { |
|||
return this->getMask() == other.getMask() && this->width == static_cast<BoundedIntegerType const&>(other).width; |
|||
} |
|||
|
|||
uint64_t RationalType::getMask() const { |
|||
return RationalType::mask; |
|||
} |
|||
|
|||
std::string RationalType::getStringRepresentation() const { |
|||
return "rational"; |
|||
} |
|||
|
|||
Type::Type(ExpressionManager const& manager, std::shared_ptr<BaseType> innerType) : manager(manager), innerType(innerType) { |
|||
// Intentionally left empty.
|
|||
} |
|||
|
|||
bool Type::operator==(Type const& other) const { |
|||
return *this->innerType == *other.innerType; |
|||
} |
|||
|
|||
uint64_t Type::getMask() const { |
|||
return this->innerType->getMask(); |
|||
} |
|||
|
|||
std::string Type::getStringRepresentation() const { |
|||
return this->innerType->getStringRepresentation(); |
|||
} |
|||
|
|||
bool Type::isNumericalType() const { |
|||
return this->isIntegralType() || this->isRationalType(); |
|||
} |
|||
|
|||
bool Type::isIntegralType() const { |
|||
return this->isUnboundedIntegralType() || this->isBoundedIntegralType(); |
|||
} |
|||
|
|||
bool Type::isBooleanType() const { |
|||
return typeid(*this->innerType) == typeid(BooleanType); |
|||
} |
|||
|
|||
bool Type::isUnboundedIntegralType() const { |
|||
return typeid(*this->innerType) == typeid(IntegerType); |
|||
} |
|||
|
|||
bool Type::isBoundedIntegralType() const { |
|||
return typeid(*this->innerType) == typeid(BoundedIntegerType); |
|||
} |
|||
|
|||
std::size_t Type::getWidth() const { |
|||
return dynamic_cast<BoundedIntegerType const&>(*this->innerType).getWidth(); |
|||
} |
|||
|
|||
bool Type::isRationalType() const { |
|||
return typeid(*this->innerType) == typeid(RationalType); |
|||
} |
|||
|
|||
Type Type::plusMinusTimes(Type const& other) const { |
|||
STORM_LOG_ASSERT(this->isNumericalType() && other.isNumericalType(), "Operator requires numerical operands."); |
|||
if (this->isRationalType() || other.isRationalType()) { |
|||
return manager.getRationalType(); |
|||
} |
|||
return manager.getIntegerType(); |
|||
} |
|||
|
|||
Type Type::minus() const { |
|||
STORM_LOG_ASSERT(this->isNumericalType(), "Operator requires numerical operand."); |
|||
return *this; |
|||
} |
|||
|
|||
Type Type::divide(Type const& other) const { |
|||
STORM_LOG_ASSERT(this->isNumericalType() && other.isNumericalType(), "Operator requires numerical operands."); |
|||
return manager.getRationalType(); |
|||
} |
|||
|
|||
Type Type::logicalConnective(Type const& other) const { |
|||
STORM_LOG_ASSERT(this->isBooleanType() && other.isBooleanType(), "Operator requires boolean operands."); |
|||
return *this; |
|||
} |
|||
|
|||
Type Type::logicalConnective() const { |
|||
STORM_LOG_ASSERT(this->isBooleanType(), "Operator requires boolean operand."); |
|||
return *this; |
|||
} |
|||
|
|||
Type Type::numericalComparison(Type const& other) const { |
|||
STORM_LOG_ASSERT(this->isNumericalType() && other.isNumericalType(), "Operator requires numerical operands."); |
|||
if (this->isRationalType() || other.isRationalType()) { |
|||
return manager.getRationalType(); |
|||
} |
|||
return manager.getIntegerType(); |
|||
} |
|||
|
|||
Type Type::ite(Type const& thenType, Type const& elseType) const { |
|||
STORM_LOG_ASSERT(thenType == elseType, "Operator requires equal types."); |
|||
return thenType; |
|||
} |
|||
|
|||
Type Type::floorCeil() const { |
|||
STORM_LOG_ASSERT(this->isRationalType(), "Operator requires rational operand."); |
|||
return manager.getIntegerType(); |
|||
} |
|||
|
|||
Type Type::minimumMaximum(Type const& other) const { |
|||
STORM_LOG_ASSERT(this->isNumericalType() && other.isNumericalType(), "Operator requires numerical operands."); |
|||
if (this->isRationalType() || other.isRationalType()) { |
|||
return manager.getRationalType(); |
|||
} |
|||
return manager.getIntegerType(); |
|||
} |
|||
|
|||
std::ostream& operator<<(std::ostream& stream, Type const& type) { |
|||
stream << type.getStringRepresentation(); |
|||
return stream; |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,224 @@ |
|||
#ifndef STORM_STORAGE_EXPRESSIONS_EXPRESSIONRETURNTYPE_H_ |
|||
#define STORM_STORAGE_EXPRESSIONS_EXPRESSIONRETURNTYPE_H_ |
|||
|
|||
#include <iostream> |
|||
#include <memory> |
|||
#include <cstdint> |
|||
|
|||
#include "src/storage/expressions/OperatorType.h" |
|||
|
|||
namespace storm { |
|||
namespace expressions { |
|||
// Forward-declare expression manager class. |
|||
class ExpressionManager; |
|||
|
|||
class BaseType { |
|||
public: |
|||
/*! |
|||
* Retrieves the mask that is associated with this type. |
|||
* |
|||
* @return The mask associated with this type. |
|||
*/ |
|||
virtual uint64_t getMask() const = 0; |
|||
|
|||
/*! |
|||
* Checks whether two types are actually the same. |
|||
* |
|||
* @param other The type to compare with. |
|||
* @return True iff the types are the same. |
|||
*/ |
|||
virtual bool operator==(BaseType const& other) const; |
|||
|
|||
/*! |
|||
* Returns a string representation of the type. |
|||
* |
|||
* @return A string representation of the type. |
|||
*/ |
|||
virtual std::string getStringRepresentation() const = 0; |
|||
}; |
|||
|
|||
class BooleanType : public BaseType { |
|||
public: |
|||
virtual uint64_t getMask() const override; |
|||
virtual std::string getStringRepresentation() const override; |
|||
|
|||
private: |
|||
static const uint64_t mask = (1 << 61); |
|||
}; |
|||
|
|||
class IntegerType : public BaseType { |
|||
public: |
|||
virtual uint64_t getMask() const override; |
|||
virtual std::string getStringRepresentation() const override; |
|||
|
|||
private: |
|||
static const uint64_t mask = (1 << 62); |
|||
}; |
|||
|
|||
class BoundedIntegerType : public BaseType { |
|||
public: |
|||
/*! |
|||
* Creates a new bounded integer type with the given bit width. |
|||
* |
|||
* @param width The bit width of the type. |
|||
*/ |
|||
BoundedIntegerType(std::size_t width); |
|||
|
|||
/*! |
|||
* Retrieves the bit width of the bounded type. |
|||
* |
|||
* @return The bit width of the bounded type. |
|||
*/ |
|||
std::size_t getWidth() const; |
|||
|
|||
virtual uint64_t getMask() const override; |
|||
|
|||
virtual bool operator==(BaseType const& other) const override; |
|||
|
|||
virtual std::string getStringRepresentation() const override; |
|||
|
|||
private: |
|||
static const uint64_t mask = (1 << 61) | (1 << 62); |
|||
|
|||
// The bit width of the type. |
|||
std::size_t width; |
|||
}; |
|||
|
|||
class RationalType : public BaseType { |
|||
public: |
|||
virtual uint64_t getMask() const override; |
|||
|
|||
virtual std::string getStringRepresentation() const override; |
|||
|
|||
private: |
|||
static const uint64_t mask = (1 << 63); |
|||
}; |
|||
|
|||
class ErrorType : public BaseType { |
|||
public: |
|||
virtual uint64_t getMask() const override; |
|||
|
|||
virtual std::string getStringRepresentation() const override; |
|||
|
|||
private: |
|||
static const uint64_t mask = 0; |
|||
}; |
|||
|
|||
class Type { |
|||
public: |
|||
Type(ExpressionManager const& manager, std::shared_ptr<BaseType> innerType); |
|||
|
|||
/*! |
|||
* Checks whether two types are the same. |
|||
* |
|||
* @other The type to compare with. |
|||
* @return True iff the types are the same. |
|||
*/ |
|||
bool operator==(Type const& other) const; |
|||
|
|||
/*! |
|||
* Retrieves the bit mask of the type. |
|||
* |
|||
* @return The bit mask of the type. |
|||
*/ |
|||
uint64_t getMask() const; |
|||
|
|||
/*! |
|||
* Retrieves a string representation of the type. |
|||
* |
|||
* @return A string representation of the type. |
|||
*/ |
|||
std::string getStringRepresentation() const; |
|||
|
|||
/*! |
|||
* Checks whether this type is a numerical type. |
|||
* |
|||
* @return True iff the type is a numerical one. |
|||
*/ |
|||
bool isNumericalType() const; |
|||
|
|||
/*! |
|||
* Checks whether this type is an integral type. |
|||
* |
|||
* @return True iff the type is a integral one. |
|||
*/ |
|||
bool isIntegralType() const; |
|||
|
|||
/*! |
|||
* Checks whether this type is a boolean type. |
|||
* |
|||
* @return True iff the type is a boolean one. |
|||
*/ |
|||
bool isBooleanType() const; |
|||
|
|||
/*! |
|||
* Checks whether this type is an unbounded integral type. |
|||
* |
|||
* @return True iff the type is a unbounded integral one. |
|||
*/ |
|||
bool isUnboundedIntegralType() const; |
|||
|
|||
/*! |
|||
* Checks whether this type is a bounded integral type. |
|||
* |
|||
* @return True iff the type is a bounded integral one. |
|||
*/ |
|||
bool isBoundedIntegralType() const; |
|||
|
|||
/*! |
|||
* Retrieves the bit width of the type, provided that it is a bounded integral type. |
|||
* |
|||
* @return The bit width of the bounded integral type. |
|||
*/ |
|||
std::size_t getWidth() const; |
|||
|
|||
/*! |
|||
* Checks whether this type is a rational type. |
|||
* |
|||
* @return True iff the type is a rational one. |
|||
*/ |
|||
bool isRationalType() const; |
|||
|
|||
// Functions that, given the input types, produce the output type of the corresponding function application. |
|||
Type plusMinusTimes(Type const& other) const; |
|||
Type minus() const; |
|||
Type divide(Type const& other) const; |
|||
Type logicalConnective(Type const& other) const; |
|||
Type logicalConnective() const; |
|||
Type numericalComparison(Type const& other) const; |
|||
Type ite(Type const& thenType, Type const& elseType) const; |
|||
Type floorCeil() const; |
|||
Type minimumMaximum(Type const& other) const; |
|||
|
|||
private: |
|||
// The manager responsible for the type. |
|||
ExpressionManager const& manager; |
|||
|
|||
// The encapsulated type. |
|||
std::shared_ptr<BaseType> innerType; |
|||
}; |
|||
|
|||
std::ostream& operator<<(std::ostream& stream, Type const& type); |
|||
|
|||
} |
|||
} |
|||
|
|||
namespace std { |
|||
// Provide a hashing operator, so we can put types in unordered collections. |
|||
template <> |
|||
struct hash<storm::expressions::Type> { |
|||
std::size_t operator()(storm::expressions::Type const& type) const { |
|||
return std::hash<uint64_t>()(type.getMask()); |
|||
} |
|||
}; |
|||
|
|||
// Provide a less operator, so we can put types in ordered collections. |
|||
template <> |
|||
struct less<storm::expressions::Type> { |
|||
std::size_t operator()(storm::expressions::Type const& type1, storm::expressions::Type const& type2) const { |
|||
return type1.getMask() < type2.getMask(); |
|||
} |
|||
}; |
|||
} |
|||
|
|||
#endif /* STORM_STORAGE_EXPRESSIONS_EXPRESSIONRETURNTYPE_H_ */ |
@ -1,82 +1,10 @@ |
|||
#include "src/storage/expressions/Valuation.h"
|
|||
|
|||
#include <boost/functional/hash.hpp>
|
|||
|
|||
#include "src/storage/expressions/ExpressionManager.h"
|
|||
#include "src/storage/expressions/Variable.h"
|
|||
|
|||
namespace storm { |
|||
namespace expressions { |
|||
Valuation::Valuation(ExpressionManager const& manager) : manager(manager), booleanValues(nullptr), integerValues(nullptr), rationalValues(nullptr) { |
|||
if (manager.getNumberOfBooleanVariables() > 0) { |
|||
booleanValues = std::unique_ptr<std::vector<bool>>(new std::vector<bool>(manager.getNumberOfBooleanVariables())); |
|||
} |
|||
if (manager.getNumberOfIntegerVariables() > 0) { |
|||
integerValues = std::unique_ptr<std::vector<int_fast64_t>>(new std::vector<int_fast64_t>(manager.getNumberOfIntegerVariables())); |
|||
} |
|||
if (manager.getNumberOfRationalVariables() > 0) { |
|||
rationalValues = std::unique_ptr<std::vector<double>>(new std::vector<double>(manager.getNumberOfRationalVariables())); |
|||
} |
|||
} |
|||
|
|||
Valuation::Valuation(Valuation const& other) : manager(other.manager) { |
|||
if (other.booleanValues != nullptr) { |
|||
booleanValues = std::unique_ptr<std::vector<bool>>(new std::vector<bool>(*other.booleanValues)); |
|||
} |
|||
if (other.integerValues != nullptr) { |
|||
integerValues = std::unique_ptr<std::vector<int_fast64_t>>(new std::vector<int_fast64_t>(*other.integerValues)); |
|||
} |
|||
if (other.booleanValues != nullptr) { |
|||
rationalValues = std::unique_ptr<std::vector<double>>(new std::vector<double>(*other.rationalValues)); |
|||
} |
|||
} |
|||
|
|||
bool Valuation::operator==(Valuation const& other) const { |
|||
return manager == other.manager && booleanValues == other.booleanValues && integerValues == other.integerValues && rationalValues == other.rationalValues; |
|||
} |
|||
|
|||
bool Valuation::getBooleanValue(Variable const& booleanVariable) const { |
|||
return (*booleanValues)[booleanVariable.getOffset()]; |
|||
} |
|||
|
|||
int_fast64_t Valuation::getIntegerValue(Variable const& integerVariable) const { |
|||
return (*integerValues)[integerVariable.getOffset()]; |
|||
} |
|||
|
|||
double Valuation::getRationalValue(Variable const& rationalVariable) const { |
|||
return (*rationalValues)[rationalVariable.getOffset()]; |
|||
} |
|||
|
|||
void Valuation::setBooleanValue(Variable const& booleanVariable, bool value) { |
|||
(*booleanValues)[booleanVariable.getOffset()] = value; |
|||
} |
|||
|
|||
void Valuation::setIntegerValue(Variable const& integerVariable, int_fast64_t value) { |
|||
(*integerValues)[integerVariable.getOffset()] = value; |
|||
} |
|||
|
|||
void Valuation::setRationalValue(Variable const& rationalVariable, double value) { |
|||
(*rationalValues)[rationalVariable.getOffset()] = value; |
|||
} |
|||
|
|||
ExpressionManager const& Valuation::getManager() const { |
|||
return manager; |
|||
} |
|||
|
|||
std::size_t ValuationPointerHash::operator()(Valuation* valuation) const { |
|||
size_t seed = 0; |
|||
boost::hash_combine(seed, valuation->booleanValues); |
|||
boost::hash_combine(seed, valuation->integerValues); |
|||
boost::hash_combine(seed, valuation->rationalValues); |
|||
return seed; |
|||
} |
|||
|
|||
bool ValuationPointerCompare::operator()(Valuation* valuation1, Valuation* valuation2) const { |
|||
return *valuation1 == *valuation2; |
|||
} |
|||
|
|||
bool ValuationPointerLess::operator()(Valuation* valuation1, Valuation* valuation2) const { |
|||
return valuation1->booleanValues < valuation2->booleanValues || valuation1->integerValues < valuation2->integerValues || valuation1->rationalValues < valuation2->rationalValues; |
|||
} |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue