Problem

class unified_planning.model.Problem(name: str | None = None, environment: Environment | None = None, *, initial_defaults: Dict[Type, int | float | Fraction | str | FNode | Object | bool] = {})[source]

Bases: AbstractProblem, UserTypesSetMixin, TimeModelMixin, FluentsSetMixin, ActionsSetMixin, ObjectsSetMixin, InitialStateMixin, MetricsMixin

Represents the classical planning problem, with Actions, Fluents, Objects and UserTypes.

The Actions can be DurativeActions when the Problem deals with time.

clone()[source]
has_name(name: str) bool[source]

Returns True if the given name is already in the Problem, False otherwise.

Parameters:

name – The target name to find in the Problem.

Returns:

True if the given name is already in the Problem, False otherwise.

normalize_plan(plan: Plan) Plan[source]

Normalizes the given Plan, that is potentially the result of another Problem, updating the Object references present in it with the ones of this Problem which are syntactically equal.

Parameters:

plan – The Plan that must be normalized.

Returns:

A Plan syntactically valid for this Problem.

get_static_fluents() Set[Fluent][source]

Returns the set of the static fluents.

Static fluents are those who can’t change their values because they never appear in the fluent field of an Effect, therefore there are no Actions in the Problem that can change their value.

get_unused_fluents() Set[Fluent][source]

Returns the set of fluents that are never used in the problem.

property timed_goals: Dict[TimeInterval, List[FNode]]

Returns all the timed goals in the Problem.

add_timed_goal(interval: Timing | TimeInterval, goal: FNode | Fluent | bool)[source]

Adds the timed goal to the Problem. A timed goal is a goal that must be satisfied in a given period of time.

Parameters:
  • interval – The interval of time in which the given goal must be True.

  • goal – The expression that must be evaluated to True in the given interval.

clear_timed_goals()[source]

Removes all the timed goals from the Problem.

property timed_effects: Dict[Timing, List[Effect]]

Returns all the timed effects in the Problem.

add_timed_effect(timing: Timing, fluent: FNode | Fluent, value: Timing | Timepoint | int | float | Fraction | FNode | Fluent | Parameter | Variable | bool | str | Object, condition: FNode | Fluent | Parameter | Variable | bool = True, forall: Iterable[Variable] = ())[source]

Adds the given timed effect to the Problem; a timed effect is an Effect applied at a fixed time.

Parameters:
  • timing – The exact time in which the given Effect is applied.

  • fluent – The fluent modified by the Effect.

  • value – The value assigned to the given fluent at the given time.

  • condition – The condition that must be evaluated to True in order for this Effect to be actually applied.

  • forall – The ‘Variables’ that are universally quantified in this effect; the default value is empty.

add_increase_effect(timing: Timing, fluent: FNode | Fluent, value: Timing | Timepoint | int | float | Fraction | FNode | Fluent | Parameter | Variable | bool | str | Object, condition: FNode | Fluent | Parameter | Variable | bool = True, forall: Iterable[Variable] = ())[source]

Adds the given timed increase effect to the Problem; a timed effect is an Effect applied at a fixed time.

Parameters:
  • timing – The exact time in which the given Effect is applied.

  • fluent – The fluent increased by the Effect.

  • value – The value of which the given fluent is increased at the given time.

  • condition – The condition that must be evaluated to True in order for this Effect to be actually applied.

  • forall – The ‘Variables’ that are universally quantified in this effect; the default value is empty.

add_decrease_effect(timing: Timing, fluent: FNode | Fluent, value: Timing | Timepoint | int | float | Fraction | FNode | Fluent | Parameter | Variable | bool | str | Object, condition: FNode | Fluent | Parameter | Variable | bool = True, forall: Iterable[Variable] = ())[source]

Adds the given timed decrease effect to the problem; a timed effect is an Effect applied at a fixed time.

Parameters:
  • timing – The exact time in which the given Effect is applied.

  • fluent – The fluent decreased by the Effect.

  • value – The value of which the given fluent is decrease at the given time.

  • condition – The condition that must be evaluated to True in order for this Effect to be actually applied.

  • forall – The ‘Variables’ that are universally quantified in this effect; the default value is empty.

clear_timed_effects()[source]

Removes all the timed effects from the Problem.

property goals: List[FNode]

Returns all the goals in the Problem.

add_goal(goal: FNode | Fluent | bool)[source]

Adds the given goal to the Problem; a goal is an expression that must be evaluated to True at the end of the execution of a Plan. If a Plan does not satisfy all the given goals, it is not valid.

Parameters:

goal – The expression added to the Problem goals.

