concepts.pdsketch.strips.strips_grounded_expression.GSSimpleBoolExpression#

class GSSimpleBoolExpression[source]#

Bases: GSBoolOutputExpression

A simple Boolean expression. Here, a simple Boolean expression is a conjunction or disjunction of propositions. Therefore, internally, we use a frozen set to store the propositions. This also accelerates the testing process.

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 propositions in this 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.

propositions

The propositions in the expression.

is_disjunction

Whether the expression is a disjunction.

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

Initialize the simple Boolean expression.

Parameters:
  • propositions (Sequence[str] | FrozenSet[str]) – the propositions in the expression.

  • is_disjunction (bool) – 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 propositions are true, and return all propositions as the forward diff.

  2. If the expression is a disjunction, the function will return True if any proposition is true, and return the first true proposition 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 propositions in this expression. Only the propositions in the given set will be kept. Note that this function will automatically handle cases where the filtered expression is a constant expression. The rules are:

1. If the expression is a conjunction, denote the set of propositions that will be filtered out as A, and the set of propositions that are True in the initial state as B:

1. If A is a not subset of B, then the filtered expression is a constant False expression (i.e., there are propositions that are not True in the initial state but will never be changed by actions).

2. Otherwise, if the remaining set of propositions is empty, then the filtered expression is a constant True expression. Otherwise, the filtered expression is a conjunction of the remaining propositions.

2. If the expression is a disjunction, denote the set of propositions that will be filtered out as A, and the set of propositions that are True in the initial state as B:

1. If A and B has non-empty intersection, then the filtered expression is a constant True expression (i.e., there are propositions that are True in the initial state and will never be changed by actions).

2. Otherwise, if the remaining set of propositions is empty, then the filtered expression is a constant False expression (i.e., all propositions are False in the initial state and will never be changed by actions). Otherwise, the filtered expression is a disjunction of the remaining propositions.

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.

property is_conjunction: bool#

Whether the expression is a conjunction.

is_disjunction: bool#

Whether the expression is a disjunction.

propositions: FrozenSet[str]#

The propositions in the expression.