naginterfaces.library.opt.handle_disable¶
- naginterfaces.library.opt.handle_disable(handle, comp, idx)[source]¶
handle_disable
is a part of the NAG optimization modelling suite and allows you to disable various components of an existing model.For full information please refer to the NAG Library document for e04tc
https://www.nag.com/numeric/nl/nagdoc_29/flhtml/e04/e04tcf.html
- Parameters
- handleHandle
The handle to the problem. It needs to be initialized (e.g., by
handle_init()
) and must not be changed between calls to the NAG optimization modelling suite.- compstr
The type of the component of the model to be disabled. is case insensitive.
, or
Decision variables .
or
Linear constraints (see
handle_set_linconstr()
).or
Quadratic constraints (see
handle_set_qconstr()
andhandle_set_qconstr_fac()
).or
Nonlinear constraints (see
handle_set_nlnconstr()
).or
Quadratic or rotated quadratic cones (see
handle_set_group()
).or
Matrix inequality constraints (see
handle_set_linmatineq()
).or
Nonlinear residuals in the nonlinear least squares objective function (see
handle_set_nlnls()
).- idxint, array-like, shape
The index set of components to be disabled. The elements may be supplied in any order.
- Raises
- NagValueError
- (errno )
has not been initialized.
- (errno )
does not belong to the NAG optimization modelling suite, has not been initialized properly or is corrupted.
- (errno )
has not been initialized properly or is corrupted.
- (errno )
The problem cannot be modified right now, the solver is running.
- (errno )
On entry, .
Constraint: .
- (errno )
On entry, .
Constraint: , , , , , or .
- (errno )
On entry, , , and .
Constraint: .
- (errno )
On entry, and .
This component has been deleted.
- Notes
handle_disable
andhandle_enable()
form a pair of functions which allow you to quickly remove parts of the model and add them back. This is particularly useful when a sequence of similar problems needs to be solved, to identify how a particular constraint or variable affects the solution, or to switch between previously defined constraints which are somewhat related to each other.After the model has been fully or partially built by calling functions of the NAG optimization modelling suite,
handle_disable
may be used to disable some components (variables or constraints) from the model. To identify the part of the model to be disabled, the component type needs to be specified in together with the appropriate component indices, such as variable or linear constraint numbers, in an index set .handle_enable()
may be used to bring them back (to enable them). Note that a disabled component may still be edited but would not be automatically re-enabled; a disabled component can only be enabled by callinghandle_enable()
. By default, all newly created components of the model are enabled. Calling this function on disabled components is not an error but has no effect.In general, disabled components are still present in the model with respect to the numbering of the variables and constraints (e.g., disabling a variable will not renumber the remaining variables) but the solver will ignore them and work internally with a smaller model formulation. The solver will communicate with you (e.g., return results) in arrays matching the full size of the model and the elements corresponding to the disabled components will be set to NaN, which can be tested for via a call to
ieee.is_nan
. The effect of disabling components is described in detail as follows:- Decision variables
As a rule, a disabled variable behaves as if the existing parts of the model were defined without the variable in the first place. Matching elements in all other model components are ignored. In particular, the following applies:
elements in the linear or quadratic objective function corresponding to the disabled variables are ignored, as if they were set to 0;
the same applies to the linear and quadratic constraints as well as to the matrix inequalities, however, note that this can generate infeasible constraints (for instance, with disabled and is interpreted as and thus would be infeasible);
the box bounds of the disabled variables are ignored;
if a disabled variable is present in a cone constraint and the cone constraint becomes invalid (e.g., the length of the cone is just one or the first cone variable is disabled), the whole constraint is disabled as well;
any callbacks for nonlinear function evaluation will have on input the full vector, however, all disabled variables are set to NaN and the matching elements in the returned derivatives are not referenced.
An alternative approach is to fix the variable to a predefined value by changing its simple bounds using
handle_set_bound()
instead of disabling it.- Linear constraints, Quadratic constraints, Second-order cones, Matrix inequalities
Disabled constraints do not restrict the feasible set, they are eliminated before the model is presented to the solver. As the constraints are not renumbered, the position for Lagrangian multipliers (, , ) is unchanged and NaNs are returned in place of disabled constraints.
- Nonlinear constraints
The disabled nonlinear constraints do not affect the feasible set and their Lagrangian multipliers are returned as NaNs in their expected location. The values of the nonlinear constraints and their partial derivatives are passed to the solver via callbacks, such as, and . The size of all array arguments in the callbacks remain the same, irrespective of the number of disabled constraints. On exit from the callback any elements in these arrays corresponding to the disabled constraints are not referenced.
- Nonlinear residuals
The disabled residuals in the nonlinear least squares objective function are skipped in the sum and their values are not referenced.
See the E04 Introduction for more details about the NAG optimization modelling suite.