ExpressionManager

class unified_planning.model.ExpressionManager(environment: Environment)[source]

Bases: object

ExpressionManager is responsible for the creation of all expressions.

auto_promote(*args: Timing | Timepoint | int | float | Fraction | FNode | Fluent | Parameter | Variable | bool | str | Object | Iterable[Timing | Timepoint | int | float | Fraction | FNode | Fluent | Parameter | Variable | bool | str | Object]) List[FNode][source]

Method that takes an iterable of expressions and returns the list of these expressions casted to FNode.

Parameters:

args – The iterable of expression that must be promoted to FNode.

Returns:

The resulting list of FNode.

create_node(node_type: OperatorKind, args: Tuple[FNode, ...], payload: Fluent | Object | Parameter | Variable | Timing | str | bool | int | Fraction | Tuple[Variable, ...] | None = None) FNode[source]

Creates the unified_planning expressions if it hasn’t been created yet in the environment. Otherwise returns the existing one.

Parameters:
  • node_type – The OperationKind referring to this expression (like a PLUS, MINUS, FLUENT_EXP, etc.).

  • args – The direct sons in this expression tree; a tuple of expressions.

  • payload – In some OperationKind contains the information about the expression; for an INT_EXP contains the integer, for a FLUENT_EXP the fluent etc.

Returns:

The created expression.

And(*args: FNode | Fluent | Parameter | Variable | bool | Iterable[FNode | Fluent | Parameter | Variable | bool]) FNode[source]
Returns a conjunction of terms.
This function has polymorphic n-arguments:
  • And(a,b,c)

  • And([a,b,c])

Restriction: Arguments must be boolean.
Parameters:

*args – Either an Iterable of boolean expressions, like [a, b, c], or an unpacked version of it, like a, b, c.

Returns:

The AND expression created.

Or(*args: FNode | Fluent | Parameter | Variable | bool | Iterable[FNode | Fluent | Parameter | Variable | bool]) FNode[source]
Returns an disjunction of terms.
This function has polymorphic n-arguments:
  • Or(a,b,c)

  • Or([a,b,c])

Restriction: Arguments must be boolean
Parameters:

*args – Either an Iterable of boolean expressions, like [a, b, c], or an unpacked version of it, like a, b, c.

Returns:

The OR expression created.

XOr(*args: FNode | Fluent | Parameter | Variable | bool | Iterable[FNode | Fluent | Parameter | Variable | bool]) FNode[source]
Returns an exclusive disjunction of terms in CNF form.
This function has polimorphic n-arguments:
  • XOr(a,b,c)

  • XOr([a,b,c])

Restriction: Arguments must be boolean
Parameters:

*args – Either an Iterable of boolean expressions, like [a, b, c], or an unpacked version of it, like a, b, c.

Returns:

The exclusive disjunction in CNF form.

Not(expression: FNode | Fluent | Parameter | Variable | bool) FNode[source]
Creates an expression of the form:

not expression

Restriction: expression must be of boolean type

Parameters:

expression – The boolean expression of which the negation must be created.

Returns:

The created Not expression.

Implies(left: FNode | Fluent | Parameter | Variable | bool, right: FNode | Fluent | Parameter | Variable | bool) FNode[source]
Creates an expression of the form:

left -> right

Restriction: Left and Right must be of boolean type

Parameters:
  • left – The boolean expression acting as the premise of the Implies.

  • right – The boolean expression acting as the implied part of the Implies.

Returns:

The created Implication.

Iff(left: FNode | Fluent | Parameter | Variable | bool, right: FNode | Fluent | Parameter | Variable | bool) FNode[source]
Creates an expression of the form:

left <-> right

Semantically, The expression is True only if left and right have the same value. Restriction: Left and Right must be of boolean type

Parameters:
  • left – The left member of the Iff expression.

  • right – The right member of the Iff expression.

Returns:

The created Iff expression.

Exists(expression: FNode | Fluent | Parameter | Variable | bool, *vars: Variable) FNode[source]
Creates an expression of the form:

Exists (var[0]... var[n]) | expression

Restriction: expression must be of boolean type and vars must be of Variable type

Parameters:
  • expression – The main expression of the existential. The expression should contain the given variables.

  • *vars – All the Variables appearing in the existential expression.

Returns:

The created Existential expression.

Forall(expression: FNode | Fluent | Parameter | Variable | bool, *vars: Variable) FNode[source]
Creates an expression of the form:

Forall (var[0]... var[n]) | expression

Restriction: expression must be of boolean type and vars must be of Variable type

Parameters:
  • expression – The main expression of the universal quantifier. The expression should contain the given variables.

  • *vars – All the Variables appearing in the universal expression.

Returns:

The created Forall expression.

Always(expression: FNode | Fluent | Parameter | Variable | bool) FNode[source]
Creates an expression of the form:

Always(a)

Restriction: expression must be of boolean type and with only one arg.

Parameters:

expression – The boolean expression of the trajectory constraints.

Returns:

The created Always expression.

Sometime(expression: FNode | Fluent | Parameter | Variable | bool) FNode[source]
Creates an expression of the form:

Sometime(a)

Restriction: expression must be of boolean type and with only one arg.

Parameters:

expression – The boolean expression of the trajectory constraints.

Returns:

The created Sometime expression.

AtMostOnce(expression: FNode | Fluent | Parameter | Variable | bool) FNode[source]
Creates an expression of the form:

At-Most-Once(a, b)

Restriction: expression must be of boolean type and with only two arg.

Parameters:

expression – The boolean expression of the trajectory constraints.

Returns:

The created At-Most-Once(a, b) expression.

SometimeBefore(phi: FNode | Fluent | Parameter | Variable | bool, psi: FNode | Fluent | Parameter | Variable | bool) FNode[source]
Creates an expression of the form:

Sometime-Before(a, b)

Restriction: expression must be of boolean type and with only one args

Parameters:

expression – The boolean expression of the trajectory constraints.

Returns:

The created Sometime expression.

SometimeAfter(phi: FNode | Fluent | Parameter | Variable | bool, psi: FNode | Fluent | Parameter | Variable | bool) FNode[source]
Creates an expression of the form:

Sometime-After(a, b)

Restriction: expression must be of boolean type and with only two arg.

Parameters:

expression – The boolean expression of the trajectory constraints.

Returns:

The created Sometime-After(a, b) expression.

FluentExp(fluent: Fluent, params: Sequence[Timing | Timepoint | int | float | Fraction | FNode | Fluent | Parameter | Variable | bool | str | Object] = ()) FNode[source]
Creates an expression for the given fluent and parameters.
Restriction: parameters type must be compatible with the Fluent :func:signature <unified_planning.model.Fluent.signature>
Parameters:
  • fluent – The Fluent that will be set as the payload of this expression.

  • params – The Sequence of expressions acting as parameters for this Fluent; mainly the parameters will be :class:Objects <unified_planning.model.Object> (when the FluentExp is grounded) or :func:Action parameters <unified_planning.model.Action.parameters> (when the FluentExp is lifted).

Returns:

The created Fluent Expression.

Dot(agent: Agent | str, fluent_exp: FNode | Fluent) FNode[source]

Creates an expression for the given agent and fluent_exp. Restriction: agent must be of agent type or the name of an agent and fluent_exp must be of fluentExp type

Parameters:
  • agent – The Agent that will be set as the payload of this expression.

  • fluent_exp – The Fluent_exp that will be set as the args of this expression.

Returns:

The created Dot Expression.

ParameterExp(param: Parameter) FNode[source]

Returns an expression for the given Action parameter.

Parameters:

param – The Parameter that must be promoted to FNode.

Returns:

The FNode containing the given param as his payload.

VariableExp(var: Variable) FNode[source]

Returns an expression for the given Variable.

Parameters:

var – The Variable that must be promoted to FNode.

Returns:

The FNode containing the given variable as his payload.

ObjectExp(obj: Object) FNode[source]

Returns an expression for the given object.

Parameters:

obj – The Object that must be promoted to FNode.

Returns:

The FNode containing the given object as his payload.

TimingExp(timing: Timing) FNode[source]

Returns an expression for the given Timing.

Parameters:

timing – The Timing that must be promoted to FNode.

Returns:

The FNode containing the given timing as his payload.

TRUE() FNode[source]

Return the boolean constant True.

FALSE() FNode[source]

Return the boolean constant False.

Bool(value: bool) FNode[source]

Return a boolean constant.

Parameters:

value – The boolean value that must be promoted to FNode.

Returns:

The FNode containing the given value as his payload.

Int(value: int) FNode[source]