clear_goals()[source]

Removes all the goals from the Problem.

property trajectory_constraints: List[FNode]

Returns the ‘trajectory_constraints’ in the ‘Problem’.

add_trajectory_constraint(constraint: FNode)[source]

Adds the given trajectory_constraint to the Problem; a trajectory_constraint is an expression defined as: Always, Sometime, At-Most-Once, Sometime-Before, Sometime-After or defined with universal quantifiers. Nesting of these temporal operators is forbidden.

Parameters:

trajectory_constraint – The expression added to the Problem.

clear_trajectory_constraints()[source]

Removes the trajectory_constraints.

property state_invariants: List[FNode]

Returns the List of state_invariants in the problem.

add_state_invariant(invariant: FNode | Fluent | Parameter | Variable | bool)[source]

Adds the given invariant to the problem’s state invariants. State invariants are added as Always trajectory constraints.

Parameters:

invariant – The invariant expression to add to this problem as a state invariant.

property kind: ProblemKind

Calculates and returns the problem kind of this planning problem. If the Problem is modified, this method must be called again in order to be reliable.

IMPORTANT NOTE: this property does a lot of computation, so it should be called as seldom as possible.

action(name: str) Action

Returns the action with the given name.

Parameters:

name – The name of the target action.

Returns:

The action in the problem with the given name.

property actions: List[Action]

Returns the list of the Actions in the Problem.

add_action(action: Action)

Adds the given action to the problem.

Parameters:

action – The action that must be added to the problem.

add_actions(actions: Iterable[Action])

Adds the given actions to the problem.

Parameters:

actions – The actions that must be added to the problem.

add_fluent(fluent_or_name: Fluent | str, typename: Type | None = None, *, default_initial_value: int | float | Fraction | str | FNode | Object | bool | None = None, **kwargs: Type) Fluent

Adds the given fluent to the problem.

If the first parameter is not a Fluent, the parameters will be passed to the Fluent constructor to create it.

Parameters:
  • fluent_or_nameFluent instance or name of the fluent to be constructed.

  • typename – If only the name of the fluent is given, this is the fluent’s type (passed to the Fluent constructor).

  • default_initial_value – If provided, defines the default value taken in initial state by a state variable of this fluent that has no explicit value.

  • kwargs – If only the name of the fluent is given, these are the fluent’s parameters (passed to the Fluent constructor).

Returns:

The fluent passed or constructed.

Example

>>> from unified_planning.shortcuts import *
>>> problem = Problem()
>>> location = UserType("Location")
>>> at_loc = Fluent("at_loc", BoolType(), l=location)  # creates a new fluent
>>> problem.add_fluent(at_loc)  # adds it to the problem
bool at_loc[l=Location]
>>> problem.add_fluent("connected", BoolType(), l1=location, l2=location)  # creates a new fluent and add it to the problem.
bool connected[l1=Location, l2=Location]
>>>
add_fluents(fluents: Iterable[Fluent])

Adds the given fluents to the problem.

Parameters:

fluents – The fluents that must be added to the problem.

add_object(obj_or_name: Object | str, typename: Type | None = None) Object

Add the given object to the problem, constructing it from the parameters if needed.

Parameters:
  • obj_or_name – Either an Object instance or a string containing the name of the object.

  • typename – If the first argument contains only the name of the object, this parameter should contain its type, to allow creating the object.

Returns:

The Object that was passed or constructed.

Examples

>>> from unified_planning.shortcuts import *
>>> problem = Problem()
>>> cup = UserType("Cup")
>>> o1 = Object("o1", cup)  # creates a new object o1
>>> problem.add_object(o1)  # adds it to the problem
o1
>>> o2 = problem.add_object("o2", cup)  # alternative syntax to create a new object and add it to the problem.
add_objects(objects: Iterable[Object])

Adds the given objects to the problem.

Parameters:

objects – The objects that must be added to the problem.

add_quality_metric(metric: PlanQualityMetric)

Adds the given quality metric to the Problem; a quality metric defines extra requirements that a Plan must satisfy in order to be valid.

Parameters:

metric – The quality metric that a Plan of this Problem must satisfy in order to be valid.

property all_objects: List[Object]

Returns the list containing all the objects in the problem.

clear_actions()

Removes all the Problem Actions.

clear_fluents()

Removes all the Fluent from the current Problem, together with their default.

clear_quality_metrics()

Removes all the quality metrics in the Problem.

property conditional_actions: List[Action]

Returns the conditional Actions.

IMPORTANT NOTE: this property does some computation, so it should be called as seldom as possible.

