pub trait ConstrainedProblem: BasicProblem {
// Required methods
fn num_constraints(&self) -> usize;
fn num_constraint_jacobian_non_zeros(&self) -> usize;
fn constraint(&self, x: &[Number], new_x: bool, g: &mut [Number]) -> bool;
fn constraint_bounds(&self, g_l: &mut [Number], g_u: &mut [Number]) -> bool;
fn constraint_jacobian_indices(
&self,
rows: &mut [Index],
cols: &mut [Index],
) -> bool;
fn constraint_jacobian_values(
&self,
x: &[Number],
new_x: bool,
vals: &mut [Number],
) -> bool;
fn num_hessian_non_zeros(&self) -> usize;
fn hessian_indices(&self, rows: &mut [Index], cols: &mut [Index]) -> bool;
fn hessian_values(
&self,
x: &[Number],
new_x: bool,
obj_factor: Number,
lambda: &[Number],
vals: &mut [Number],
) -> bool;
// Provided methods
fn initial_constraint_multipliers(&self, lambda: &mut [Number]) -> bool { ... }
fn constraint_scaling(&self, _g_scaling: &mut [Number]) -> bool { ... }
}Expand description
Extends the BasicProblem trait to enable equality and inequality constraints.
Equality constraints are enforced by setting the lower and upper bounds for the
constraint to the same value.
This type of problem is the target use case for Ipopt.
NOTE: Although it’s possible to run Quasi-Newton iterations on a constrained problem,
it doesn’t perform well in general, which is the reason why you must also provide the
Hessian callbacks. However, you may still enable L-BFGS explicitly by setting the
“hessian_approximation” Ipopt option to “limited-memory”, in which case you should
simply return false in hessian_indices and hessian_values.
Required Methods§
Sourcefn num_constraints(&self) -> usize
fn num_constraints(&self) -> usize
Number of equality and inequality constraints.
Sourcefn num_constraint_jacobian_non_zeros(&self) -> usize
fn num_constraint_jacobian_non_zeros(&self) -> usize
Number of non-zeros in the constraint Jacobian.
Sourcefn constraint(&self, x: &[Number], new_x: bool, g: &mut [Number]) -> bool
fn constraint(&self, x: &[Number], new_x: bool, g: &mut [Number]) -> bool
Constraint function.
This gives the value of each constraint.
The output slice g is guaranteed to be the same size as num_constraints.
This function is internally called by Ipopt callback eval_g.
Sourcefn constraint_bounds(&self, g_l: &mut [Number], g_u: &mut [Number]) -> bool
fn constraint_bounds(&self, g_l: &mut [Number], g_u: &mut [Number]) -> bool
Specify lower and upper bounds, g_l and g_u respectively, on the constraint function.
Both slices will have the same size as what num_constraints returns.
Sourcefn constraint_jacobian_indices(
&self,
rows: &mut [Index],
cols: &mut [Index],
) -> bool
fn constraint_jacobian_indices( &self, rows: &mut [Index], cols: &mut [Index], ) -> bool
Constraint Jacobian indices.
These are the row and column indices of the
non-zeros in the sparse representation of the matrix.
This function is internally called by Ipopt callback eval_jac_g.
Sourcefn constraint_jacobian_values(
&self,
x: &[Number],
new_x: bool,
vals: &mut [Number],
) -> bool
fn constraint_jacobian_values( &self, x: &[Number], new_x: bool, vals: &mut [Number], ) -> bool
Constraint Jacobian values.
Each value must correspond to the row and
column as specified in constraint_jacobian_indices.
This function is internally called by Ipopt callback eval_jac_g.
Sourcefn num_hessian_non_zeros(&self) -> usize
fn num_hessian_non_zeros(&self) -> usize
Number of non-zeros in the Hessian matrix.
This includes the constraint Hessian.
Sourcefn hessian_indices(&self, rows: &mut [Index], cols: &mut [Index]) -> bool
fn hessian_indices(&self, rows: &mut [Index], cols: &mut [Index]) -> bool
Hessian indices.
These are the row and column indices of the non-zeros
in the sparse representation of the matrix.
This should be a symmetric matrix, fill the lower left triangular half only.
Ensure that you provide coordinates for non-zeros of the
objective and constraint Hessians.
This function is internally called by Ipopt callback eval_h.
Sourcefn hessian_values(
&self,
x: &[Number],
new_x: bool,
obj_factor: Number,
lambda: &[Number],
vals: &mut [Number],
) -> bool
fn hessian_values( &self, x: &[Number], new_x: bool, obj_factor: Number, lambda: &[Number], vals: &mut [Number], ) -> bool
Hessian values.
Each value must correspond to the row and column as
specified in hessian_indices.
Write the objective Hessian values multiplied by obj_factor and constraint
Hessian values multipled by the corresponding values in lambda (the Lagrange
multiplier).
This function is internally called by Ipopt callback eval_h.
Provided Methods§
Sourcefn initial_constraint_multipliers(&self, lambda: &mut [Number]) -> bool
fn initial_constraint_multipliers(&self, lambda: &mut [Number]) -> bool
Construct the initial guess of the constraint multipliers for Ipopt to start with.
The given slice has the same size as num_constraints.
This function should return whether the output slice lambda has been populated with
initial values. If this function returns false, then a zero initial guess will be used.
For convenience, the default implementation initializes constraint multipliers to zero. This is a good guess for any initial point in the interior of the feasible region.
Sourcefn constraint_scaling(&self, _g_scaling: &mut [Number]) -> bool
fn constraint_scaling(&self, _g_scaling: &mut [Number]) -> bool
Provide custom constraint function scaling.
This method is called if the Ipopt option, nlp_scaling_method, is set to user-scaling.
Return true if scaling is provided and false otherwise: if false is returned, Ipopt
will not scale the constraint function.
g_scaling has the same dimensions as the constraint function: the value returned by
num_constraints.
For convenience, this function returns false by default without modifying the g_scaling
slice.