pockit.base.discretizationbase

def lr_c( num_point: numpy.ndarray[typing.Any, numpy.dtype[numpy.int32]]) -> tuple[numpy.ndarray[typing.Any, numpy.dtype[numpy.int32]], numpy.ndarray[typing.Any, numpy.dtype[numpy.int32]]]:

Compute the left and right indices if the border variables are shared. The left index is l_c[i] and the right index is r_c[i], which represents the range of interval i in a half-open interval [l_c[i], r_c[i]).

Arguments:
  • num_point: Number of interpolation points of each interval.
Returns:

Left and right index l_c, r_c for shared border variables.

def lr_nc( num_point: numpy.ndarray[typing.Any, numpy.dtype[numpy.int32]]) -> tuple[numpy.ndarray[typing.Any, numpy.dtype[numpy.int32]], numpy.ndarray[typing.Any, numpy.dtype[numpy.int32]]]:

Compute the left and right indices if separate variables represent the common borders. The left index is l_nc[i] and the right index is r_nc[i], which represents the range of interval i in a half-open interval [l_nc[i], r_nc[i]).

Arguments:
  • num_point: Number of interpolation points of each interval.
Returns:

Left and right index l_nc, r_nc for separate border variables.

class CooMatrix:

Hold the data of a sparse matrix in COO format.

CooMatrix( row: numpy.ndarray[typing.Any, numpy.dtype[numpy.int32]], col: numpy.ndarray[typing.Any, numpy.dtype[numpy.int32]], data: numpy.ndarray[typing.Any, numpy.dtype[numpy.float64]])
row: numpy.ndarray[typing.Any, numpy.dtype[numpy.int32]]
col: numpy.ndarray[typing.Any, numpy.dtype[numpy.int32]]
data: numpy.ndarray[typing.Any, numpy.dtype[numpy.float64]]
class IndexNode:

In the discretization scheme, the state and control variables are represented by values at discrete time points. The scheme requires additional information about whether the vector contains the variable's initial and terminal values to handle boundary conditions.

The data structure is applied to state, control, and middle-stage variables.

IndexNode(front: Optional[int], middle: tuple[int, int], back: Optional[int])
Arguments:
  • front: The index of the front variable or None if the vector does not contain the initial value.
  • middle: The range of the middle variables.
  • back: The index of the back variable or None if the vector does not contain the terminal value.
f: bool

Whether the vector contains the front variable.

m: slice

The slice of the middle variables.

b: bool

Whether the vector contains the back variable.

L_m: int

The length of the middle variables.

l_m: int

The left index of the middle variables.

r_m: int

The right index of the middle variables (exclusive).

class CooMatrixNode:

Classify the COO matrix into front, middle, and back parts according to the column index and the index partition.

The data structure is used to generate the Jacobian and Hessian matrices of the discretized problem.

CooMatrixNode( csr_matrix: scipy.sparse._csr.csr_array, index: IndexNode)
Arguments:
  • csr_matrix: The CSR matrix to be classified.
  • index: The index partition of the vector.

The front part of the COO matrix.

The middle part of the COO matrix.

The back part of the COO matrix.

class DiscretizationBase(abc.ABC):

Essential information for a discretization scheme.

The class contains the information to discretize the continuous-time optimal control problem into a discrete-time problem and generate the derivative matrices.

DiscretizationBase( mesh: numpy.ndarray[typing.Any, numpy.dtype[numpy.float64]], num_point: numpy.ndarray[typing.Any, numpy.dtype[numpy.int32]], n_x: int, n_u: int)
Arguments:
  • mesh: The mesh points of the time interval.
  • num_point: The number of interpolation points in each subinterval.
  • n_x: The number of state variables.
  • n_u: The number of control variables.
mesh: numpy.ndarray[typing.Any, numpy.dtype[numpy.float64]]

The mesh points of the time interval, scaled to [0, 1].

num_point: numpy.ndarray[typing.Any, numpy.dtype[numpy.int32]]

The number of interpolation points in each subinterval.

n_x: int

The number of state variables.

n_u: int

The number of control variables.

index_state: IndexNode

Index partition of the state variables.

index_control: IndexNode

Index partition of the control variables.

