Callbacks
In MadNLP, a nonlinear program is implemented with a given AbstractNLPModel
. The model may have a form unsuitable for the interior-point algorithm. For that reason, MadNLP wraps the AbstractNLPModel
internally using custom data structures, encoded as a AbstractCallback
. Depending on the setting, choose to wrap the AbstractNLPModel
as a DenseCallback
or alternatively, as a SparseCallback
.
MadNLP.AbstractCallback
— TypeAbstractCallback{T, VT}
Wrap the AbstractNLPModel
passed by the user in a form amenable to MadNLP.
An AbstractCallback
handles the scaling of the problem and the reformulations of the equality constraints and fixed variables.
MadNLP.DenseCallback
— TypeDenseCallback{T, VT} < AbstractCallback{T, VT}
Wrap an AbstractNLPModel
using dense structures.
MadNLP.SparseCallback
— TypeSparseCallback{T, VT} < AbstractCallback{T, VT}
Wrap an AbstractNLPModel
using sparse structures.
The function create_callback
allows to instantiate a AbstractCallback
from a given NLPModel
:
MadNLP.create_callback
— Functioncreate_callback(
::Type{Callback},
nlp::AbstractNLPModel{T, VT};
fixed_variable_treatment=MakeParameter,
equality_treatment=EnforceEquality,
) where {T, VT}
Wrap the nonlinear program nlp
using the callback wrapper with type Callback
. The option fixed_variable_treatment
decides if the fixed variables are relaxed (RelaxBound
) or removed (MakeParameter
). The option equality_treatment
decides if the the equality constraints are keep as is (EnforceEquality
) or relaxed (RelaxEquality
).
Internally, a AbstractCallback
reformulates the inequality constraints as equality constraints by introducing additional slack variables. The fixed variables are reformulated as parameters (using MakeParameter
) or are relaxed (using RelaxBound
). The equality constraints can be keep as is with EnforceEquality
(default option) or relaxed as inequality constraints with RelaxEquality
. In that later case, MadNLP solves a relaxation of the original problem.
MadNLP.AbstractFixedVariableTreatment
— TypeAbstractFixedVariableTreatment
Abstract type to define the reformulation of the fixed variables inside MadNLP.
MadNLP.MakeParameter
— TypeMakeParameter{VT, VI} <: AbstractFixedVariableTreatment
Remove the fixed variables from the optimization variables and define them as problem's parameters.
MadNLP.RelaxBound
— TypeRelaxBound <: AbstractFixedVariableTreatment
Relax the fixed variables $x = x_{fixed}$ as bounded variables $x_{fixed} - ϵ ≤ x ≤ x_{fixed} + ϵ$, with $ϵ$ a small-enough parameter.
MadNLP.AbstractEqualityTreatment
— TypeAbstractEqualityTreatment
Abstract type to define the reformulation of the equality constraints inside MadNLP.
MadNLP.EnforceEquality
— TypeEnforceEquality <: AbstractEqualityTreatment
Keep the equality constraints intact.
The solution returned by MadNLP will respect the equality constraints.
MadNLP.RelaxEquality
— TypeRelaxEquality <: AbstractEqualityTreatment
Relax the equality constraints $g(x) = 0$ with two inequality constraints, as $-ϵ ≤ g(x) ≤ ϵ$. The parameter $ϵ$ is usually small.
The solution returned by MadNLP will satisfy the equality constraints only up to a tolerance $ϵ$.
MadNLP has to keep in memory all the indexes associated to the equality and inequality constraints. Similarly, MadNLP has to keep track of the indexes of the bounded variables and the fixed variables. MadNLP provides a utility get_index_constraints
to import all the indexes required by MadNLP. Each index vector is encoded as a Vector{Int}
.
MadNLP.get_index_constraints
— Functionget_index_constraints(nlp::AbstractNLPModel)
Analyze the bounds of the variables and the constraints in the AbstractNLPModel
nlp
. Return a named-tuple witht the following keys:return (
ind_eq
: indices of equality constraints.ind_ineq
: indices of inequality constraints.ind_fixed
: indices of fixed variables.ind_lb
: indices of variables with a lower-bound.ind_ub
: indices of variables with an upper-bound.ind_llb
: indices of variables with only a lower-bound.ind_uub
: indices of variables with only an upper-bound.