Inequality Constraint Definition
OPTIMake supports the following types of inequality constraints:
general_inequality: General type, defined directly through expressionsexternal_general_inequality: General type, defined through external C/C++ functionssecond_order_cone_inequality: Second-order cone constraint
Additionally, OPTIMake's collision avoidance extension provides direct support for collision avoidance constraints on geometric shapes/occupancy grids, supporting the following types of collision avoidance inequality constraints:
point_to_rectangle_inequality: Point-to-rectangle collision avoidance inequality constraintrectangle_to_rectangle_inequality: Rectangle-to-rectangle collision avoidance inequality constraintpoint_to_occupancy_map_inequality: Point-to-2D occupancy grid collision avoidance inequality constraintpoint_to_boundary_inequality: Point-to-boundary collision avoidance inequality constraint
After defining the constraint, use the following interface to add it:
prob.inequality(ineq, weight_soft, penalty_type)
The function parameters of the inequality interface are defined as follows (see Constraint Transformation for details on constraint softening):
- ineq: The inequality constraint, type can be
general_inequality,external_general_inequality,second_order_cone_inequality, or collision avoidance constraints supported in the collision avoidance extension - weight_soft: The penalty weight when softening this constraint, must be non-negative, can be a constant or an expression in terms of parameter , default value is all inf, indicating a hard constraint This parameter can be a list with the same dimension as the constraint or a single value (meaning the same penalty weight is used for each dimension of the constraint)
- penalty_type: The penalty type for softening this constraint, options are
'none','quadratic','l1', default value is all'none', indicating a hard constraint This parameter can be a list with the same dimension as the constraint or a single value (meaning the same penalty type is used for each dimension of the constraint)
- When the constraint type is
external_general_inequality, prob.inequality can only be called once to set the constraint - For other constraint types, prob.inequality can be called multiple times to add multiple constraints
general_inequality
Below is an example of defining an inequality constraint through general_inequality:
# -1.0 <= x + y <= 1.0
ineq = general_inequality(
expr = [x + y, x + y],
sign = ['>=', '<='],
bound = [-1.0, 1.0])
prob.inequality(ineq)
The parameters of the general_inequality interface are as follows:
- expr: A list of inequality constraint expressions
- sign: A list of inequality constraint signs, options are "<=", ">="
- bound: A list of inequality constraint bounds, which can be constants or expressions in terms of parameter
When all inequality constraints have the same sign and bound, the definition of sign and bound can be simplified. For example, the above inequality constraint can also be implemented as follows:
# -1.0 <= x + y <= 1.0
ineq = general_inequality(
expr = [x + y, -(x + y)],
sign = '<=',
bound = 1.0)
prob.inequality(ineq)
external_general_inequality
A general_inequality defined through external C/C++ functions, with the expression . During modeling, the sparsity of its Jacobian & Hessian can be specified to accelerate computation.
Below is an example of external_general_inequality:
ineq_spy_jac = \
[[1, 1, 0, 0],
[1, 1, 0, 0]]
ineq_spy_hess = \
[[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0]]
ineq = external_general_inequality(
dim = 2,
sparsity_jacobian=ineq_spy_jac,
sparsity_hessian=ineq_spy_hess)
prob.inequality(ineq)
The parameters of the external_general_inequality interface are as follows:
- dim: The dimension of the constraint
- sparsity_jacobian (optional): The sparsity pattern of the Jacobian of , a matrix of dimension dim, where 0 represents sparse and 1 represents dense; default value is all 1.0
- sparsity_hessian (optional): The sparsity pattern of the Hessian of (where z is a Lagrange multiplier of dimension dim), a symmetric matrix of dimension , where 0 represents sparse and 1 represents dense; default value is all 1.0
second_order_cone_inequality
second_order_cone_inequality is used to define second-order cone constraints, with the form . During modeling, a second-order cone constraint can be defined as follows:
# Define second-order cone constraint: ||x1||_2 <= x0
ineq = second_order_cone_inequality(x0, x1)
prob.inequality(ineq)
The parameters of the second_order_cone_inequality interface are as follows:
- x0: The expression for the scalar part of the second-order cone constraint, can be a constant, an expression in terms of parameter , or an expression in terms of optimization variable
- x1: The expressions for the vector part of the second-order cone constraint, a list of expressions in terms of optimization variable
x0 or x1 can be nonlinear expressions in terms of optimization variable v, in which case the second-order cone constraint is a nonlinear second-order cone constraint