Agent

class unified_planning.model.multi_agent.Agent(name: str, ma_problem: MultiAgentProblem)[source]

Bases: FluentsSetMixin, ActionsSetMixin

This is an agent class that represents a generic agent.

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

property name: str

Returns the Agent name.

property environment: Environment

Returns this Agent Environment.

add_public_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[source]

Adds the given public 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.

add_private_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[source]

Adds the given private 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.

add_public_fluents(fluents: Iterable[Fluent])[source]

Adds the given public fluents to the problem.

Parameters:

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

add_private_fluents(fluents: Iterable[Fluent])[source]

Adds the given private fluents to the problem.

Parameters:

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

property public_fluents: List[Fluent]

Returns the fluents currently in the problem.

property private_fluents: List[Fluent]

Returns the fluents currently in the problem.

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

Adds the given goal to the Agent as a private goal.

Parameters:

goal – The expression added to the Agent private goals.

Returns:

The expression of the private goal added.

Note: - Private-specific goals are; individual agent goals (not coalition goals) unknown to other agents.

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

Adds the given goal to the Agent as a public goal.

Parameters:

goal – The expression added to the Agent public goals.

Returns:

The expression of the public goal added.

Note: - Public-specific goals are; individual agent goals (not coalition goals) known to other agents.

property public_goals: List[FNode]

Returns the public goals currently in the agent.

property private_goals: List[FNode]

Returns the private goals currently in the agent.

clear_goals()[source]

Removes all the goals from the Agent.

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.

clear_actions()

Removes all the Problem Actions.

clear_fluents()

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

clone(ma_problem: MultiAgentProblem, name: str | None = None)[source]
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 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.

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.

get_static_fluents() Set[Fluent]

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]

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

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.

property initial_defaults: Dict[Type, FNode]

Returns the problem’s fluents defaults for each type.

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

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.