Factory

class unified_planning.engines.Factory(environment: Environment)[source]

Bases: object

Class that manages all the different Engines classes and handles the operation modes available in the library.

property engines: List[str]

Returns the list of the available Engines names.

engine(name: str) Type[Engine][source]

Returns a specific Engine class.

Parameters:

name – The name of the engine in the factory.

Returns:

The engine Class.

property preference_list: List[str]

Returns the current list of preferences.

add_engine(name: str, module_name: str, class_name: str)[source]

Adds an Engine Class to the factory, given the module and the class names.

Parameters:
  • name – The name of the added engine Class in the factory.

  • module_name – The name of the module in which the engine Class is defined.

  • class_name – The name of the engine Class.

add_meta_engine(name: str, module_name: str, class_name: str)[source]

Adds a MetaEngine Class to the Factory, given the module and the class names.

Parameters:
  • name – The name of the added meta engine Class in the factory.

  • module_name – The name of the module in which the meta engine Class is defined.

  • class_name – The name of the meta engine Class.

configure_from_file(config_filename: str | None = None)[source]

Reads a configuration file and configures the factory.

The following is an example of configuration file:

[global] engine_preference_list: fast-downward fast-downward-opt enhsp enhsp-opt tamer

[engine <engine-name>] module_name: <module-name> class_name: <class-name>

If not given, the configuration is read from the first up.ini or .up.ini file located in any of the parent directories from which this code was called or, otherwise, from one of the following files: ~/up.ini, ~/.up.ini, ~/.uprc.

Parameters:

config_filename – The path of the file containing the wanted configuration.

property environment: Environment

Returns the environment in which this factory is created

OneshotPlanner(*, name: str | None = None, names: Sequence[str] | None = None, params: Dict[str, Any] | Sequence[Dict[str, Any]] | None = None, problem_kind: ProblemKind = ProblemKind([]), optimality_guarantee: OptimalityGuarantee | str | None = None) Engine[source]

Returns a oneshot planner. There are three ways to call this method:

  • using name (the name of a specific planner) and params (planner dependent options).
    e.g. OneshotPlanner(name='tamer', params={'heuristic': 'hadd'})
  • using names (list of specific planners name) and params (list of planner dependent options) to get a Parallel engine.
    e.g. OneshotPlanner(names=['tamer', 'tamer'], params=[{'heuristic': 'hadd'}, {'heuristic': 'hmax'}])
  • using problem_kind and optimality_guarantee.
    e.g. OneshotPlanner(problem_kind=problem.kind, optimality_guarantee=SOLVED_OPTIMALLY)
AnytimePlanner(*, name: str | None = None, params: Dict[str, str] | None = None, problem_kind: ProblemKind = ProblemKind([]), anytime_guarantee: AnytimeGuarantee | str | None = None) Engine[source]

Returns a anytime planner. There are two ways to call this method:

  • using name (the name of a specific planner) and params (planner dependent options).
    e.g. AnytimePlanner(name='tamer', params={'heuristic': 'hadd'})
  • using problem_kind and anytime_guarantee.
    e.g. AnytimePlanner(problem_kind=problem.kind, anytime_guarantee=INCREASING_QUALITY)

An AnytimePlanner is a planner that returns an Iterator of solutions. Depending on the given anytime_guarantee parameter, every plan being generated is:

  • strictly better in terms of quality than the previous one (INCREASING_QUALITY);

  • optimal (OPTIMAL_PLANS);

  • just a different plan, with no specific guarantee (None).

It raises an exception if the problem has no optimality metrics and anytime_guarantee is equal to INCREASING_QUALITY or OPTIMAL_PLAN.

PlanValidator(*, name: str | None = None, names: Sequence[str] | None = None, params: Dict[str, str] | Sequence[Dict[str, str]] | None = None, problem_kind: ProblemKind = ProblemKind([]), plan_kind: PlanKind | str | None = None) Engine[source]

Returns a plan validator. There are three ways to call this method:

  • using name (the name of a specific plan validator) and params (plan validator dependent options).
    e.g. PlanValidator(name='tamer', params={'opt': 'val'})
  • using names (list of specific plan validators name) and params (list of plan validators dependent options) to get a Parallel engine.
    e.g. PlanValidator(names=['tamer', 'tamer'], params=[{'opt1': 'val1'}, {'opt2': 'val2'}])
  • using problem_kind and plan_kind parameters.
    e.g. PlanValidator(problem_kind=problem.kind, plan_kind=plan.kind)
Compiler(*, name: str | None = None, names: Sequence[str] | None = None, params: Dict[str, str] | Sequence[Dict[str, str]] | None = None, problem_kind: ProblemKind = ProblemKind([]), compilation_kind: CompilationKind | str | None = None, compilation_kinds: Sequence[CompilationKind | str] | None = None) Engine[source]

Returns a compiler or a pipeline of compilers.

To get a compiler there are two ways to call this method:

  • using name (the name of a specific compiler) and params (compiler dependent options).
    e.g. Compiler(name='tamer', params={'opt': 'val'})
  • using problem_kind and compilation_kind parameters.
    e.g. Compiler(problem_kind=problem.kind, compilation_kind=GROUNDING)

