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
The name associated with the optimal control problem.
num_mesh_iterations
number_endpoint_constraints
number_parameter_variables
Number of phases associated with this optimal control problem.
objective_function
parameter_variables
A tuple of all phases associated with the optimal control problem.
scaling
settings
solution
Raises: NotImplementedError: Whenever called to inform the user that these types of problem are not currently supported.
Methods
Initialise the optimal control problem with user-passed objects.
Add an already instantiated
Phase
to this optimal control problem.Associate multiple already instantiated
Phase
objects.Initialise the optimal control problem before solving.
Create a new
Phase
and add to this optimal control problem.new_phase_like
Creates multiple new phases like an already instantiated phase.
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
ofPhase
, optional) – Phases to be associated with the optimal control problem at initialisation. Defaults to None.() (parameter_variables) –
- __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 addPhase
objects to an optimal control problem.phases
is required to be read only as it is an iterable ofPhase
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:
Check that for each phase there are the same number of state variables as there are state equations.
Check that for each phase the user-supplied bounds are permissible, and check point bounds on optimal control problem.
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 validoptimal_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 callingadd_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 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 withinphases
. 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.