modopt.CasadiProblem
- class modopt.CasadiProblem(x0, name='unnamed_problem', ca_obj=None, ca_con=None, xl=None, xu=None, cl=None, cu=None, x_scaler=1.0, o_scaler=1.0, c_scaler=1.0, grad_free=False, order=1)[source]
Class that wraps CasADi expressions for objective and constraints. Depending on the
orderspecified, this class will automatically generate the expressions for the objective gradient, constraint Jacobian, objective Hessian, Lagrangian, Lagrangian gradient, and Lagrangian Hessian. All expressions will be turned into functions and then wrapped for use withOptimizersubclasses. Vector products (HVP, JVP, VJP) are not supported.- __init__(x0, name='unnamed_problem', ca_obj=None, ca_con=None, xl=None, xu=None, cl=None, cu=None, x_scaler=1.0, o_scaler=1.0, c_scaler=1.0, grad_free=False, order=1)[source]
Initialize the optimization problem with the given design variables, objective, and constraints. Derivatives are automatically generated using CasADi.
- Parameters
- namestr, default=’unnamed_problem’
Problem name assigned by the user.
- x0np.ndarray
Initial guess for design variables.
- ca_objcallable
A Python function that returns the objective function expression in CasADi. Signature: ca_obj(x: ca.MX) -> ca.MX
- ca_concallable
A Python function that returns the constraint function expression in CasADi. Signature: ca_con(x: ca.MX) -> ca.MX
- xlfloat or np.ndarray
Lower bounds on design variables.
- xufloat or np.ndarray
Upper bounds on design variables.
- clfloat or np.ndarray
Lower bounds on constraints.
- cufloat or np.ndarray
Upper bounds on constraints.
- x_scalerfloat or np.ndarray
Scaling factor for design variables.
- o_scalerfloat
Scaling factor for the objective function.
- c_scalerfloat or np.ndarray
Scaling factor for constraints.
- grad_freebool, default=False
Flag to indicate if the problem is gradient-free. If True, CasadiProblem will not generate any derivatives.
- order{1, 2}, default=1
Order of the problem if
grad_free=False. Used for determining up to which order of derivatives need to be generated.
- __str__()
Print the details of the UNSCALED optimization problem.