Method

class unified_planning.model.htn.Method(_name: str, _parameters: OrderedDict[str, Type] | List[Parameter] | None = None, _env: Environment | None = None, **kwargs: Type)[source]

Bases: AbstractTaskNetwork

HTN Method: encoding of a procedure for achieving a high-level task.

property name: str

Returns the action name.

property achieved_task: ParameterizedTask

Returns the task that this method achieves.

set_task(task: Task | ParameterizedTask, *arguments: Parameter)[source]

Defines the task that is method achieves.

It expects a Task and its arguments, either bundle in a ParameterizedTask instance of passed separetly. It is assumed that each parameter of the achieved task is a parameter of the method.

# Examples >>> from unified_planning.shortcuts import * >>> from unified_planning.model.htn import * >>> Location = UserType(“Location”) >>> go = Task(“go”, target=Location) >>> m1 = Method(“m-go1”, target=Location) >>> task_achieved = ParameterizedTask(go, m1.parameter(“target”)) >>> m1.set_task(task_achieved) >>> m2 = Method(“m-go2”, source=Location, target=Location) >>> m2.set_task(go, m2.parameter(“target”)) >>> m3 = Method(“m-go3”, source=Location, target=Location) >>> m3.set_task(go) # Infer the parameters of the go task from the parameters of m3 with the same name

property parameters: List[Parameter]

Returns the list of the method’s parameters.

parameter(name: str) Parameter[source]

Returns the parameter of the Method with the given name.

Example

>>> from unified_planning.shortcuts import *
>>> from unified_planning.model.htn import *
>>> location_type = UserType("Location")
>>> robot_type = UserType("Robot")
>>> goto = Method("goto", robot=robot_type, target=location_type)
>>> goto.parameter("robot")  # return the "robot" parameter of the method, with type "Robot"
Robot robot
>>> goto.parameter("target")
Location target

If a parameter’s name (1) does not conflict with an existing attribute of Method and (2) does not start with ‘_’ it can also be accessed as if it was an attribute of the method. For instance:

>>> goto.target
Location target
Parameters:

name – The name of the target parameter.

Returns:

The parameter of the Method with the given name.

property preconditions: List[FNode]

Returns the list of the method’s preconditions.

add_precondition(precondition: Timing | Timepoint | int | float | Fraction | FNode | Fluent | Parameter | Variable | bool | str | Object)[source]

Adds the given method precondition.

add_constraint(constraint: up.model.timing.Timing | up.model.timing.Timepoint | int | float | Fraction | up.model.fnode.FNode | up.model.fluent.Fluent | up.model.parameter.Parameter | up.model.variable.Variable | bool | str | up.model.object.Object)
add_subtask(task: Subtask | Action | Task, *args: up.model.timing.Timing | up.model.timing.Timepoint | int | float | Fraction | up.model.fnode.FNode | up.model.fluent.Fluent | up.model.parameter.Parameter | up.model.variable.Variable | bool | str | up.model.object.Object, ident: str | None = None) Subtask

Adds a subtask, with no particular ordering relative to the existing ones.

property constraints: List[FNode]

Returns the list of the method’s constraints. Note that these may contain both ordering and non-ordering constraints.

get_subtask(ident: str) Subtask

Returns the subtask with the given identifier.

non_temporal_constraints() List[FNode]

All constraints that do not involve any temporal aspect

partial_order() List[Tuple[str, str]] | None

If the temporal constraints define a partial order, returns a list of precedences between the network’ subtasks. Returns None, if the temporal constraints cannot be fully expressed by a set of precedence constraints. This can be the case if, e.g., the constraint contains simple temporal constraints, implying a given delay between two subtasks.

set_ordered(*subtasks: Subtask)

Imposes a sequential order between the given subtasks.

set_strictly_before(lhs: Subtask | Timepoint | Timing, rhs: Subtask | Timepoint | Timing)
property subtasks: List[Subtask]

Returns the list of the subtasks.

temporal_constraints() List[FNode]

All constraints that impose an order between tasks or explicitly refer to a timepoint.

total_order() List[str] | None

If the temporal constraints define a total order, returns the ordered list of task identifiers. Returns None, if the temporal constraints cannot be exactly expressed by a total order.