Skip to content

Commit

Permalink
added concrete conditions and effects to python api
Browse files Browse the repository at this point in the history
  • Loading branch information
drexlerd committed Mar 1, 2024
1 parent da85723 commit 148af1c
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 4 deletions.
6 changes: 5 additions & 1 deletion api/python/src/dlplan/policy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
from _dlplan import NamedBoolean, NamedNumerical, NamedConcept, NamedRole, \
BaseCondition, BaseEffect, Rule, Policy, PolicyFactory, \
PolicyMinimizer
PolicyMinimizer, \
PositiveBooleanCondition, NegativeBooleanCondition, \
GreaterNumericalCondition, EqualNumericalCondition, \
PositiveBooleanEffect, NegativeBooleanEffect, UnchangedBooleanEffect, \
DecrementNumericalEffect, IncrementNumericalEffect, UnchangedNumericalEffect
40 changes: 40 additions & 0 deletions api/python/src/dlplan/policy/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,22 @@ class BaseCondition:
def get_index(self) -> int: ...


class PositiveBooleanCondition(BaseCondition):
def get_named_element(self) -> NamedBoolean: ...


class NegativeBooleanCondition(BaseCondition):
def get_named_element(self) -> NamedBoolean: ...


class GreaterNumericalCondition(BaseCondition):
def get_named_element(self) -> NamedNumerical: ...


class EqualNumericalCondition(BaseCondition):
def get_named_element(self) -> NamedNumerical: ...


class BaseEffect:
def __str__(self) -> str: ...
@overload
Expand All @@ -46,6 +62,30 @@ class BaseEffect:
def get_index(self) -> int: ...


class PositiveBooleanEffect(BaseEffect):
def get_named_element(self) -> NamedBoolean: ...


class NegativeBooleanEffect(BaseEffect):
def get_named_element(self) -> NamedBoolean: ...


class UnchangedBooleanEffect(BaseEffect):
def get_named_element(self) -> NamedBoolean: ...


class DecrementNumericalEffect(BaseEffect):
def get_named_element(self) -> NamedNumerical: ...


class IncrementNumericalEffect(BaseEffect):
def get_named_element(self) -> NamedNumerical: ...


class UnchangedNumericalEffect(BaseEffect):
def get_named_element(self) -> NamedNumerical: ...


class Rule:
def __str__(self) -> str: ...
@overload
Expand Down
43 changes: 42 additions & 1 deletion api/python/src/policy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@

#include "../../../include/dlplan/core.h"
#include "../../../include/dlplan/policy.h"

#include "../../../include/dlplan/policy/condition.h"
#include "../../../include/dlplan/policy/effect.h"

namespace py = pybind11;

Expand Down Expand Up @@ -46,13 +47,53 @@ void init_policy(py::module_ &m_policy) {
.def("get_index", &policy::BaseCondition::get_index)
;

py::class_<policy::PositiveBooleanCondition, policy::BaseCondition, std::shared_ptr<policy::PositiveBooleanCondition>>(m_policy, "PositiveBooleanCondition")
.def("get_named_element", &policy::PositiveBooleanCondition::get_named_element)
;

py::class_<policy::NegativeBooleanCondition, policy::BaseCondition, std::shared_ptr<policy::NegativeBooleanCondition>>(m_policy, "NegativeBooleanCondition")
.def("get_named_element", &policy::NegativeBooleanCondition::get_named_element)
;

py::class_<policy::GreaterNumericalCondition, policy::BaseCondition, std::shared_ptr<policy::GreaterNumericalCondition>>(m_policy, "GreaterNumericalCondition")
.def("get_named_element", &policy::GreaterNumericalCondition::get_named_element)
;

py::class_<policy::EqualNumericalCondition, policy::BaseCondition, std::shared_ptr<policy::EqualNumericalCondition>>(m_policy, "EqualNumericalCondition")
.def("get_named_element", &policy::EqualNumericalCondition::get_named_element)
;

py::class_<policy::BaseEffect, std::shared_ptr<policy::BaseEffect>>(m_policy, "BaseEffect")
.def("__str__", py::overload_cast<>(&policy::BaseEffect::str, py::const_))
.def("evaluate", py::overload_cast<const core::State&, const core::State&>(&policy::BaseEffect::evaluate, py::const_))
.def("evaluate", py::overload_cast<const core::State&, const core::State&, core::DenotationsCaches&>(&policy::BaseEffect::evaluate, py::const_))
.def("get_index", &policy::BaseEffect::get_index)
;

py::class_<policy::PositiveBooleanEffect, policy::BaseEffect, std::shared_ptr<policy::PositiveBooleanEffect>>(m_policy, "PositiveBooleanEffect")
.def("get_named_element", &policy::PositiveBooleanEffect::get_named_element)
;

py::class_<policy::NegativeBooleanEffect, policy::BaseEffect, std::shared_ptr<policy::NegativeBooleanEffect>>(m_policy, "NegativeBooleanEffect")
.def("get_named_element", &policy::NegativeBooleanEffect::get_named_element)
;

py::class_<policy::UnchangedBooleanEffect, policy::BaseEffect, std::shared_ptr<policy::UnchangedBooleanEffect>>(m_policy, "UnchangedBooleanEffect")
.def("get_named_element", &policy::UnchangedBooleanEffect::get_named_element)
;

py::class_<policy::DecrementNumericalEffect, policy::BaseEffect, std::shared_ptr<policy::DecrementNumericalEffect>>(m_policy, "DecrementNumericalEffect")
.def("get_named_element", &policy::DecrementNumericalEffect::get_named_element)
;

py::class_<policy::IncrementNumericalEffect, policy::BaseEffect, std::shared_ptr<policy::IncrementNumericalEffect>>(m_policy, "IncrementNumericalEffect")
.def("get_named_element", &policy::IncrementNumericalEffect::get_named_element)
;

py::class_<policy::UnchangedNumericalEffect, policy::BaseEffect, std::shared_ptr<policy::UnchangedNumericalEffect>>(m_policy, "UnchangedNumericalEffect")
.def("get_named_element", &policy::UnchangedNumericalEffect::get_named_element)
;

py::class_<policy::Rule, std::shared_ptr<policy::Rule>>(m_policy, "Rule")
.def("__str__", py::overload_cast<>(&policy::Rule::str, py::const_))
.def("evaluate_conditions", py::overload_cast<const core::State&>(&policy::Rule::evaluate_conditions, py::const_))
Expand Down
2 changes: 1 addition & 1 deletion examples/policy/policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from dlplan.core import VocabularyInfo, InstanceInfo, State, SyntacticElementFactory, \
DenotationsCaches
from dlplan.policy import PolicyFactory
from dlplan.policy import PolicyFactory, PositiveBooleanEffect, DecrementNumericalEffect


def construct_vocabulary_info():
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from setuptools import setup, find_packages, Extension
from setuptools.command.build_ext import build_ext

__version__ = "0.3.13"
__version__ = "0.3.14"
HERE = Path(__file__).resolve().parent


Expand Down

0 comments on commit 148af1c

Please sign in to comment.