naginterfaces.library.opt.handle_set_property¶
- naginterfaces.library.opt.handle_set_property(handle, ptype, idx)[source]¶
handle_set_property
is a part of the NAG optimization modelling suite and sets a given property to a subset of the decision variables, particularly, it specifies if the variables are integral or continuous.For full information please refer to the NAG Library document for e04rc
https://support.nag.com/numeric/nl/nagdoc_30.2/flhtml/e04/e04rcf.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.- ptypestr
Indicates the property to set for the specified variables. is case insensitive.
Class of properties referring to integrality:
or
The variables will be continuous (the default property).
or
The variables become integer.
or
The variables become binary so they will be able to hold only values 0 or 1. Note that any existing box bounds are preserved. For example, if variable has its bounds set as and becomes binary, its box bounds are not removed and, therefore, the only allowed value will be .
Class of properties referring to linearity.
or
The variables have no special property. If they appear in at least one nonlinear expression (constraints or the objective), they will be assumed to be nonlinear (the default property).
or
The variables will be assumed to be linear in all nonlinear constraints and the objective they might appear.
- idxint, array-like, shape
The index set of variables whose properties will be modified. 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: .
- Notes
After the model has been fully or partially built by calling functions of the NAG optimization modelling suite,
handle_set_property
may be used to change properties of a subset of the variables in the model. The property is given by which refers to the integrality of the variables (continuous, integer or binary) or their linearity (if the variables are linear or generic, see Linearity of the Variables). Both classes of properties can be set independently, however, only one property per class of properties can be chosen (i.e., a variable can be linear and integer but it cannot be continuous and binary at the same time). The properties can be changed multiple times and the last setting is the one used.handle_print()
may be used to display the properties and further details of the problem.See the E04 Introduction for more details about the NAG optimization modelling suite.
Linearity of the Variables
It is sometimes useful in Nonlinear Programming (NLP) problems to distinguish between linear and nonlinear variables and thus give the solvers an extra piece of information to utilize. A variable is said to be linear if its involvement in the whole optimization model is linear, i.e., it appears only in linear expressions. All other variables, if used at all, are nonlinear.
Let’s assume that we have a problem with seven variables with two nonlinear constraints declared by
handle_set_nlnconstr()
and defined as follows:and with a linear objective function, linear constraints. Variables and are not used at all in the definition of and, therefore, they are clearly linear which is automatically detected by the solver. Although and appear in the nonlinear constraints , they are involved only in linear expressions and, therefore, are also linear. These two cannot be detected by the solver because the solver can only see the sparsity pattern defined by
handle_set_nlnconstr()
and a Black Box call-back. In this case, it might be beneficial to set their property as linear using this function. If no property is set, it is assumed that the variables are generic, meaning that they have no special property, and their linearity is auto detected based on the constraints they appear in. Solvers which can exploit this property will describe it in their documentation.