soft4pes.control.mpc.solvers#
Solvers for model predictive control (MPC) algorithms.
Submodules#
Classes#
Problem formulation and QP solver for indirect MPC. |
|
Branch-and-bound (BnB) solver for model predictive control (MPC). |
|
Enumeration-based solver for model predictive control (MPC). |
Functions#
|
Check if a candidate three-phase switch position violates a switching constraint. |
|
Compute the squared weighted second norm of a vector. The elements of the norm are weighted by |
|
Create the QP matrices. |
|
Make Gamma matrix for the QP. |
|
Make Upsilon matrix for the QP. |
Package Contents#
- class soft4pes.control.mpc.solvers.IndirectMpcQP[source]#
Problem formulation and QP solver for indirect MPC.
- QP_matrices#
Namespace containing the matrices used in the QP problem.
- Type:
SimpleNamespace
- __call__(sys, ctr, y_ref)[source]#
Formulate and solve the MPC QP.
- Parameters:
sys (system object) – System model.
ctr (controller object) – Controller object.
y_ref (ndarray of floats) – Reference vector [p.u.].
- Returns:
u_abc – The three-phase modulating signal.
- Return type:
1 x 3 ndarray of floats
- class soft4pes.control.mpc.solvers.MpcBnB(conv)[source]#
Branch-and-bound (BnB) solver for model predictive control (MPC).
- Parameters:
conv (converter object) – Converter model.
- J_min#
Minimum cost.
- Type:
float
- U_seq#
Sequence of three-phase switch positions (switching sequence) with the lowest cost.
- Type:
1 x 3*Np ndarray of ints
- U_temp#
Temporary array for incumbent swithing sequence.
- Type:
1 x 3*Np ndarray of ints
- SW_COMB#
All possible three-phase switch positions.
- Type:
1 x conv.nl^3 ndarray of ints
- __call__(sys, ctr, y_ref)[source]#
Solve MPC problem by using a simple BnB method.
- Parameters:
sys (system object) – System model.
ctr (controller object) – Controller object.
y_ref (ndarray of floats) – Reference vector [p.u.].
- Returns:
u_abc – The three-phase switch position.
- Return type:
1 x 3 ndarray of ints
- solve(sys, ctr, x_ell, y_ref, u_ell_abc_prev, ell=0, J_prev=0)[source]#
Recursively compute the cost for different switching sequences.
- Parameters:
sys (object) – System model.
ctr (object) – Controller object.
x_ell (ndarray of floats) – State vector [p.u.].
y_ref (ndarray of floats) – Reference vector [p.u.].
u_ell_abc_prev (1 x 3 ndarray of ints) – Previous three-phase switch position.
ell (int) – Prediction step. The default is 0.
J_prev (float) – Previous cost. The default is 0.
- class soft4pes.control.mpc.solvers.MpcEnum(conv)[source]#
Enumeration-based solver for model predictive control (MPC).
- Parameters:
conv (converter object) – Converter model.
- U_seq#
Array for sequences of three-phase switch positions (switching sequences).
- Type:
3*Np x conv.nl^(3*Np) ndarray of ints
- sw_pos_3ph#
Possible one-phase switch positions.
- Type:
1 x conv.nl ndarray of ints
- __call__(sys, ctr, y_ref)[source]#
Solve MPC problem with exhaustive enumeration.
- Parameters:
sys (system object) – System model.
ctr (controller object) – Controller object.
y_ref (ndarray of floats) – Reference vector [p.u.].
- Returns:
u_abc – The three-phase switch position with the lowest cost.
- Return type:
1 x 3 ndarray of ints
- solve(sys, ctr, xk, y_ref, u_km1_abc)[source]#
Recursively compute the cost for different switching sequences
- Parameters:
sys (system object) – System model.
ctr (controller object.) – Controller object.
xk (ndarray of floats) – Current state vector [p.u.].
y_ref (ndarray of floats) – Reference vector [p.u.].
u_km1_abc (1 x 3 ndarray of ints) – Three-phase switch position applied at step k-1.
- Returns:
J – Cost array.
- Return type:
1 x nl^(3*Np) ndarray of floats
- soft4pes.control.mpc.solvers.switching_constraint_violated(nl, u_abc, u_km1_abc)[source]#
Check if a candidate three-phase switch position violates a switching constraint. A three-level converter is not allowed to directly switch from -1 and 1 (and vice versa) on one phase.
- Parameters:
nl (int) – Number of converter voltage levels.
u_abc (1 x 3 ndarray of ints) – three-phase switch position.
u_km1_abc (1 x 3 ndarray of ints) – Previously applied three-phase switch position.
- Returns:
Constraint violated.
- Return type:
bool
- soft4pes.control.mpc.solvers.squared_weighted_second_norm(vector, Q)[source]#
Compute the squared weighted second norm of a vector. The elements of the norm are weighted by the weighting matrix Q, i.e. sqrt(x.T * Q * x)^2 = x.T * Q * x.
- Parameters:
vector (ndarray) – Vector.
Q (ndarray) – Weighting matrix.
- Returns:
Squared weighted second norm.
- Return type:
float
- soft4pes.control.mpc.solvers.make_QP_matrices(sys, ctr)[source]#
Create the QP matrices.
- Parameters:
sys (system object) – System model.
ctr (controller object) – Controller object.
- Returns:
Namespace containing the QP matrices.
- Return type:
SimpleNamespace
- soft4pes.control.mpc.solvers.make_Gamma(Np, C, A)[source]#
Make Gamma matrix for the QP.
- Parameters:
Np (int) – Prediction horizon.
C (ndarray) – Output matrix of the system.
A (ndarray) – State matrix of the system.
- Returns:
Gamma matrix.
- Return type:
ndarray
- soft4pes.control.mpc.solvers.make_Upsilon(Np, C, A, B)[source]#
Make Upsilon matrix for the QP.
- Parameters:
Np (int) – Prediction horizon.
C (ndarray) – Output matrix of the system.
A (ndarray) – State matrix of the system.
B (ndarray) – Input matrix of the system.
- Returns:
Upsilon matrix.
- Return type:
ndarray