Browse Source

Started working on new easy-to-use expression classes.

Former-commit-id: 9ee1be5822
tempestpy_adaptions
dehnert 11 years ago
parent
commit
c8a8beca2a
  1. 2
      CMakeLists.txt
  2. 26
      src/storage/expressions/BaseExpression.h
  3. 13
      src/storage/expressions/Expression.cpp
  4. 42
      src/storage/expressions/Expression.h
  5. 29
      src/storage/expressions/SimpleValuation.cpp
  6. 40
      src/storage/expressions/SimpleValuation.h
  7. 15
      src/storage/expressions/Valuation.h
  8. 9
      test/functional/storage/ExpressionTest.cpp

2
CMakeLists.txt

@ -251,6 +251,7 @@ file(GLOB_RECURSE STORM_SETTINGS_FILES ${PROJECT_SOURCE_DIR}/src/settings/*.h ${
file(GLOB_RECURSE STORM_SOLVER_FILES ${PROJECT_SOURCE_DIR}/src/solver/*.h ${PROJECT_SOURCE_DIR}/src/solver/*.cpp)
file(GLOB STORM_STORAGE_FILES ${PROJECT_SOURCE_DIR}/src/storage/*.h ${PROJECT_SOURCE_DIR}/src/storage/*.cpp)
file(GLOB_RECURSE STORM_STORAGE_DD_FILES ${PROJECT_SOURCE_DIR}/src/storage/dd/*.h ${PROJECT_SOURCE_DIR}/src/storage/dd/*.cpp)
file(GLOB_RECURSE STORM_STORAGE_EXPRESSIONS_FILES ${PROJECT_SOURCE_DIR}/src/storage/expressions/*.h ${PROJECT_SOURCE_DIR}/src/storage/expressions/*.cpp)
file(GLOB_RECURSE STORM_UTILITY_FILES ${PROJECT_SOURCE_DIR}/src/utility/*.h ${PROJECT_SOURCE_DIR}/src/utility/*.cpp)
file(GLOB STORM_IR_FILES ${PROJECT_SOURCE_DIR}/src/ir/*.h ${PROJECT_SOURCE_DIR}/src/ir/*.cpp)
file(GLOB_RECURSE STORM_IR_EXPRESSIONS_FILES ${PROJECT_SOURCE_DIR}/src/ir/expressions/*.h ${PROJECT_SOURCE_DIR}/src/ir/expressions/*.cpp)
@ -284,6 +285,7 @@ source_group(settings FILES ${STORM_SETTINGS_FILES})
source_group(solver FILES ${STORM_SOLVER_FILES})
source_group(storage FILES ${STORM_STORAGE_FILES})
source_group(storage\\dd FILES ${STORM_STORAGE_DD_FILES})
source_group(storage\\expressions FILES ${STORM_STORAGE_EXPRESSIONS_FILES})
source_group(utility FILES ${STORM_UTILITY_FILES})
source_group(functional-test FILES ${STORM_FUNCTIONAL_TEST_FILES})
source_group(performance-test FILES ${STORM_PERFORMANCE_TEST_FILES})

26
src/storage/expressions/BaseExpression.h

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

13
src/storage/expressions/Expression.cpp

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

42
src/storage/expressions/Expression.h

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

29
src/storage/expressions/SimpleValuation.cpp

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

40
src/storage/expressions/SimpleValuation.h

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

15
src/storage/expressions/Valuation.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_ */

9
test/functional/storage/ExpressionTest.cpp

@ -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));
}
Loading…
Cancel
Save