Skip to main content
Version: v0.7.0 beta

Objective Definition

The objective is the objective function to be minimized. OPTIMake supports the following types of objective definitions:

  • general_objective: General type, defined directly through expressions
  • least_square_objective: Least square type
  • external_general_objective: General type, defined through external C/C++ functions

After defining the objective, use the following interface to minimize it:

prob.objective(obj)

Similarly, use the following interface to add an objective for the last stage:

prob.end_objective(obj)
info
  • prob.objective or prob.end_objective can only be called once to set the objective

general_objective

Below is an example of defining an objective directly through expressions:

# wyref, wphi are previously defined parameters
obj = general_objective(wxref * (x * sin(phi) - xref)**2 + wyref * (y - yref)**2 + wphi * phi**2 + 0.01 * delta**2 + 0.1 * v**2)
prob.objective(obj)

least_square_objective

When the objective has the following form, it can be defined through the least square interface, where rj(v,p)r_j(v, p) is the residual term and wj(p)w_j(p) is the corresponding weight term.

l(vi,p)=12jwj(p)rj2(vi,p) l(v_i, p) = \frac{1}{2}\sum_{j}w_j(p) r^2_j(v_i, p)

Below is an example of defining an objective through the least square interface:

r = [x * sin(phi) - xref, y - yref, phi, delta, v]
w = [wxref, wyref, wphi, 0.01, 0.1]
obj = least_square_objective(residuals=r, weights=w)
prob.objective(obj)

The function parameters of the least_square_objective interface are defined as follows:

  • residuals: The residual terms, corresponding to r(v,p)r(v, p), type is list
  • weights (optional): The residual weights, corresponding to w(p)w(p), can be a list of constants or expressions in terms of parameter pp, default value is a list of all 1.0
info

When the objective is defined through the least square interface, its Hessian is approximately computed using the Gauss-Newton method.

external_general_objective

A general_objective defined through external C/C++ functions. During modeling, the sparsity of its Hessian can be specified to accelerate computation.

Below is an example of defining an objective through the external_general_objective interface:

obj_spy_hess = \
[[1, 0, 0, 0],
[0, 1, 0, 0],
[0, 0, 1, 0],
[0, 0, 0, 1]]
obj = external_general_objective(sparsity_hessian=obj_spy_hess)
prob.objective(obj)

The parameters of the external_general_objective interface are as follows:

  • sparsity_hessian (optional): The sparsity pattern of the objective's Hessian, a symmetric matrix of dimension nv×nvn_{v} \times n_{v}, where 0 represents sparse and 1 represents dense; this is an optional parameter with a default value of all 1.0