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.AbstractCallbackType
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.

source

The function create_callback allows to instantiate a AbstractCallback from a given NLPModel:

MadNLP.create_callbackFunction
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).

source

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.MakeParameterType
MakeParameter{VT, VI} <: AbstractFixedVariableTreatment

Remove the fixed variables from the optimization variables and define them as problem's parameters.

source
MadNLP.RelaxBoundType
RelaxBound <: AbstractFixedVariableTreatment

Relax the fixed variables $x = x_{fixed}$ as bounded variables $x_{fixed} - ϵ ≤ x ≤ x_{fixed} + ϵ$, with $ϵ$ a small-enough parameter.

source
MadNLP.EnforceEqualityType
EnforceEquality <: AbstractEqualityTreatment

Keep the equality constraints intact.

The solution returned by MadNLP will respect the equality constraints.

source
MadNLP.RelaxEqualityType
RelaxEquality <: 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 $ϵ$.

source

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_constraintsFunction
get_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.
source