index_mstage: IndexNode

Index partition of the middle-stage variables.

l_v: numpy.ndarray[typing.Any, numpy.dtype[numpy.int32]]

The left index of the state and control variables.

r_v: numpy.ndarray[typing.Any, numpy.dtype[numpy.int32]]

The right index of the state and control variables (exclusive).

t_m: numpy.ndarray[typing.Any, numpy.dtype[numpy.float64]]

Position of all interpolation nodes in the middle stage, scaled to [0, 1].

l_m: numpy.ndarray[typing.Any, numpy.dtype[numpy.int32]]

The left index of subintervals in the middle stage.

r_m: numpy.ndarray[typing.Any, numpy.dtype[numpy.int32]]

The right index of subintervals in the middle stage (exclusive).

L_m: int

The number of interpolation points in the middle stage.

w_m: numpy.ndarray[typing.Any, numpy.dtype[numpy.float64]]

The integration weights of the middle stage.

f_v2m: Callable[[numpy.ndarray[Any, numpy.dtype[numpy.float64]]], numpy.ndarray[Any, numpy.dtype[numpy.float64]]]

Function turns the state and control variables into the middle stage.

T_v: scipy.sparse._csr.csr_array

Translation matrix of a state variable to eliminate the integration coefficient.

T_v_coo: CooMatrixNode

Translation matrix of a state variable in COO format partitioned by the index.

I_m: scipy.sparse._csr.csr_array

Integration matrix of a middle-stage variable.

I_m_coo: CooMatrixNode

Integration matrix of a middle-stage variable in COO format partitioned by the index.

l_d: numpy.ndarray[typing.Any, numpy.dtype[numpy.int32]]

The left index of the dynamic constraints of each state variable.

r_d: numpy.ndarray[typing.Any, numpy.dtype[numpy.int32]]

The right index of the dynamic constraints of each state variable (exclusive).

t_m_aug: numpy.ndarray[typing.Any, numpy.dtype[numpy.float64]]

Position of all interpolation nodes in the middle stage, scaled to [0, 1] with one additional interpolation point in each subinterval.

l_m_aug: numpy.ndarray[typing.Any, numpy.dtype[numpy.int32]]

The left index of subintervals in the middle stage, with one additional interpolation point in each subinterval.

r_m_aug: numpy.ndarray[typing.Any, numpy.dtype[numpy.int32]]

The right index of subintervals in the middle stage (exclusive), with one additional interpolation point in each subinterval.

L_m_aug: int

The number of interpolation points in the middle stage, with one additional interpolation point in each subinterval.

w_aug: list[numpy.ndarray[typing.Any, numpy.dtype[numpy.float64]]]

The integration weights of each subinterval in the middle stage, with one additional interpolation point in each subinterval.

P: Callable[[int], numpy.ndarray[Any, numpy.dtype[numpy.float64]]]

Function to compute the polynomial matrix given the number of interpolation points.

V_xu_aug: scipy.sparse._csr.csr_array

The value matrix translates all state and control variables to the middle stage with one additional interpolation point in each subinterval.

T_x_aug: scipy.sparse._csr.csr_array

The translation matrix of all state variables, with one additional interpolation point in each subinterval.

I_m_aug: scipy.sparse._csr.csr_array

The integration matrix of a middle-stage variable, with one additional interpolation point in each subinterval.

t_x: numpy.ndarray[typing.Any, numpy.dtype[numpy.float64]]

Position of all interpolation nodes of a state variable, scaled to [0, 1].

t_u: numpy.ndarray[typing.Any, numpy.dtype[numpy.float64]]

Position of all interpolation nodes of a control variable, scaled to [0, 1].

l_x: numpy.ndarray[typing.Any, numpy.dtype[numpy.int32]]

The left index of subintervals of a state variable.

r_x: numpy.ndarray[typing.Any, numpy.dtype[numpy.int32]]

The right index of subintervals of a state variable (exclusive).

l_u: numpy.ndarray[typing.Any, numpy.dtype[numpy.int32]]

The left index of subintervals of a control variable.

r_u: numpy.ndarray[typing.Any, numpy.dtype[numpy.int32]]

The right index of subintervals of a control variable (exclusive).