concepts.dm.pdsketch.strips.strips_grounded_expression.GSComplexBoolExpression#

class GSComplexBoolExpression[source]#

Bases: GSBoolOutputExpression

A complex Boolean expression. Here, a complex Boolean expression is a conjunction or disjunction of Boolean sub-expressions. In most of the scenarios, you should directly call the constructor for this class. Instead, if you want to compose multiple Boolean expressions, you should use the function gs_compose_bool_expressions() instead.

Methods

compile()

Compile the expression into a function.

enable_forward_diff_ctx()

A context manager that enables the forward difference flag.

filter_propositions(propositions[, state])

Filter the given propositions from the expression.

forward(state)

Compute the expression on the given state.

iter_propositions()

Iterate over all propositions that are used in this expression.

set_forward_diff([value])

Set the forward difference flag.

Attributes

FORWARD_DIFF

A static variable that indicates whether we want to enable forward difference for expressions.

is_conjunction

Whether the expression is a conjunction.

expressions

The sub-expressions.

is_disjunction

Whether the expression is a disjunction.

__init__(expressions, is_disjunction=False)[source]#

Initialize the complex Boolean expression.

Parameters:
  • expressions (Sequence[GSBoolOutputExpression]) – the sub-expressions.

  • is_disjunction (bool | None) – whether the expression is a disjunction, default to False (a.k.a. conjunction).

__new__(**kwargs)#
compile()[source]#

Compile the expression into a function. When forward diff is enabled, the function will use the following strategy:

  1. If the expression is a conjunction, the function will return True if all sub-expressions are true, and return the union of propositions as the forward diff.

  2. If the expression is a disjunction, the function will return True if any sub-expression is true, and return the first true sub-expression as the forward diff.

Return type:

Callable[[SState], bool | GSBoolForwardDiffReturn]

static enable_forward_diff_ctx()#

A context manager that enables the forward difference flag. Example:

state = SState({'a', 'b'})
expr = GSSimpleBoolExpression({'a', 'b'})
compiled_function = expr.compile()
with GSBoolExpression.enable_forward_diff_ctx():
    rv = compiled_function(state)
    assert isinstance(rv, GSBoolForwardDiffReturn)
    assert rv.rv is True
    assert rv.propositions == {'a', 'b'}
filter_propositions(propositions, state=None)[source]#

Filter the given propositions from the expression. See the documentation of gstrips_compose_classifiers() for more details.

Parameters:
  • propositions (Set[str]) – the propositions that should be kept.

  • state (SState | None) – the initial state, default to None.

Returns:

the Boolean expression after filtering.

Return type:

GSBoolOutputExpression

forward(state)#

Compute the expression on the given state.

Parameters:

state (SState) – the state to compute the expression on.

Returns:

the return value of the expression.

Return type:

bool | GSBoolForwardDiffReturn

iter_propositions()[source]#

Iterate over all propositions that are used in this expression.

Return type:

Iterable[str]

static set_forward_diff(value=True)#

Set the forward difference flag. If the forward difference flag is set to True, the compiled function will return a tuple of (bool, Set[SProposition]) instead of a bool.

Parameters:

value (bool) – the value to set, default to True.

FORWARD_DIFF = False#

A static variable that indicates whether we want to enable forward difference for expressions.

expressions: Tuple[GSBoolOutputExpression]#

The sub-expressions.

property is_conjunction: bool#

Whether the expression is a conjunction.

is_disjunction: bool#

Whether the expression is a disjunction.