MultiAgentProblem

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

Bases: AbstractProblem, UserTypesSetMixin, ObjectsSetMixin, AgentsSetMixin

Represents the multi-agent planning problem, with Agent, with MAEnvironment, Fluents, Objects and UserTypes.

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

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

Parameters:

name – The target name to find in the MultiAgentProblem.

Returns:

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

has_name_not_in_agents(name: str) bool[source]

Returns True if the given name is already in the MultiAgentProblem, False otherwise; this method does not check in the problem’s agents

Parameters:

name – The target name to find in the MultiAgentProblem without checking Agents.

Returns:

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

property ma_environment: MAEnvironment

Returns this MultiAgentProblem MAEnvironment.

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

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.

initial_value(fluent: FNode | Fluent) FNode[source]

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 MultiAgentProblem.

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

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.

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

Adds the given goal to the MultiAgentProblem; 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 MultiAgentProblem goals.

add_goals(goals: Iterable[FNode | Fluent | bool])[source]

Adds the given goal to the MultiAgentProblem.

Parameters:

goals – The goals that must be added to the MultiAgentProblem.

property goals: List[FNode]

Returns all the goals in the MultiAgentProblem.

clear_goals()[source]

Removes all the goals from the MultiAgentProblem.

clear_agents()[source]

Removes all the goals from the MultiAgentProblem.

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.

normalize_plan(plan: Plan) Plan[source]

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

Parameters:

plan – The Plan that must be normalized.

Returns:

A Plan syntactically valid for this Problem.

add_agent(agent: Agent)

This method adds an Agent

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.

agent(name: str) Agent

Returns the agent with the given name.

property agents: List[Agent]

Returns the agents.

property all_objects: List[Object]

Returns the list containing all the objects in the problem.

property environment: Environment

Returns the Problem Environment.

has_agent(name: str) bool

Returns True iff the agent ‘name’ is defined.

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 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.

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.