Matthias Volk
8 years ago
11 changed files with 90 additions and 49 deletions
-
1CMakeLists.txt
-
2lib/stormpy/expressions/__init__.py
-
3setup.py
-
8src/logic/formulae.cpp
-
21src/mod_expressions.cpp
-
2src/mod_storage.cpp
-
30src/storage/expressions.cpp
-
8src/storage/expressions.h
-
10tests/expressions/test_expressions.py
-
20tests/logic/test_formulas.py
-
34tests/storage/test_expressions.py
@ -1,2 +0,0 @@ |
|||
from . import expressions |
|||
from .expressions import * |
@ -1,21 +0,0 @@ |
|||
#include "common.h"
|
|||
#include "storm/storage/expressions/ExpressionManager.h"
|
|||
|
|||
PYBIND11_MODULE(expressions, m) { |
|||
m.doc() = "Storm expressions"; |
|||
|
|||
#ifdef STORMPY_DISABLE_SIGNATURE_DOC
|
|||
py::options options; |
|||
options.disable_function_signatures(); |
|||
#endif
|
|||
|
|||
py::class_<std::shared_ptr<storm::expressions::ExpressionManager>>(m, "ExpressionManager", "Manages variables for expressions"); |
|||
|
|||
py::class_<storm::expressions::Expression>(m, "Expression", "Holds an expression") |
|||
.def("__str__", &storm::expressions::Expression::toString) |
|||
.def_property_readonly("contains_variables", &storm::expressions::Expression::containsVariables) |
|||
.def_property_readonly("has_boolean_type", &storm::expressions::Expression::hasBooleanType) |
|||
.def_property_readonly("has_integer_type", &storm::expressions::Expression::hasIntegerType) |
|||
.def_property_readonly("has_rational_type", &storm::expressions::Expression::hasRationalType) |
|||
; |
|||
} |
@ -0,0 +1,30 @@ |
|||
#include "expressions.h"
|
|||
#include "src/helpers.h"
|
|||
|
|||
#include "storm/storage/expressions/ExpressionManager.h"
|
|||
#include "storm/storage/expressions/Expression.h"
|
|||
|
|||
//Define python bindings
|
|||
void define_expressions(py::module& m) { |
|||
|
|||
// ExpressionManager
|
|||
py::class_<storm::expressions::ExpressionManager, std::shared_ptr<storm::expressions::ExpressionManager>>(m, "ExpressionManager", "Manages variables for expressions") |
|||
.def(py::init(), "Constructor") |
|||
.def("create_boolean", &storm::expressions::ExpressionManager::boolean, py::arg("boolean"), "Create expression from boolean") |
|||
.def("create_integer", &storm::expressions::ExpressionManager::integer, py::arg("integer"), "Create expression from integer number") |
|||
.def("create_rational", [](storm::expressions::ExpressionManager const& manager, storm::RationalNumber number) { |
|||
return manager.rational(number); |
|||
}, py::arg("rational"), "Create expression from rational number") |
|||
; |
|||
|
|||
// Expression
|
|||
py::class_<storm::expressions::Expression, std::shared_ptr<storm::expressions::Expression>>(m, "Expression", "Holds an expression") |
|||
.def("contains_variables", &storm::expressions::Expression::containsVariables, "Check if the expression contains variables.") |
|||
.def("is_literal", &storm::expressions::Expression::isLiteral, "Check if the expression is a literal") |
|||
.def("has_boolean_type", &storm::expressions::Expression::hasBooleanType, "Check if the expression is a boolean") |
|||
.def("has_integer_type", &storm::expressions::Expression::hasIntegerType, "Check if the expression is an integer") |
|||
.def("has_rational_type", &storm::expressions::Expression::hasRationalType, "Check if the expression is a rational") |
|||
.def("__str__", &streamToString<storm::expressions::Expression>) |
|||
; |
|||
|
|||
} |
@ -0,0 +1,8 @@ |
|||
#ifndef PYTHON_STORAGE_EXPRESSIONS_H_ |
|||
#define PYTHON_STORAGE_EXPRESSIONS_H_ |
|||
|
|||
#include "common.h" |
|||
|
|||
void define_expressions(py::module& m); |
|||
|
|||
#endif /* PYTHON_STORAGE_EXPRESSIONS_H_ */ |
@ -1,10 +0,0 @@ |
|||
import stormpy |
|||
from stormpy.expressions import expressions |
|||
|
|||
|
|||
class TestExpressions: |
|||
def test_expression_manager(self): |
|||
manager = expressions.ExpressionManager |
|||
|
|||
def test_expression(self): |
|||
expression = expressions.Expression |
@ -0,0 +1,34 @@ |
|||
import stormpy |
|||
|
|||
|
|||
class TestExpressions: |
|||
def test_expression_manager(self): |
|||
manager = stormpy.ExpressionManager() |
|||
|
|||
def test_boolean_expression(self): |
|||
manager = stormpy.ExpressionManager() |
|||
expression = manager.create_boolean(True) |
|||
assert expression.is_literal() |
|||
assert not expression.contains_variables() |
|||
assert expression.has_boolean_type() |
|||
assert not expression.has_integer_type() |
|||
assert not expression.has_rational_type() |
|||
|
|||
def test_integer_expression(self): |
|||
manager = stormpy.ExpressionManager() |
|||
expression = manager.create_integer(2) |
|||
assert expression.is_literal() |
|||
assert not expression.contains_variables() |
|||
assert not expression.has_boolean_type() |
|||
assert expression.has_integer_type() |
|||
assert not expression.has_rational_type() |
|||
|
|||
def test_rational_expression(self): |
|||
import pycarl.gmp |
|||
manager = stormpy.ExpressionManager() |
|||
expression = manager.create_rational(pycarl.gmp.Rational(0.2)) |
|||
assert expression.is_literal() |
|||
assert not expression.contains_variables() |
|||
assert not expression.has_boolean_type() |
|||
assert not expression.has_integer_type() |
|||
assert expression.has_rational_type() |
Write
Preview
Loading…
Cancel
Save
Reference in new issue