Return an int constant.

Parameters:

value – The integer that must be promoted to FNode.

Returns:

The FNode containing the given integer as his payload.

Real(value: Fraction) FNode[source]

Return a real constant.

Parameters:

value – The Fraction that must be promoted to FNode.

Returns:

The FNode containing the given value as his payload.

Plus(*args: Timing | Timepoint | int | float | Fraction | FNode | Fluent | Parameter | Variable | bool | str | Object | Iterable[Timing | Timepoint | int | float | Fraction | FNode | Fluent | Parameter | Variable | bool | str | Object]) FNode[source]
Creates an expression of the form:

args[0] + ... + args[n]

Parameters:

*args – Either an Iterable of expressions, like [a, b, 3], or an unpacked version of it, like a, b, 3.

Returns:

The PLUS expression created. (like a + b + 3)

Minus(left: Timing | Timepoint | int | float | Fraction | FNode | Fluent | Parameter | Variable | bool | str | Object, right: Timing | Timepoint | int | float | Fraction | FNode | Fluent | Parameter | Variable | bool | str | Object) FNode[source]

Creates an expression of the form: left - right.

Parameters:
  • left – The Minus minuend.

  • right – The Minus subtrahend.

Returns:

The created Minus expression.

Times(*args: Timing | Timepoint | int | float | Fraction | FNode | Fluent | Parameter | Variable | bool | str | Object | Iterable[Timing | Timepoint | int | float | Fraction | FNode | Fluent | Parameter | Variable | bool | str | Object]) FNode[source]
Creates an expression of the form:

args[0] * ... * args[n]

Parameters:

*args – Either an Iterable of expressions, like [a, b, 3], or an unpacked version of it, like a, b, 3.

Returns:

The TIMES expression created. (like a * b * 3)

Div(left: Timing | Timepoint | int | float | Fraction | FNode | Fluent | Parameter | Variable | bool | str | Object, right: Timing | Timepoint | int | float | Fraction | FNode | Fluent | Parameter | Variable | bool | str | Object) FNode[source]
Creates an expression of the form:

left / right

Parameters:
  • left – The Div dividend.

  • right – The Div divisor.

Returns:

The created DIV expression.

LE(left: Timing | Timepoint | int | float | Fraction | FNode | Fluent | Parameter | Variable | bool | str | Object, right: Timing | Timepoint | int | float | Fraction | FNode | Fluent | Parameter | Variable | bool | str | Object) FNode[source]
Creates an expression of the form:

left <= right.

Parameters:
  • left – The left side of the <=.

  • right – The right side of the <=.

Returns:

The created LE expression.

GE(left: Timing | Timepoint | int | float | Fraction | FNode | Fluent | Parameter | Variable | bool | str | Object, right: Timing | Timepoint | int | float | Fraction | FNode | Fluent | Parameter | Variable | bool | str | Object) FNode[source]
Creates an expression of the form:

left >= right.

Parameters:
  • left – The left side of the >=.

  • right – The right side of the >=.

Returns:

The created GE expression.

LT(left: Timing | Timepoint | int | float | Fraction | FNode | Fluent | Parameter | Variable | bool | str | Object, right: Timing | Timepoint | int | float | Fraction | FNode | Fluent | Parameter | Variable | bool | str | Object) FNode[source]
Creates an expression of the form:

left < right.

Parameters:
  • left – The left side of the <.

  • right – The right side of the <.

Returns:

The created LT expression.

GT(left: Timing | Timepoint | int | float | Fraction | FNode | Fluent | Parameter | Variable | bool | str | Object, right: Timing | Timepoint | int | float | Fraction | FNode | Fluent | Parameter | Variable | bool | str | Object) FNode[source]
Creates an expression of the form:

left > right.

Parameters:
  • left – The left side of the >.

  • right – The right side of the >.

Returns:

The created GT expression.

Equals(left: Timing | Timepoint | int | float | Fraction | FNode | Fluent | Parameter | Variable | bool | str | Object, right: Timing | Timepoint | int | float | Fraction | FNode | Fluent | Parameter | Variable | bool | str | Object) FNode[source]
Creates an expression of the form:

left == right.

NOTE: Is not valid for boolean expression, for those use Iff.

Parameters:
  • left – The left side of the ==.

  • right – The right side of the ==.

Returns:

The created Equals expression.