naginterfaces.library.mip.iqp_dense¶
- naginterfaces.library.mip.iqp_dense(bl, bu, h, intvar, xs, strtgy, comm, a=None, cvec=None, qphess=None, mdepth=None, istate=None, monit=None, data=None, io_manager=None)[source]¶
iqp_dense
solves general quadratic programming problems with integer constraints on the variables. It is not intended for large sparse problems.Note: this function uses optional algorithmic parameters, see also:
iqp_dense_optfile()
,iqp_dense_optstr()
.For full information please refer to the NAG Library document for h02cb
https://support.nag.com/numeric/nl/nagdoc_30.2/flhtml/h/h02cbf.html
- Parameters
- blfloat, array-like, shape
must contain the lower bounds and the upper bounds, for all the constraints in the following order. The first elements of each array must contain the bounds on the variables, and the next elements the bounds for the general linear constraints (if any). To specify a nonexistent lower bound (i.e., ), set , and to specify a nonexistent upper bound (i.e., ), set ; the default value of is , but this may be changed by the ‘Infinite Bound Size’. To specify the th constraint as an equality, set , say, where .
- bufloat, array-like, shape
must contain the lower bounds and the upper bounds, for all the constraints in the following order. The first elements of each array must contain the bounds on the variables, and the next elements the bounds for the general linear constraints (if any). To specify a nonexistent lower bound (i.e., ), set , and to specify a nonexistent upper bound (i.e., ), set ; the default value of is , but this may be changed by the ‘Infinite Bound Size’. To specify the th constraint as an equality, set , say, where .
- hfloat, array-like, shape
May be used to store the quadratic term of the QP objective function if desired. In some cases, you need not use to store explicitly (see the specification of ). The elements of are referenced only by . The number of rows of is denoted by , whose default value is . (The ‘Hessian Rows’ may be used to specify a value of .)
If the default version of is used and the problem is of type QP1 or QP2 (the default), the first rows and columns of must contain the leading rows and columns of the symmetric Hessian matrix .
Only the diagonal and upper triangular elements of the leading rows and columns of are referenced.
The remaining elements need not be assigned.
If the default version of is used and the problem is of type QP3 or QP4, the first rows of must contain an upper trapezoidal factor of the symmetric Hessian matrix .
The factor need not be of full rank, i.e., some of the diagonal elements may be zero.
However, as a general rule, the larger the dimension of the leading nonsingular sub-matrix of , the fewer iterations will be required.
Elements outside the upper trapezoidal part of the first rows of need not be assigned.
In other situations, it may be desirable to compute or without accessing – for example, if or is sparse or has special structure.
The arguments and may then refer to any convenient array.
If the problem is of type FP or LP, is not referenced.
- intvarint, array-like, shape
must contain the index of the solution vector which is required to be integer. For example, if and are constrained to take integer values then might be set to and to . The order in which the indices are specified is important, since this determines the order in which the sub-problems are generated. As a rule-of-thumb, the important variables should always be specified first. Thus, in the above example, if relates to a more important quantity than , then it might be advantageous to set and . If is the smallest integer such that is less than or equal to zero then
iqp_dense
assumes that variables are constrained to be integer; components , , are not referenced.- xsfloat, array-like, shape
An initial estimate of the solution.
- strtgyint
Determines a branching strategy to be used throughout the computation, as follows:
Meaning
Always left branch first, i.e., impose an upper bound constraint on the variable first.
Always right branch first, i.e., impose a lower bound constraint on the variable first.
Branch towards the nearest integer, i.e., if then impose an upper bound constraint , whereas if then impose the lower bound constraint .
A random choice is made between a left-hand and a right-hand branch.
- commdict, communication object, modified in place
Communication structure.
This argument must have been initialized by a prior call to
opt.nlp1_init
with .- aNone or float, array-like, shape , optional
Note: the required extent for this argument in dimension 2 is determined as follows: if : ; if : ; otherwise: .
The th row of must contain the coefficients of the th general linear constraint, for .
- cvecNone or float, array-like, shape , optional
The coefficients of the explicit linear term of the objective function when the problem is of type LP, QP2 (the default) and QP4.
If the problem is of type FP, QP1, or QP3, is not referenced.
- qphessNone or callable hx = qphess(jthcol, h, x, data=None), optional
Note: if this argument is None then a NAG-supplied facility will be used.
In general, you need not provide a version of , because supplying None will cause a ‘default’ function to be used.
However, the algorithm of
iqp_dense
requires only the product of or and a vector ; and in some cases you may obtain increased efficiency by providing a version of that avoids the need to define the elements of the matrices or explicitly. is not referenced if the problem is of type FP or LP, in which case may be None.- Parameters
- jthcolint
Specifies whether or not the vector is a column of the identity matrix.
The vector is the th column of the identity matrix, and hence or is the th column of or , respectively, which may in some cases require very little computation and may be coded to take advantage of this. However special code is not necessary because is always stored explicitly in the array .
has no special form.
- hfloat, ndarray, shape
This is the same argument as supplied to
iqp_dense
.- xfloat, ndarray, shape
The vector .
- dataarbitrary, optional, modifiable in place
User-communication data for callback functions.
- Returns
- hxfloat, array-like, shape
The product if the problem is of type QP1 or QP2 (the default), or the product if the problem is of type QP3 or QP4.
- mdepthNone or int, optional
Note: if this argument is None then a default value will be used, determined as follows: .
The maximum depth (i.e., number of extra constraints) that
iqp_dense
may insert before admitting failure.- istateNone or int, array-like, shape , optional
Need not be set if the (default) option ‘Cold Start’ is used.
If the option ‘Warm Start’ has been chosen, specifies the desired status of the constraints at the start of the feasibility phase.
More precisely, the first elements of refer to the upper and lower bounds on the variables, and the next elements refer to the general linear constraints (if any).
Possible values for are as follows:
Meaning
0
The corresponding constraint should not be in the initial working set.
1
The constraint should be in the initial working set at its lower bound.
2
The constraint should be in the initial working set at its upper bound.
3
The constraint should be in the initial working set as an equality. This value must not be specified unless .
The values , and are also acceptable but will be reset to zero by the function.
If
iqp_dense
has been called previously with the same values of and , already contains satisfactory information. (See also the description of the option ‘Warm Start’.) The function also adjusts (if necessary) the values supplied in to be consistent with .- monitNone or callable (bstval, halt, count) = monit(intfnd, nodes, depth, obj, x, bstval, bstsol, bl, bu, halt, count, data=None), optional
Note: if this argument is None then a NAG-supplied facility will be used.
may be used to print out intermediate output and to affect the course of the computation.
Specifically, it allows you to specify a realistic value for the cut-off value (see Notes) and to terminate the algorithm.
If you do not require any intermediate output, have no estimate of the cut-off value and require an exhaustive tree search then may be None.
- Parameters
- intfndint
Specifies the number of integer solutions obtained so far.
- nodesint
Specifies the number of nodes (sub-problems) solved so far.
- depthint
Specifies the depth in the tree of sub-problems the algorithm has now reached.
- objfloat
Specifies the value of the objective function of the end of the latest sub-problem.
- xfloat, ndarray, shape
Specifies the values of the independent variables at the end of the latest sub-problem.
- bstvalfloat
Normally specifies the value of the best integer solution found so far.
- bstsolfloat, ndarray, shape
Specifies the solution vector which gives rise to the best integer solution value so far discovered.
- blfloat, ndarray, shape
specifies the current lower bounds on the variable .
- bufloat, ndarray, shape
specifies the current upper bounds on the variable .
- haltbool
Will have the value .
- countint
Unchanged from previous call.
- dataarbitrary, optional, modifiable in place
User-communication data for callback functions.
- Returns
- bstvalfloat
May be set to a cut-off value if you are an experienced user as follows. Before an integer solution has been found will be set by
iqp_dense
to the largest machine representable number (seemachine.real_largest
). If you know that the solution being sought is a much smaller number, then may be set to this number as a cut-off value (see Notes). Beware of setting too small, since then no integer solutions will be discovered. Also, on entry to , should be set using a statement of the formif intfnd == 0: bstval = cut_off_value
Setting in this way will not prevent the normal operation of the algorithm when subsequent integer solutions are found. It would be a grievous mistake to unconditionally set and if you have any doubts whatsoever about the correct use of this argument then you are strongly recommended to leave it unchanged.
- haltbool
If is set to ,
opt.qp_dense_solve
will be brought to a halt with = -1. This facility may be useful if you are content with any integer solution, or with any integer solution that fits certain criteria. Under these circumstances setting can save considerable unnecessary computation.- countint
May be used by you to save the last value of . If a subsequent call of has a value of which is greater than , then you know that a new integer solution has been found at this node.
- dataarbitrary, optional
User-communication data for callback functions.
- io_managerFileObjManager, optional
Manager for I/O in this routine.
- Returns
- istateint, ndarray, shape
The status of the constraints in the working set at the point returned in . The significance of each possible value of is as follows:
Meaning
The constraint violates its lower bound by more than the feasibility tolerance.
The constraint violates its upper bound by more than the feasibility tolerance.
The constraint is satisfied to within the feasibility tolerance, but is not in the working set.
This inequality constraint is included in the working set at its lower bound.
This inequality constraint is included in the working set at its upper bound.
This constraint is included in the working set as an equality. This value of can occur only when .
This corresponds to optimality being declared with being temporarily fixed at its current value. This value of can occur only when = 1 on exit.
- xsfloat, ndarray, shape
The point at which
iqp_dense
terminated. If the function exits successfully or = 1 or 3, contains an estimate of the solution.- objfloat
The value of the objective function at if is feasible, or the sum of infeasibilities at otherwise. If the problem is of type FP and is feasible, is set to zero.
- axNone or float, ndarray, shape
The final values of the linear constraints .
- clamdafloat, ndarray, shape
The values of the Lagrange-multipliers for each constraint with respect to the current working set. The first elements contain the multipliers for the bound constraints on the variables, and the next elements contain the multipliers for the general linear constraints (if any). If (i.e., constraint is not in the working set), is zero. If is optimal, should be non-negative if , non-positive if and zero if .
- Other Parameters
- ‘Check Frequency’int
Default
Every th iteration, a numerical test is made to see if the current solution satisfies the constraints in the working set. If the largest residual of the constraints in the working set is judged to be too large, the current working set is refactorized and the variables are recomputed to satisfy the constraints more accurately. If , the default value is used.
- ‘Cold Start’valueless
Default
This option specifies how the initial working set is chosen. With a ‘Cold Start’,
iqp_dense
chooses the initial working set based on the values of the variables and constraints at the initial point. Broadly speaking, the initial working set will include equality constraints and bounds or inequality constraints that violate or ‘nearly’ satisfy their bounds (to within ‘Crash Tolerance’).With a ‘Warm Start’, you must provide a valid definition of every element of the array (see Parameters for the definition of this array).
iqp_dense
will override your specification of if necessary, so that a poor choice of the working set will not cause a fatal error. For instance, any elements of which are set to , or will be reset to zero, as will any elements which are set to when the corresponding elements of and are not equal. A warm start will be advantageous if a good estimate of the initial working set is available – for example, wheniqp_dense
is called repeatedly to solve related problems.- ‘Warm Start’valueless
This option specifies how the initial working set is chosen. With a ‘Cold Start’,
iqp_dense
chooses the initial working set based on the values of the variables and constraints at the initial point. Broadly speaking, the initial working set will include equality constraints and bounds or inequality constraints that violate or ‘nearly’ satisfy their bounds (to within ‘Crash Tolerance’).With a ‘Warm Start’, you must provide a valid definition of every element of the array (see Parameters for the definition of this array).
iqp_dense
will override your specification of if necessary, so that a poor choice of the working set will not cause a fatal error. For instance, any elements of which are set to , or will be reset to zero, as will any elements which are set to when the corresponding elements of and are not equal. A warm start will be advantageous if a good estimate of the initial working set is available – for example, wheniqp_dense
is called repeatedly to solve related problems.- ‘Crash Tolerance’float
Default
This value is used in conjunction with the option ‘Cold Start’ (the default value) when
iqp_dense
selects an initial working set. If , the initial working set will include (if possible) bounds or general inequality constraints that lie within of their bounds. In particular, a constraint of the form will be included in the initial working set if . If or , the default value is used.- ‘Defaults’valueless
This special keyword may be used to reset all options to their default values.
- ‘Expand Frequency’int
Default
This option is part of an anti-cycling procedure designed to guarantee progress even on highly degenerate problems.
The strategy is to force a positive step at every iteration, at the expense of violating the constraints by a small amount. Suppose that the value of the option ‘Feasibility Tolerance’ is . Over a period of iterations, the feasibility tolerance actually used by
iqp_dense
(i.e., the working feasibility tolerance) increases from to (in steps of ).At certain stages the following ‘resetting procedure’ is used to remove constraint infeasibilities. First, all variables whose upper or lower bounds are in the working set are moved exactly onto their bounds. A count is kept of the number of nontrivial adjustments made. If the count is positive, iterative refinement is used to give variables that satisfy the working set to (essentially) machine precision. Finally, the working feasibility tolerance is reinitialized to .
If a problem requires more than iterations, the resetting procedure is invoked and a new cycle of iterations is started with incremented by . (The decision to resume the feasibility phase or optimality phase is based on comparing any constraint infeasibilities with .)
The resetting procedure is also invoked when
iqp_dense
reaches an apparently optimal, infeasible or unbounded solution, unless this situation has already occurred twice. If any nontrivial adjustments are made, iterations are continued.If , the default value is used. If , no anti-cycling procedure is invoked.
- ‘Feasibility Phase Iteration Limit’int
Default
The scalars and specify the maximum number of iterations allowed in the feasibility and optimality phases. ‘Optimality Phase Iteration Limit’ is equivalent to ‘Iteration Limit’. Setting and means that the workspace needed will be computed and printed, but no iterations will be performed. If or , the default value is used.
- ‘Optimality Phase Iteration Limit’int
Default
The scalars and specify the maximum number of iterations allowed in the feasibility and optimality phases. ‘Optimality Phase Iteration Limit’ is equivalent to ‘Iteration Limit’. Setting and means that the workspace needed will be computed and printed, but no iterations will be performed. If or , the default value is used.
- ‘Feasibility Tolerance’float
Default
If , defines the maximum acceptable absolute violation in each constraint at a ‘feasible’ point. For example, if the variables and the coefficients in the general constraints are of order unity, and the latter are correct to about decimal digits, it would be appropriate to specify as . If , the default value is used.
iqp_dense
attempts to find a feasible solution before optimizing the objective function. If the sum of infeasibilities cannot be reduced to zero, the ‘Minimum Sum of Infeasibilities’ can be used to find the minimum value of the sum. Let Sinf be the corresponding sum of infeasibilities. If Sinf is quite small, it may be appropriate to raise by a factor of or . Otherwise, some error in the data should be suspected.Note that a ‘feasible solution’ is a solution that satisfies the current constraints to within the tolerance .
- ‘Hessian Rows’int
Default
Note that this option does not apply to problems of type FP or LP.
This specifies , the number of rows of the Hessian matrix . The default value of is , the number of variables of the problem.
If the problem is of type QP, will usually be , the number of variables. However, a value of less than is appropriate for QP3 or QP4 if is an upper trapezoidal matrix with rows. Similarly, may be used to define the dimension of a leading block of nonzeros in the Hessian matrices of QP1 or QP2, in which case the last rows and columns of are assumed to be zero. In the QP case, should not be greater than ; if it is, the last rows of are ignored.
If or , the default value is used.
- ‘Infinite Bound Size’float
Default
If , defines the ‘infinite’ bound in the definition of the problem constraints. Any upper bound greater than or equal to will be regarded as (and similarly any lower bound less than or equal to will be regarded as ). If , the default value is used.
- ‘Infinite Step Size’float
Default
If , specifies the magnitude of the change in variables that will be considered a step to an unbounded solution. (Note that an unbounded solution can occur only when the Hessian is not positive definite.) If the change in during an iteration would exceed the value of , the objective function is considered to be unbounded below in the feasible region. If , the default value is used.
- ‘Iteration Limit’int
Default
See option ‘Feasibility Phase Iteration Limit’.
- ‘Iters’int
Default
See option ‘Feasibility Phase Iteration Limit’.
- ‘Itns’int
Default
See option ‘Feasibility Phase Iteration Limit’.
- ‘List’valueless
Option ‘List’ enables printing of each option specification as it is supplied. ‘Nolist’ suppresses this printing.
- ‘Nolist’valueless
Default
Option ‘List’ enables printing of each option specification as it is supplied. ‘Nolist’ suppresses this printing.
- ‘Maximum Degrees of Freedom’int
Default
Note that this option does not apply to problems of type FP or LP.
This places a limit on the storage allocated for the triangular factor of the reduced Hessian . Ideally, should be set slightly larger than the value of expected at the solution. It need not be larger than , where is the number of variables that appear nonlinearly in the quadratic objective function. For many problems it can be much smaller than .
For quadratic problems, a minimizer may lie on any number of constraints, so that may vary between and . The default value of is, therefore, the number of variables . If ‘Hessian Rows’ is specified, the default value of is the same number, .
- ‘Minimum Sum of Infeasibilities’str
Default
If no feasible point exists for the constraints, this option is used to control whether or not
iqp_dense
will calculate a point that minimizes the constraint violations. If ,iqp_dense
will terminate as soon as it is evident that no feasible point exists for the constraints. The final point will generally not be the point at which the sum of infeasibilities is minimized. If ,iqp_dense
will continue until the sum of infeasibilities is minimized.- ‘Monitoring File’int
Default
If and , monitoring information produced by
iqp_dense
at every iteration is sent to a file with logical unit number . If and/or , no monitoring information is produced.- ‘Optimality Tolerance’float
Default
If , defines the tolerance used to determine if the bounds and general constraints have the right ‘sign’ for the solution to be judged to be optimal.
If , the default value is used.
- ‘Print Level’int
Default
The value of controls the amount of printout produced by
iqp_dense
, as indicated below. A detailed description of the printed output is given in Further Comments (summary output at each iteration and the final solution) and Monitoring Information (monitoring information at each iteration). If , the default value is used.The following printout is sent to the file object associated with the advisory I/O unit (see
FileObjManager
):Output
No output.
The final solution only.
One line of summary output ( characters; see Further Comments) for each iteration (no printout of the final solution).
The final solution and one line of summary output for each iteration.
The following printout is sent to the logical unit number defined by the ‘Monitoring File’:
Output
No output.
One long line of output ( characters; see Monitoring Information) for each iteration (no printout of the final solution).
At each iteration, the Lagrange-multipliers, the variables , the constraint values and the constraint status.
At each iteration, the diagonal elements of the upper triangular matrix associated with the factorization (3) (see Definition of the Search Direction) of the working set, and the diagonal elements of the upper triangular matrix .
If and the unit number defined by ‘Monitoring File’ is the advisory unit number, then the summary output is suppressed.
- ‘Problem Type’str
Default QP2
This option specifies the type of objective function to be minimized during the optimality phase. The following are the five optional keywords and the dimensions of the arrays that must be specified in order to define the objective function:
LP
not referenced, length- required;
QP1
rank- symmetric, not referenced;
QP2
rank- symmetric, length- required;
QP3
rank- upper trapezoidal, not referenced;
QP4
rank- upper trapezoidal, length- required.
For problems of type FP, the objective function is omitted and neither nor are referenced.
The following keywords are also acceptable.
Option
Quadratic
QP2
Linear
LP
Feasible
FP
In addition, the keyword QP is equivalent to the default option QP2.
If , i.e., the objective function is purely linear, the efficiency of
iqp_dense
may be increased by specifying as LP.- ‘Rank Tolerance’float
Default
Note that this option does not apply to problems of type FP or LP.
This argument enables you to control the condition number of the triangular factor (see Algorithmic Details). If denotes the function , the dimension of is defined to be smallest index such that . If , the default value is used.
- Raises
- NagValueError
- (errno )
Invalid input argument for basic problem.
- (errno )
On entry, .
Constraint: , , or .
- (errno )
On entry, .
Constraint: .
- (errno )
On entry, .
Constraint: .
- (errno )
On entry, .
Constraint: .
- (errno )
On entry, .
Constraint: .
- (errno )
No integer solutions found.
- (errno )
Need to increase depth, .
- (errno )
Basic problem (without integer constraints) unbounded.
- (errno )
Basic problem is infeasible.
- (errno )
Basic problem requires too many iterations.
- (errno )
Basic problem has a reduced Hessian exceeding assigned dimensions.
- (errno )
Error in designated problem type.
- (errno )
Unexpected error in NAG function – contact NAG.
- Warns
- NagAlgorithmicWarning
- (errno )
Halted at your request.
- Notes
No equivalent traditional C interface for this routine exists in the NAG Library.
iqp_dense
uses a ‘Branch and Bound’ algorithm in conjunction withopt.qp_dense_solve
to try and determine integer solutions to a general quadratic programming problem. The problem is assumed to be stated in the following general form:where is an matrix and may be specified in a variety of ways depending upon the particular problem to be solved. The available forms for are listed in Table [label omitted], in which the prefixes FP, LP and QP stand for ‘feasible point’, ‘linear programming’ and ‘quadratic programming’ respectively and is an -element vector.
Problem type
Matrix
FP
Not applicable
Not applicable
LP
Not applicable
QP1
symmetric
QP2
symmetric
QP3
upper trapezoidal
QP4
upper trapezoidal
Only when the problem is linear or the matrix is positive definite can the technique be guaranteed to work; but often useful results can be obtained for a wider class of problems.
The default problem type is QP2 and other objective functions are selected by using the option ‘Problem Type’. For problems of type FP, the objective function is omitted and
iqp_dense
attempts to find a feasible point for the set of constraints.Branch and bound consists firstly of obtaining a solution without any of the variables constrained to be integer. Suppose ought to be integer, but at the optimal value just computed . A constraint is added to the system and the second problem solved. A constraint gives rise to a third sub-problem. In a similar manner a whole series of sub-problems may be generated, corresponding to integer constraints on the variables. The sub-problems are all solved using
opt.qp_dense_solve
.In practice the function tries to compute an integer solution as quickly as possible using a depth-first approach, since this helps determine a realistic cut-off value. If we have a cut-off value, say the value of the function at this first integer solution, and any sub-problem, say, has a solution value greater than this cut-off value, then subsequent sub-problems of must have solutions greater than the value of the solution at and, therefore, need not be computed. Thus a knowledge of a good cut-off value can result in fewer sub-problems being solved and thus speed up the operation of the function. (See the description of in Parameters for details of how you can supply your own cut-off value.)
- References
Gill, P E, Hammarling, S, Murray, W, Saunders, M A and Wright, M H, 1986, Users’ guide for LSSOL (Version 1.0), Report SOL 86-1, Department of Operations Research, Stanford University
Gill, P E and Murray, W, 1978, Numerically stable methods for quadratic programming, Math. Programming (14), 349–372
Gill, P E, Murray, W, Saunders, M A and Wright, M H, 1984, Procedures for optimization problems with a mixture of bounds and general linear constraints, ACM Trans. Math. Software (10), 282–298
Gill, P E, Murray, W, Saunders, M A and Wright, M H, 1989, A practical anti-cycling procedure for linearly constrained optimization, Math. Programming (45), 437–474
Gill, P E, Murray, W, Saunders, M A and Wright, M H, 1991, Inertia-controlling methods for general quadratic programming, SIAM Rev. (33), 1–36
Gill, P E, Murray, W and Wright, M H, 1981, Practical Optimization, Academic Press
Pardalos, P M and Schnitger, G, 1988, Checking local optimality in constrained quadratic programming is NP-hard, Operations Research Letters (7), 33–35