pympcc.StructuredMPCC¶
- class pympcc.StructuredMPCC(n, n_comp, x0, objective, comp_G, comp_H, gradient=None, comp_G_jacobian=None, comp_H_jacobian=None, derivatives=None, xl=None, xu=None, A_eq=None, b_eq=None, n_nl_eq=0, eq_nl=None, jac_eq_nl=None, A_ineq=None, b_ineq=None, n_nl_ineq=0, ineq_nl=None, jac_ineq_nl=None, fd_h=1.4901161193847656e-08, fd_mode='forward', use_jax_hessian=False, jax_sparsity_tol=1e-12)[source]¶
Bases:
objectMPCC with explicitly separated linear and nonlinear constraint layers.
- Parameters:
n (int) – Number of decision variables.
n_comp (int) – Number of complementarity pairs (>= 1).
x0 (array-like, shape (n,)) – Initial guess.
objective (callable) –
f(x) -> floatgradient (callable) –
∇f(x) -> ndarray, shape (n,)comp_G (callable) –
G(x) -> ndarray, shape (n_comp,)withG(x) >= 0comp_G_jacobian (callable) –
∇G(x) -> ndarray, shape (n_comp, n)comp_H (callable) –
H(x) -> ndarray, shape (n_comp,)withH(x) >= 0comp_H_jacobian (callable) –
∇H(x) -> ndarray, shape (n_comp, n)xl (array-like, shape (n,), optional) – Lower bounds on x (default:
-inf).xu (array-like, shape (n,), optional) – Upper bounds on x (default:
+inf).b_eq (ndarray, shape (n_lin_eq,), optional)
----------------------------------------
b_eq – Must be supplied together.
0 (Nonlinear inequalities g_nl(x) ≤)
----------------------------------------
n_nl_eq (int) – Number of nonlinear equality constraints (default 0).
eq_nl (callable, optional) –
h_nl(x) -> ndarray, shape (n_nl_eq,)jac_eq_nl (callable, optional) –
∇h_nl(x) -> ndarray, shape (n_nl_eq, n)b_ineq (ndarray, shape (n_lin_ineq,), optional)
-----------------------------------------------
A_ineq (ndarray, shape (n_lin_ineq, n), optional)
b_ineq – Must be supplied together.
0
------------------------------------------
n_nl_ineq (int) – Number of nonlinear inequality constraints (default 0).
ineq_nl (callable, optional) –
g_nl(x) -> ndarray, shape (n_nl_ineq,)jac_ineq_nl (callable, optional) –
∇g_nl(x) -> ndarray, shape (n_nl_ineq, n)derivatives (str | None)
fd_h (float)
fd_mode (Literal['forward', 'central'])
use_jax_hessian (bool)
jax_sparsity_tol (float)
Notes
All Jacobians (linear and nonlinear) must be dense 2-D arrays. Dimensions and callables shapes are validated at construction time by evaluating every callable at
x0.Examples
>>> import numpy as np >>> import pympcc >>> >>> model = pympcc.StructuredMPCC( ... n=3, n_comp=1, ... x0=np.ones(3), ... xl=np.zeros(3), ... objective=lambda x: x[0]**2 + x[1]**2 + x[2]**2, ... gradient=lambda x: 2*x, ... # linear equality: x[0] + x[1] = 1 ... A_eq=np.array([[1.0, 1.0, 0.0]]), ... b_eq=np.array([1.0]), ... # nonlinear equality: x[0]^2 + x[2] = 1 ... n_nl_eq=1, ... eq_nl=lambda x: np.array([x[0]**2 + x[2] - 1.0]), ... jac_eq_nl=lambda x: np.array([[2*x[0], 0.0, 1.0]]), ... # complementarity: x[0] >= 0, x[1] >= 0, x[0]*x[1] = 0 ... comp_G=lambda x: np.array([x[0]]), ... comp_G_jacobian=lambda x: np.array([[1.0, 0.0, 0.0]]), ... comp_H=lambda x: np.array([x[1]]), ... comp_H_jacobian=lambda x: np.array([[0.0, 1.0, 0.0]]), ... ) >>> result = pympcc.solve(model)
- __init__(n, n_comp, x0, objective, comp_G, comp_H, gradient=None, comp_G_jacobian=None, comp_H_jacobian=None, derivatives=None, xl=None, xu=None, A_eq=None, b_eq=None, n_nl_eq=0, eq_nl=None, jac_eq_nl=None, A_ineq=None, b_ineq=None, n_nl_ineq=0, ineq_nl=None, jac_ineq_nl=None, fd_h=1.4901161193847656e-08, fd_mode='forward', use_jax_hessian=False, jax_sparsity_tol=1e-12)¶
- Parameters:
n (int)
n_comp (int)
x0 (ndarray)
derivatives (str | None)
xl (ndarray | None)
xu (ndarray | None)
A_eq (ndarray | None)
b_eq (ndarray | None)
n_nl_eq (int)
A_ineq (ndarray | None)
b_ineq (ndarray | None)
n_nl_ineq (int)
fd_h (float)
fd_mode (Literal['forward', 'central'])
use_jax_hessian (bool)
jax_sparsity_tol (float)
- Return type:
None
Methods
__init__(n, n_comp, x0, objective, comp_G, ...)Assemble a
MPCCProblemfrom the structured constraint layers.Attributes
linear + nonlinear.
linear + nonlinear.
Number of linear equality constraints (rows of
A_eq).Number of linear inequality constraints (rows of
A_ineq).- to_mpcc_problem()[source]¶
Assemble a
MPCCProblemfrom the structured constraint layers.The linear and nonlinear equality (inequality) blocks are stacked in order — linear first, nonlinear second — into a single callable pair suitable for
MPCCProblem.- Return type: