pycollo.optimal_control_problem.OptimalControlProblem#

class pycollo.optimal_control_problem.OptimalControlProblem(name, parameter_variables=None, *, bounds=None, guess=None, scaling=None, endpoint_constraints=None, objective_function=None, settings=None, auxiliary_data=None)[source]#

Bases: object

The main class for Pycollo optimal control problems

Attributes

auxiliary_data

bounds

endpoint_constraints

guess

mesh_iterations

name

The name associated with the optimal control problem.

num_mesh_iterations

number_endpoint_constraints

number_parameter_variables

number_phases

Number of phases associated with this optimal control problem.

objective_function

parameter_variables

phases

A tuple of all phases associated with the optimal control problem.

scaling

settings

solution

time_symbol

Raises: NotImplementedError: Whenever called to inform the user that these types of problem are not currently supported.

Methods

__init__

Initialise the optimal control problem with user-passed objects.

add_phase

Add an already instantiated Phase to this optimal control problem.

add_phases

Associate multiple already instantiated Phase objects.

initialise

Initialise the optimal control problem before solving.

new_phase

Create a new Phase and add to this optimal control problem.

new_phase_like

new_phases_like

Creates multiple new phases like an already instantiated phase.

solve

Solve the optimal control problem.

__init__(name, parameter_variables=None, *, bounds=None, guess=None, scaling=None, endpoint_constraints=None, objective_function=None, settings=None, auxiliary_data=None)[source]#

Initialise the optimal control problem with user-passed objects.

Parameters:
  • phases (Iterable of Phase, optional) – Phases to be associated with the optimal control problem at initialisation. Defaults to None.

  • () (parameter_variables) –

__repr__()[source]#

Return repr(self).

__str__()[source]#

Returns name of OCP

__weakref__#

list of weak references to the object (if defined)

add_phase(phase: Iterable[Phase]) Phase[source]#

Add an already instantiated Phase to this optimal control problem.

This method is needed as phases is read only (“private”) and therefore users cannot manually add Phase objects to an optimal control problem. phases is required to be read only as it is an iterable of Phase objects and must be protected from accidental errors introduced by user interacting with it incorrectly.

Parameters:

phase (Phase) – The phase to be added to the optimal control problem

Returns:

the phase that has been added. It is the same

add_phases(phases: Iterable[Phase]) Tuple[Phase, ...][source]#

Associate multiple already instantiated Phase objects.

This is a convinience method to allow the user to add multiple Phase objects to the optimal control problem in one go.

initialise()[source]#

Initialise the optimal control problem before solving.

The initialisation of the optimal control problem involves the following stages:

    1. Check that for each phase there are the same number of state variables as there are state equations.

    1. Check that for each phase the user-supplied bounds are permissible, and check point bounds on optimal control problem.

    1. Process bounds that need processing.

property name: str#

The name associated with the optimal control problem. For setter behaviour, the supplied name is cast to a str.

The name is not strictly needed, however it improves the usefulness of Pycollo console output. This is particularly useful in cases where the user may wish to instantiate multiple OptimalControlProblem objects within a single script, or instantiates other Pycollo objects without providing a valid optimal_control_problem argument for them to be linked to at initialisation.

new_phase(name: str, state_variables: None | Symbol | Iterable[Symbol] | AppliedUndef | Iterable[AppliedUndef] = None, control_variables: None | Symbol | Iterable[Symbol] | AppliedUndef | Iterable[AppliedUndef] = None) Phase[source]#

Create a new Phase and add to this optimal control problem.

Provides the same behaviour as manually creating a Phase called phase and calling add_phase().

new_phases_like(phase_for_copying: Phase, number: int, names: Iterable[str], **kwargs) Tuple[Phase, ...][source]#

Creates multiple new phases like an already instantiated phase.

For a list of key word arguments and default values see the docstring for the new_phase_like() method.

Returns:

The newly instantiated and associated phases.

Raises:

ValueError – If the same number of names are not supplied as the number of specified new phases.

property number_phases: int#

Number of phases associated with this optimal control problem.

property phases: Tuple[Phase, ...]#

A tuple of all phases associated with the optimal control problem.

phase_number() are integers beginning at 1 and are ordered corresponding to the order that they were added to the optimal control problem. As Python uses zero-based indexing the phase numbers do not directly map to the indexes of phases within phases. Phases are however ordered sequentially corresponding to the cronological order they were added to the optimal control problem.

solve(display_progress=False)[source]#

Solve the optimal control problem.

If the initialisation flag is not set to True then the initialisation method is called to initialise the optimal control problem.

Parameters:

display_progress – bool Option for whether progress updates should be outputted to the console during solving. Defaults to False.

property time_symbol#

Raises: NotImplementedError: Whenever called to inform the user that these

types of problem are not currently supported.