To get a pipeline of compilers there are two ways to call this method:

  • using names (the names of the specific compilers), params (compilers dependent options) and compilation_kinds.
    e.g. Compiler(names=['up_quantifiers_remover', 'up_grounder'], params=[{'opt1': 'val1'}, {'opt2': 'val2'}], compilation_kinds=[QUANTIFIERS_REMOVING, GROUNDING])
  • using problem_kind and compilation_kinds parameters.
    e.g. Compiler(problem_kind=problem.kind, compilation_kinds=[QUANTIFIERS_REMOVING, GROUNDING])
SequentialSimulator(problem: AbstractProblem, *, name: str | None = None, params: Dict[str, str] | None = None) Engine[source]

Returns a sequential simulator. There are two ways to call this method:

  • using problem_kind through the problem field.
    e.g. SequentialSimulator(problem)
  • using name (the name of a specific simulator) and eventually some params (simulator dependent options).
    e.g. SequentialSimulator(problem, name='sequential_simulator')
Replanner(problem: AbstractProblem, *, name: str | None = None, params: Dict[str, str] | None = None, optimality_guarantee: OptimalityGuarantee | str | None = None) Engine[source]

Returns a Replanner. There are two ways to call this method:

  • using problem (with its kind) and optimality_guarantee parameters.
    e.g. Replanner(problem, optimality_guarantee=SOLVED_OPTIMALLY)
  • using name (the name of a specific replanner) and params (replanner dependent options).
    e.g. Replanner(problem, name='replanner[tamer]')
PlanRepairer(*, name: str | None = None, params: Dict[str, Any] | None = None, problem_kind: ProblemKind = ProblemKind([]), plan_kind: PlanKind | str | None = None, optimality_guarantee: OptimalityGuarantee | str | None = None) Engine[source]

Returns a plan repairer. There are two ways to call this method:

  • using name (the name of a plan repairer) and eventually params.
    e.g. PlanRepairer(name='xxx')
  • using problem_kind, plan_kind and optimality_guarantee.
    e.g. PlanRepairer(problem_kind=problem.kind, plan_kind=plan.kind, optimality_guarantee=SOLVED_OPTIMALLY)
PortfolioSelector(*, name: str | None = None, params: Dict[str, Any] | None = None, problem_kind: ProblemKind = ProblemKind([]), optimality_guarantee: OptimalityGuarantee | str | None = None) Engine[source]

Returns a portfolio selector. There are two ways to call this method:

  • using name (the name of a specific portfolio) and eventually params (portfolio dependent options).
    e.g. PortfolioSelector(name='ibacop')
  • using problem_kind and optimality_guarantee.
    e.g. PortfolioSelector(problem_kind=problem.kind, optimality_guarantee=SOLVED_OPTIMALLY)
print_engines_info(stream: ~typing.IO[str] = <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>, *, operation_mode: ~unified_planning.engines.engine.OperationMode | str | None = None, show_supported_kind: bool = True, show_credits: bool = False, full_credits: bool = True)[source]

Writes the info of all the installed engines in the given stream; the default stream is the stdout.

Parameters:
  • stream – The IO[str] where all the engine’s info are written; defaults to sys.stdout.

  • operation_mode – If specified, writes info about the engines that support that OperationMode.

  • show_supported_kind – If True writes the supported_kind of the engines. defaults to True.

  • show_credits – If True writes the credits of the engines. defaults to False.

  • full_credits – If True writes a longer version of the credits; ignored if show_credits is False; defaults to True.

get_all_applicable_engines(problem_kind: ProblemKind, operation_mode: OperationMode = OperationMode.ONESHOT_PLANNER, *, optimality_guarantee: OptimalityGuarantee | str | None = None, anytime_guarantee: AnytimeGuarantee | str | None = None, plan_kind: PlanKind | str | None = None, compilation_kind: CompilationKind | str | None = None) List[str][source]
Returns all the engine names installed that are able to handle all the given requirements.
Since the semantic of the parameters given to this function depends on the chosen OperationMode, an user must have clear their meaning in the Operation Mode context.
Parameters:
  • problem_kind – An engine is returned only if it supports this problem_kind.

  • operation_mode – An engine is returned only if it implements this operation_mode; defaults to ONESHOT_PLANNER.

  • optimality_guarantee – An engine is returned only if it satisfies this optimality_guarantee. This parameter can be specified only if the operation_mode is ONESHOT_PLANNER, REPLANNER, PLAN_REPAIRER or PORTFOLIO_SELECTOR.

  • anytime_guarantee – An engine is returned only if it satisfies this anytime_guarantee. This parameter can be specified only if the operation_mode is ANYTIME_PLANNER.

  • plan_kind – An engine is returned only if it is able to handle this plan_kind. This parameter can be specified only if the operation_mode is PLAN_VALIDATOR or PLAN_REPAIRER.

  • compilation_kind – An engine is returned only if it is able to handle this compilation_kind. This parameter can be specified only if the operation_mode is COMPILER.

Returns:

The list of engines names that satisfy all the given requirements.