Browse Source
Started working on new easy-to-use expression classes.
Started working on new easy-to-use expression classes.
Former-commit-id: 9ee1be5822
tempestpy_adaptions
dehnert
11 years ago
8 changed files with 176 additions and 0 deletions
-
2CMakeLists.txt
-
26src/storage/expressions/BaseExpression.h
-
13src/storage/expressions/Expression.cpp
-
42src/storage/expressions/Expression.h
-
29src/storage/expressions/SimpleValuation.cpp
-
40src/storage/expressions/SimpleValuation.h
-
15src/storage/expressions/Valuation.h
-
9test/functional/storage/ExpressionTest.cpp
@ -0,0 +1,26 @@ |
|||
#ifndef STORM_STORAGE_EXPRESSIONS_BASEEXPRESSION_H_ |
|||
#define STORM_STORAGE_EXPRESSIONS_BASEEXPRESSION_H_ |
|||
|
|||
#include "src/storage/expressions/Valuation.h" |
|||
|
|||
namespace storm { |
|||
namespace expressions { |
|||
class BaseExpression { |
|||
public: |
|||
/*! |
|||
* Each node in an expression tree has a uniquely defined type from this enum. |
|||
*/ |
|||
enum ReturnType {undefined, bool_, int_, double_}; |
|||
|
|||
std::unique_ptr<BaseExpression> substitute() const = 0; |
|||
|
|||
virtual int_fast64_t evaluateAsInt(Evaluation const& evaluation) const = 0; |
|||
|
|||
virtual bool evaluateAsBool(Evaluation const& evaluation) const = 0; |
|||
|
|||
virtual double evaluateAsDouble(Evaluation const& evaluation) const = 0; |
|||
}; |
|||
} |
|||
} |
|||
|
|||
#endif /* STORM_STORAGE_EXPRESSIONS_BASEEXPRESSION_H_ */ |
@ -0,0 +1,13 @@ |
|||
#include "src/storage/expressions/Expression.h"
|
|||
|
|||
namespace storm { |
|||
namespace expressions { |
|||
virtual Expression Expression::operator+(Expression const& other) { |
|||
return Expression(this->getBaseExpression() + other.getBaseExpression()); |
|||
} |
|||
|
|||
BaseExpression const& getBaseExpression() const { |
|||
return *this->expressionPtr; |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,42 @@ |
|||
#ifndef STORM_STORAGE_EXPRESSIONS_EXPRESSION_H_ |
|||
#define STORM_STORAGE_EXPRESSIONS_EXPRESSION_H_ |
|||
|
|||
namespace storm { |
|||
namespace expressions { |
|||
class Expression { |
|||
Expression() = default; |
|||
|
|||
// Static factory methods to create atomic expression parts. |
|||
|
|||
// Virtual operator overloading. |
|||
virtual Expression operator+(Expression const& other); |
|||
|
|||
/*! |
|||
* Substitutes all occurrences of identifiers according to the given substitution. Note that this |
|||
* substitution is done simultaneously, i.e., identifiers appearing in the expressions that were "plugged |
|||
* in" are not substituted. |
|||
* |
|||
* @param substitutionFilter A function that returns true iff the given identifier is supposed to be |
|||
* substituted. |
|||
* @param substitution A substitution that returns for each identifier an expression that is supposed to |
|||
* replace the identifier. |
|||
* @return An expression in which all identifiers |
|||
*/ |
|||
Expression substitute(std::function<Expression (std::string const&)> const& substitution) const; |
|||
|
|||
private: |
|||
/*! |
|||
* Retrieves the base expression underlying this expression object. Note that prior to calling this, the |
|||
* expression object must be properly initialized. |
|||
* |
|||
* @return A reference to the underlying base expression. |
|||
*/ |
|||
BaseExpression const& getBaseExpression() const; |
|||
|
|||
// A pointer to the underlying base expression. |
|||
std::unique_ptr<BaseExpression> expressionPtr; |
|||
}; |
|||
} |
|||
} |
|||
|
|||
#endif /* STORM_STORAGE_EXPRESSIONS_EXPRESSION_H_ */ |
@ -0,0 +1,29 @@ |
|||
#include "src/storage/expressions/SimpleValuation.h"
|
|||
|
|||
namespace storm { |
|||
namespace expressions { |
|||
SimpleValuation::SimpleValuation(std::size_t booleanVariableCount, std::size_t integerVariableCount, std::size_t doubleVariableCount) : identifierToIndexMap(), booleanValues(booleanVariableCount), integerValues(integerVariableCount), doubleValues(doubleVariableCount) { |
|||
// Intentionally left empty.
|
|||
} |
|||
|
|||
SimpleValuation::SimpleValuation(std::shared_ptr<std::unordered_map<std::string, uint_fast64_t>> identifierToIndexMap, std::vector<bool> booleanValues, std::vector<int_fast64_t> integerValues, std::vector<double> doubleValues) : identifierToIndexMap(identifierToIndexMap), booleanValues(booleanValues), integerValues(integerValues), doubleValues(doubleValues) { |
|||
// Intentionally left empty.
|
|||
} |
|||
|
|||
void SimpleValuation::setIdentifierIndex(std::string const& name, uint_fast64_t index) { |
|||
(*this->identifierToIndexMap)[name] = index; |
|||
} |
|||
|
|||
bool SimpleValuation::getBooleanValue(std::string const& name) const { |
|||
return false; |
|||
} |
|||
|
|||
int_fast64_t SimpleValuation::getIntegerValue(std::string const& name) const { |
|||
return 0; |
|||
} |
|||
|
|||
double SimpleValuation::getDoubleValue(std::string const& name) const { |
|||
return 0.0; |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,40 @@ |
|||
#ifndef STORM_STORAGE_EXPRESSIONS_SIMPLEVALUATION_H_ |
|||
#define STORM_STORAGE_EXPRESSIONS_SIMPLEVALUATION_H_ |
|||
|
|||
#include <memory> |
|||
#include <vector> |
|||
#include <string> |
|||
#include <unordered_map> |
|||
|
|||
#include "src/storage/expressions/Valuation.h" |
|||
|
|||
namespace storm { |
|||
namespace expressions { |
|||
class SimpleValuation : public Valuation { |
|||
public: |
|||
SimpleValuation(std::size_t booleanVariableCount, std::size_t integerVariableCount, std::size_t doubleVariableCount); |
|||
|
|||
SimpleValuation(std::shared_ptr<std::unordered_map<std::string, uint_fast64_t>> identifierToIndexMap, std::vector<bool> booleanValues, std::vector<int_fast64_t> integerValues, std::vector<double> doubleValues); |
|||
|
|||
SimpleValuation() = default; |
|||
SimpleValuation(SimpleValuation const&) = default; |
|||
SimpleValuation(SimpleValuation&&) = default; |
|||
SimpleValuation& operator=(SimpleValuation const&) = default; |
|||
SimpleValuation& operator=(SimpleValuation&&) = default; |
|||
|
|||
void setIdentifierIndex(std::string const& name, uint_fast64_t index); |
|||
|
|||
virtual bool getBooleanValue(std::string const& name) const override; |
|||
virtual int_fast64_t getIntegerValue(std::string const& name) const override; |
|||
virtual double getDoubleValue(std::string const& name) const override; |
|||
|
|||
private: |
|||
std::shared_ptr<std::unordered_map<std::string, uint_fast64_t>> identifierToIndexMap; |
|||
std::vector<bool> booleanValues; |
|||
std::vector<int_fast64_t> integerValues; |
|||
std::vector<double> doubleValues; |
|||
}; |
|||
} |
|||
} |
|||
|
|||
#endif /* STORM_STORAGE_EXPRESSIONS_SIMPLEVALUATION_H_ */ |
@ -0,0 +1,15 @@ |
|||
#ifndef STORM_STORAGE_EXPRESSIONS_VALUATION_H_ |
|||
#define STORM_STORAGE_EXPRESSIONS_VALUATION_H_ |
|||
|
|||
namespace storm { |
|||
namespace expressions { |
|||
class Valuation { |
|||
public: |
|||
virtual bool getBooleanValue(std::string const& name) const = 0; |
|||
virtual int_fast64_t getIntegerValue(std::string const& name) const = 0; |
|||
virtual double getDoubleValue(std::string const& name) const = 0; |
|||
}; |
|||
} |
|||
} |
|||
|
|||
#endif /* STORM_STORAGE_EXPRESSIONS_VALUATION_H_ */ |
@ -0,0 +1,9 @@ |
|||
#include "gtest/gtest.h"
|
|||
|
|||
#include <map>
|
|||
|
|||
#include "src/storage/expressions/SimpleValuation.h"
|
|||
|
|||
TEST(Expression, SimpleValuationTest) { |
|||
ASSERT_NO_THROW(storm::expressions::SimpleValuation evaluation(1, 1, 1)); |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue