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 — Type
AbstractCallback{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 — Type
DenseCallback{T, VT} < AbstractCallback{T, VT}Wrap an AbstractNLPModel using dense structures.
MadNLP.SparseCallback — Type
SparseCallback{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 — Function
create_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 — Type
AbstractFixedVariableTreatmentAbstract type to define the reformulation of the fixed variables inside MadNLP.
MadNLP.MakeParameter — Type
MakeParameter{VT, VI} <: AbstractFixedVariableTreatmentRemove the fixed variables from the optimization variables and define them as problem's parameters.
MadNLP.RelaxBound — Type
RelaxBound <: AbstractFixedVariableTreatmentRelax the fixed variables $x = x_{fixed}$ as bounded variables $x_{fixed} - ϵ ≤ x ≤ x_{fixed} + ϵ$, with $ϵ$ a small-enough parameter.
MadNLP.AbstractEqualityTreatment — Type
AbstractEqualityTreatmentAbstract type to define the reformulation of the equality constraints inside MadNLP.
MadNLP.EnforceEquality — Type
EnforceEquality <: AbstractEqualityTreatmentKeep the equality constraints intact.
The solution returned by MadNLP will respect the equality constraints.
MadNLP.RelaxEquality — Type
RelaxEquality <: AbstractEqualityTreatmentRelax 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, as well as the indexes of the bounded variables and the fixed variables. The indexes are stored explicitly as a Vector{Int} in the AbstractCallback structure used by MadNLP.