Skip to main content
Version: v0.7.0 beta

Initial and Terminal Constraint Definition

The initial constraint describes the equality constraint on the first optimization variable v1v_1, such as the vehicle initial state constraint in a vehicle trajectory planning problem.

The terminal constraint describes the equality constraint on the last optimization variable vNv_N, such as the terminal zero-velocity constraint in a rocket landing trajectory planning problem.

OPTIMake supports the following types of equality constraints for the initial and terminal points:

  • general_equality: General type, defined directly through expressions
  • external_general_equality: General type, defined through external C/C++ functions

After defining the constraint, use the following interfaces to add initial and terminal constraints:

prob.start_equality(eq, weight_soft, penalty_type)
prob.end_equality(eq, weight_soft, penalty_type)

The function parameters of the start_equality/end_equality interfaces are defined as follows (see Constraint Transformation for details on constraint softening):

  • eq: The equality constraint, type can be general_equality, external_general_equality
  • weight_soft: The penalty weight when softening this constraint, must be non-negative, can be a constant or an expression in terms of parameter pp, 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)
info
  • When the constraint type is external_general_equality, prob.start_equality/end_equality can only be called once to set the constraint
  • For other constraint types, prob.start_equality/end_equality can be called multiple times to add multiple constraints

general_equality

Below is an example of defining initial and terminal constraints through general_equality:

# x0, y0, phi0 are previously defined parameters
start_eq = general_equality(expr = [x - x0, y - y0, phi - phi0])
prob.start_equality(start_eq)

# xN, yN, phiN are previously defined parameters
end_eq = general_equality(expr = [x - xN, y - yN, phi - phiN])
prob.end_equality(end_eq)

The function parameters are defined as follows:

  • expr: A list of constraint expressions

external_general_equality

Below is an example of defining initial and terminal constraints through external_general_equality:

eq_spy_jac = \
[[1, 0, 0, 0],
[0, 1, 0, 0],
[0, 0, 1, 0]]
eq_spy_hess = \
[[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0]]

start_eq = external_general_equality(
dim = 3,
sparsity_jacobian=seq_spy_jac,
sparsity_hessian=seq_spy_hess)

end_eq = external_general_equality(
dim = 3,
sparsity_jacobian=seq_spy_jac,
sparsity_hessian=seq_spy_hess)

The parameters of the external_general_equality interface are as follows:

  • dim: The dimension of the constraint
  • sparsity_jacobian (optional): The sparsity pattern of the Jacobian of f(v,p)f(v, p), a matrix of dimension dim×nv\times n_{v}, where 0 represents sparse and 1 represents dense; default value is all 1.0
  • sparsity_hessian (optional): The sparsity pattern of the Hessian of yTf(v,p)y^T f(v, p) (where z is a Lagrange multiplier of dimension dim×1\times 1), a symmetric matrix of dimension nv×nvn_{v} \times n_{v}, where 0 represents sparse and 1 represents dense; default value is all 1.0