pockit.base.systembase
A system is the higher level objective of a multiple-phase optimal control problem.
Initialize a system with given static parameters.
If static_parameter
is an integer, the names are generated automatically as \( s_0, s_1, \dots, s_{n-1} \).
If simplify
is True
, every symbolic expression will be simplified (by sympy.simplify()
) before
being compiled. This will slow down the speed of compilation.
If parallel
is True
, the parallel
flag will be passed to the Numba JIT compiler,
which will generate parallel code for multicore CPUs.
This will slow down the speed of compilation and sometimes the speed of execution.
If fastmath
is True
, the fastmath
flag will be passed to the Numba JIT compiler,
see Numba
and LLVM documentations for details.
Arguments:
- static_parameter: Number of static parameters or list of static parameter names.
- simplify: Whether to use Sympy to simplify
sympy.Expr
before compilation. - parallel: Whether to use Numba
parallel
mode. - fastmath: Whether to use Numba
fastmath
mode.
Create a new phase for the given system.
This method is recommended to create a phase rather than using Phase
's constructor directly,
because it automatically set the symbol_static_parameter
, identifier
and flags of the phase.
Arguments:
- state: Number of state variables or list of state variable names.
- control: Number of control variables or list of control variable names.
Returns:
A new phase, with
symbol_static_parameter
,identifier
and flags automatically set.
Set the objective of the system.
Arguments:
- objective: Objective of the system composed with I and s.
- cache: Path to the directory to store the compiled functions.
Set the system constraints of the system.
For equality constraints, set the corresponding entry of lower_bounds
and upper_bounds
to the same value.
For one-sided inequality constraints, set the corresponding entry of lower_bounds
or upper_bounds
to -inf
or inf
.
Arguments:
- system_constraint: List of system constraints composed with I and s.
- lower_bound: Iterable of lower bounds of system constraints.
- upper_bound: Iterable of upper bounds of system constraints.
- cache: Path to the directory to store the compiled functions.
The objective function of the discretized optimization problem.
Constraint functions of the discretized optimization problem.
Gradient of the objective function of the discretized optimization problem.
Coordinates of the Jacobian of the constraint functions of the discretized optimization problem.
Jacobian of the constraint functions of the discretized optimization problem.
Arguments:
- x: Vector of optimization variables.
Returns:
A plain 1D array, with coordinates given by
jacobianstructure()
.
Coordinates of the Hessian of the objective function of the discretized optimization problem.
Only includes entries in the lower triangle of the Hessian matrix.
Hessian of the objective function of the discretized optimization problem.
Arguments:
- x: Vector of optimization variables.
Returns:
A plain 1D array, with coordinates given by
hessianstructure_o()
. Only includes entries in the lower triangle of the Hessian matrix.
Coordinates of the Hessian of the constraint functions of the discretized optimization problem.
Only includes entries in the lower triangle of the Hessian matrix.
Sum of Hessian of the constraint functions of the discretized
optimization problem with factor fct_c
.
Arguments:
- x: Vector of optimization variables.
- fct_c: Factors (Lagrange multipliers) for the constraints.
Returns:
A plain 1D array, with coordinates given by
hessianstructure_c()
. Only includes entries in the lower triangle of the Hessian matrix.
Coordinates of the Hessian of the Lagrangian of the discretized optimization problem.
Only includes entries in the lower triangle of the Hessian matrix.
Hessian of the Lagrangian of the discretized optimization problem
with factors fct_c
for constraints and fct_o
for the objective.
Arguments:
- x: Vector of optimization variables.
- fct_c: Factors (Lagrange multipliers) for the constraints.
- fct_o: Factor (Lagrange multiplier) for the objective.
Returns:
A plain 1D array, with coordinates given by
hessianstructure()
. Only includes entries in the lower triangle of the Hessian matrix.
Check the continuous error.
Arguments:
- value: The variable to be checked. If the system has only one phase and no static variables,
value
can be a singleVariable
object. Otherwise,value
should be a list ofVariable
objects, one for eachPhase
, followed by an array as values of static variables. - absolute_tolerance_continuous: Absolute tolerance for continuous error.
- relative_tolerance_continuous: Relative tolerance for continuous error.
- tolerance_mesh: Skip the check if the mesh width is smaller than this value.
Returns:
True
if the error is within the tolerance,False
otherwise.
Check the discontinuous error.
Arguments:
- value: The variable to be checked. If the system has only one phase and no static variables,
value
can be a singleVariable
object. Otherwise,value
should be a list ofVariable
objects, one for eachPhase
, followed by an array as values of static variables. - tolerance_discontinuous: In each subinterval, after scaling to
[0, 1]
, the bang-bang control functions should either be less thantolerance_discontinuous
or greater than1 - tolerance_discontinuous
simultaneously. - tolerance_mesh: Skip the check if the mesh width is smaller than this value.
Returns:
True
if the error is within the tolerance,False
otherwise.
Check the continuous and discontinuous error.
Arguments:
- value: The variable to be checked. If the system has only one phase and no static variables,
value
can be a singleVariable
object. Otherwise,value
should be a list ofVariable
objects, one for eachPhase
, followed by an array as values of static variables. - absolute_tolerance_continuous: Absolute tolerance for continuous error.
- relative_tolerance_continuous: Relative tolerance for continuous error.
- tolerance_discontinuous: In each subinterval, after scaling to
[0, 1]
, the bang-bang control functions should either be less thantolerance_discontinuous
or greater than1 - tolerance_discontinuous
simultaneously. - tolerance_mesh: Skip the check if the mesh width is smaller than this value.
Returns:
True
if the error is within the tolerance,False
otherwise.
Adjust the mesh and the number of interpolation points to match the continuous error tolerance.
Arguments:
- value: The variable to be checked. If the system has only one phase and no static variables,
value
can be a singleVariable
object. Otherwise,value
should be a list ofVariable
objects, one for eachPhase
, followed by an array as values of static variables. - absolute_tolerance_continuous: Absolute tolerance for continuous error.
- relative_tolerance_continuous: Relative tolerance for continuous error.
- num_point_min: Minimum number of interpolation points.
- num_point_max: Maximum number of interpolation points.
- mesh_length_min: Minimum mesh length.
- mesh_length_max: Maximum mesh length.
Returns:
The
Variable
s interpolated to the new discretization scheme.
Adjust the mesh and the number of interpolation points to match the discontinuous error tolerance.
Arguments:
- value: The variable to be checked. If the system has only one phase and no static variables,
value
can be a singleVariable
object. Otherwise,value
should be a list ofVariable
objects, one for eachPhase
, followed by an array as values of static variables. - tolerance_discontinuous: In each subinterval, after scaling to
[0, 1]
, the bang-bang control functions should either be less thantolerance_discontinuous
or greater than1 - tolerance_discontinuous
simultaneously. - num_point_min: Minimum number of interpolation points.
- num_point_max: Maximum number of interpolation points.
- mesh_length_min: Minimum mesh length.
- mesh_length_max: Maximum mesh length.
Returns:
The
Variable
s interpolated to the new discretization scheme.
Adjust the mesh and the number of interpolation points to match the error tolerances.
If the discontinuous error is not within the tolerance, refine for discontinuous error. Otherwise, if the continuous error is not within the tolerance, refine for continuous error. At most one of the continuous or discontinuous refinements will be performed.
Arguments:
- value: The variable to be checked. If the system has only one phase and no static variables,
value
can be a singleVariable
object. Otherwise,value
should be a list ofVariable
objects, one for eachPhase
, followed by an array as values of static variables. - absolute_tolerance_continuous: Absolute tolerance for continuous error.
- relative_tolerance_continuous: Relative tolerance for continuous error.
- tolerance_discontinuous: In each subinterval, after scaling to
[0, 1]
, the bang-bang control functions should either be less thantolerance_discontinuous
or greater than1 - tolerance_discontinuous
simultaneously. - num_point_min: Minimum number of interpolation points.
- num_point_max: Maximum number of interpolation points.
- mesh_length_min: Minimum mesh length.
- mesh_length_max: Maximum mesh length.
Returns:
The
Variable
s interpolated to the new discretization scheme.