property discrete_time: bool

Returns True if the problem time is discrete, False if it is continuous.

property durative_actions: Iterator[DurativeAction]

Returns all the DurativeActions of the Problem.

IMPORTANT NOTE: this property does some computation, so it should be called as seldom as possible.

property environment: Environment

Returns the Problem Environment.

property epsilon: Fraction | None

it defines the minimum amount of time that can elapse between 2 temporal events. A temporal event can be, for example, the start of an action, the end of an action, an intermediate step of an action, a timed effect of the problem.

When None, it means that this minimum step is chosen by the Engine the Problem is given to.

Type:

This parameter has meaning only in temporal problems

property explicit_initial_values: Dict[FNode, FNode]

Returns the problem’s defined initial values; those are only the initial values set with the set_initial_value() method.

IMPORTANT NOTE: For all the initial values of the problem use initial_values.

fluent(name: str) Fluent

Returns the fluent with the given name.

Parameters:

name – The name of the target fluent:

Returns:

The fluent with the given name.

property fluents: List[Fluent]

Returns the fluents currently in the problem.

property fluents_defaults: Dict[Fluent, FNode]

Returns the problem’s fluents defaults.

has_action(name: str) bool

Returns True if the problem has the action with the given name, False otherwise.

Parameters:

name – The name of the target action.

Returns:

True if the problem has an action with the given name, False otherwise.

has_fluent(name: str) bool

Returns True if the fluent with the given name is in the problem, False otherwise.

Parameters:

name – The name of the target fluent.

Returns:

True if the fluent with the given name is in the problem, False otherwise.

has_object(name: str) bool

Returns True if the object with the given name is in the problem, False otherwise.

Parameters:

name – The name of the target object in the problem.

Returns:

True if an object with the given name is in the problem, False otherwise.

has_type(name: str) bool

Returns True if the type with the given name is defined in the problem, False, otherwise.

Parameters:

name – The target name for the type.

Returns:

True if a type with the given name is in the problem, False otherwise.

property initial_defaults: Dict[Type, FNode]

Returns the problem’s fluents defaults for each type.

initial_value(fluent: FNode | Fluent) FNode

Retrieves the initial value assigned to the given fluent.

Parameters:

fluent – The target fluent of which the value in the initial state must be retrieved.

Returns:

The value expression assigned to the given fluent in the initial state.

property initial_values: Dict[FNode, FNode]

Gets the initial value of all the grounded fluents present in the Problem.

IMPORTANT NOTE: this property does a lot of computation, so it should be called as seldom as possible.

property instantaneous_actions: Iterator[InstantaneousAction]

Returns all the InstantaneousActions of the Problem.

IMPORTANT NOTE: this property does some computation, so it should be called as seldom as possible.

property name: str | None

Returns the Problem name.

object(name: str) Object

Returns the object with the given name.

Parameters:

name – The name of the target object in the problem.

objects(typename: Type) Iterator[Object]

Returns the objects compatible with the given Type: this includes the given type and its heirs.

Parameters:

typename – The target type of the objects that are retrieved.

Returns:

A generator of all the objects in the problem that are compatible with the given type.

property quality_metrics: List[PlanQualityMetric]

Returns all the quality metrics in the Problem.

property self_overlapping: bool

The self_overlapping flag determines if 2 (or more) different instances of the same action grounded with the same parameters can be running at the same time.

property sensing_actions: Iterator[SensingAction]

Returs all the sensing actions of the problem.

IMPORTANT NOTE: this property does some computation, so it should be called as seldom as possible.

set_initial_value(fluent: FNode | Fluent, value: int | float | Fraction | str | FNode | Fluent | Object | bool)

Sets the initial value for the given Fluent. The given Fluent must be grounded, therefore if it’s arity is > 0, the fluent parameter must be an FNode and the method is_fluent_exp() must return True.

Parameters:
  • fluent – The grounded Fluent of which the initial value must be set.

  • value – The value assigned in the initial state to the given fluent.

property unconditional_actions: List[Action]

Returns the unconditional Actions.

IMPORTANT NOTE: this property does some computation, so it should be called as seldom as possible.

user_type(name: str) Type

Returns the user type in the problem with the given name.

Parameters:

name – The target name for the type.

Returns:

The type in the problem with the given name.

property user_types: List[Type]

Returns the list of all the user types in the problem.

property user_types_hierarchy: Dict[Type | None, List[Type]]

Returns a Dict where every key represents an Optional Type and the value associated to the key is the List of the direct sons of the Optional Type.

All the user types corresponding to the ‘None’ key are fatherless.