concepts.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.
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.
Iterate over all propositions that are used in this expression.
set_forward_diff
([value])Set the forward difference flag.
Attributes
A static variable that indicates whether we want to enable forward difference for expressions.
Whether the expression is a conjunction.
The sub-expressions.
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:
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.
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:
- 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:
- Returns:
the Boolean expression after filtering.
- Return type:
- 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:
- 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.