Applications may define functions for evaluating problem elements given a current solution. This section of the documentation details the function signatures expected for the callbacks.
Returns the value of the objective function at the current solution x
:
function eval_f(x::Vector{Float64}) # (length n) Current Solution
# ...
return obj_value
end
Sets the value of the constraint functions g
at the current solution x
:
function eval_g(x::Vector{Float64}, # (length n) Current Solution
cons::Vector{Float64}) # (length m) Constraint values g(x)
# ...
# cons[1] = ...
# ...
# cons[prob.m] = ...
end
Note that the values of cons
must be set "in-place", i.e. the statement cons = zeros(prob.m)
musn't be done. If you do want to create a new vector and allocate it to cons
use cons[:]
, e.g. cons[:] = zeros(prob.m)
.
Sets the value of the gradient of the objective function at the current solution x
:
function eval_grad_f(x::Vector{Float64}, # (length n) Current Solution
grad::Vector{Float64}) # (length n) The gradient of the objective function
# ...
# grad[1] = ...
# ...
# grad[prob.n] = ...
end
As with eval_g
, you must set the values "in-place" for eval_grad_f
.
This function returns the values of the Jacobian, evaluated at the non-negative indices, based on the sparsity structure passed to KNITRO through initializeProblem
. Julia is 1-based, in the sense that indexing always starts at 1 (unlike C, which starts at 0).:
function eval_jac_g(x::Vector{Float64}, # (length n) Current Solution
jac::Vector{Float64}) # (length nnzJ) The values of the Jacobian
# ...
# jac[1] = ...
# ...
# jac[nnzJ] = ... # where nnzJ = length(jac)
end
As for the previous two callbacks, all values must be set "in-place". See the Ipopt documentation for a further description of the sparsity format followed by Ipopt ((row,column,value) triples).
Similar to the Jacobian, except for the Hessian of the Lagrangian. See documentation for full details of the meaning of everything.:
function eval_h(x::Vector{Float64}, # (length n) Current solution
lambda::Vector{Float64}, # (length n+m) Multipliers for each constraint
sigma::Float64, # Lagrangian multiplier for objective
hess::Vector{Float64}) # (length nnzH) The values of the Hessian
# ...
# hess[1] = ...
# ...
# hess[nnzH] = ... # where nnzH = length(hess)
end
Computes the Hessian-of-the-Lagrangian-vector product, storing the result in the vector hv
.:
function eval_hv(x::Vector{Float64}, # (length n) Current solution
lambda::Vector{Float64}, # (length n+m) Multipliers for each constraint
sigma::Float64, # Lagrangian multiplier for objective
hess::Vector{Float64}) # (length n) Hessian-of-the-Lagrangian-vector product
# ...
# hv[1] = ...
# ...
# hv[end] = ...
end