Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

Chapter Contents
Chapter Introduction
NAG Toolbox

# NAG Toolbox: nag_mip_ilp_dense (h02bb)

## Purpose

nag_mip_ilp_dense (h02bb) solves ‘zero-one’, ‘general’, ‘mixed’ or ‘all’ integer programming problems using a branch and bound method. The function may also be used to find either the first integer solution or the optimum integer solution. It is not intended for large sparse problems.

## Syntax

[itmax, toliv, tolfes, bigbnd, x, objmip, iwork, rwork, ifail] = h02bb(itmax, msglvl, a, bl, bu, intvar, cvec, maxnod, intfst, toliv, tolfes, bigbnd, x, 'n', n, 'm', m, 'maxdpt', maxdpt)
[itmax, toliv, tolfes, bigbnd, x, objmip, iwork, rwork, ifail] = nag_mip_ilp_dense(itmax, msglvl, a, bl, bu, intvar, cvec, maxnod, intfst, toliv, tolfes, bigbnd, x, 'n', n, 'm', m, 'maxdpt', maxdpt)

## Description

nag_mip_ilp_dense (h02bb) is capable of solving certain types of integer programming (IP) problems using a branch and bound (B&B) method, see Taha (1987). In order to describe these types of integer programs and to briefly state the B&B method, we define the following linear programming (LP) problem:
Minimize
 F(x) = c1x1 + c2x2 + ⋯ + cnxn $F(x)=c1x1+c2x2+⋯+cnxn$
subject to
n
aijxj{
 = ≤ ≥
}
bi,  i = 1,2,,m
j = 1
$∑j= 1naijxj { = ≤ ≥ } bi, i= 1,2,…,m$
 lj ≤ xj ≤ uj,  j = 1,2, … ,n $lj≤xj≤uj, j=1,2,…,n$ (1)
If, in (1), it is required that (some or) all the variables take integer values, then the integer program is of type (mixed or) all general IP problem. If additionally, the integer variables are restricted to take only 0$0$1$1$ values (i.e., lj = 0${l}_{j}=0$ and uj = 1${u}_{j}=1$) then the integer program is of type (mixed or all) zero-one IP problem.
The B&B method applies directly to these integer programs. The general idea of B&B (for a full description see Dakin (1965) or Mitra (1973)) is to solve the problem without the integral restrictions as an LP problem (first node). If in the optimal solution an integer variable xk${x}_{k}$ takes a noninteger value xk * ${x}_{k}^{*}$, two LP sub-problems are created by branching, imposing xk[xk * ]${x}_{k}\le \left[{x}_{k}^{*}\right]$ and xk[xk * ] + 1${x}_{k}\ge \left[{x}_{k}^{*}\right]+1$ respectively, where [xk * ]$\left[{x}_{k}^{*}\right]$ denotes the integer part of xk * ${x}_{k}^{*}$. This method of branching continues until the first integer solution (bound) is obtained. The hanging nodes are then solved and investigated in order to prove the optimality of the solution. At each node, an LP problem is solved using nag_opt_lp_solve (e04mf).

## References

Dakin R J (1965) A tree search algorithm for mixed integer programming problems Comput. J. 8 250–255
Mitra G (1973) Investigation of some branch and bound strategies for the solution of mixed integer linear programs Math. Programming 4 155–170
Taha H A (1987) Operations Research: An Introduction Macmillan, New York

## Parameters

### Compulsory Input Parameters

1:     itmax – int64int32nag_int scalar
An upper bound on the number of iterations for each LP problem.
2:     msglvl – int64int32nag_int scalar
The amount of printout produced by nag_mip_ilp_dense (h02bb).
 Value Definition 0 No output. 1 The final IP solution only. 5 One line of output for each node investigated and the final IP solution. 10 The original LP solution (first node), one line of output for each node investigated and the final IP solution.
3:     a(lda, : $:$) – double array
The first dimension of the array a must be at least max (1,m)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{m}}\right)$
The second dimension of the array must be at least n${\mathbf{n}}$ if m > 0${\mathbf{m}}>0$ and at least 1$1$ if m = 0${\mathbf{m}}=0$
The i$\mathit{i}$th row of a must contain the coefficients of the i$\mathit{i}$th general constraint, for i = 1,2,,m$\mathit{i}=1,2,\dots ,m$.
If m = 0${\mathbf{m}}=0$ then the array a is not referenced.
4:     bl(n + m${\mathbf{n}}+{\mathbf{m}}$) – double array
5:     bu(n + m${\mathbf{n}}+{\mathbf{m}}$) – double array
bl must contain the lower bounds and bu the upper bounds, for all the constraints in the following order. The first n$n$ elements of each array must contain the bounds on the variables, and the next m$m$ elements the bounds for the general linear constraints (if any). To specify a nonexistent lower bound (i.e., lj = ${l}_{j}=-\infty$), set bl(j)bigbnd${\mathbf{bl}}\left(j\right)\le -{\mathbf{bigbnd}}$ and to specify a nonexistent upper bound (i.e., uj = + ${u}_{j}=+\infty$), set bu(j)bigbnd${\mathbf{bu}}\left(j\right)\ge {\mathbf{bigbnd}}$. To specify the j$j$th constraint as an equality, set bl(j) = bu(j) = β${\mathbf{bl}}\left(j\right)={\mathbf{bu}}\left(j\right)=\beta$, say, where |β| < bigbnd$|\beta |<{\mathbf{bigbnd}}$.
Constraints:
• bl(j)bu(j)${\mathbf{bl}}\left(\mathit{j}\right)\le {\mathbf{bu}}\left(\mathit{j}\right)$, for j = 1,2,,n + m$\mathit{j}=1,2,\dots ,{\mathbf{n}}+{\mathbf{m}}$;
• if bl(j) = bu(j) = β${\mathbf{bl}}\left(j\right)={\mathbf{bu}}\left(j\right)=\beta$, |β| < bigbnd$|\beta |<{\mathbf{bigbnd}}$.
6:     intvar(n) – int64int32nag_int array
n, the dimension of the array, must satisfy the constraint n > 0${\mathbf{n}}>0$.
Indicates which are the integer variables in the problem. For example, if xj${x}_{\mathit{j}}$ is an integer variable then intvar(j)${\mathbf{intvar}}\left(\mathit{j}\right)$ must be set to 1$1$, and 0$0$ otherwise.
Constraints:
• intvar(j) = 0${\mathbf{intvar}}\left(\mathit{j}\right)=0$ or 1$1$, for j = 1,2,,n$\mathit{j}=1,2,\dots ,{\mathbf{n}}$;
• intvar(j) = 1${\mathbf{intvar}}\left(\mathit{j}\right)=1$ for at least one value of j$\mathit{j}$.
7:     cvec(n) – double array
n, the dimension of the array, must satisfy the constraint n > 0${\mathbf{n}}>0$.
The coefficients cj${c}_{j}$ of the objective function F(x) = c1x1 + c2x2 + + cnxn$F\left(x\right)={c}_{1}{x}_{1}+{c}_{2}{x}_{2}+\dots +{c}_{n}{x}_{n}$. The function attempts to find a minimum of F(x)$F\left(x\right)$. If a maximum of F(x)$F\left(x\right)$ is desired, cvec(j)${\mathbf{cvec}}\left(\mathit{j}\right)$ should be set to cj$-{c}_{\mathit{j}}$, for j = 1,2,,n$\mathit{j}=1,2,\dots ,n$, so that the function will find a minimum of F(x)$-F\left(x\right)$.
8:     maxnod – int64int32nag_int scalar
The maximum number of nodes that are to be searched in order to find a solution (optimum integer solution). If maxnod0${\mathbf{maxnod}}\le 0$ and intfst0${\mathbf{intfst}}\le 0$, then the B&B tree search is continued until all the nodes have been investigated.
9:     intfst – int64int32nag_int scalar
Specifies whether to terminate the B&B tree search after the first integer solution (if any) is obtained. If intfst > 0${\mathbf{intfst}}>0$ then the B&B tree search is terminated at node k$k$ say, which contains the first integer solution. For maxnod > 0${\mathbf{maxnod}}>0$ this applies only if kmaxnod$k\le {\mathbf{maxnod}}$.
10:   toliv – double scalar
The integer feasibility tolerance; i.e., an integer variable is considered to take an integer value if its violation does not exceed toliv. For example, if the integer variable xj${x}_{j}$ is near unity then xj${x}_{j}$ is considered to be integer only if (1toliv)xj(1 + toliv)$\left(1-{\mathbf{toliv}}\right)\le {x}_{j}\le \left(1+{\mathbf{toliv}}\right)$.
11:   tolfes – double scalar
The maximum acceptable absolute violation in each constraint at a ‘feasible’ point (feasibility tolerance); i.e., a constraint is considered satisfied if its violation does not exceed tolfes.
12:   bigbnd – double scalar
The ‘infinite’ bound size in the definition of the problem constraints. More precisely, any upper bound greater than or equal to bigbnd will be regarded as + $+\infty$ and any lower bound less than or equal to $-{\mathbf{bigbnd}}$ will be regarded as $-\infty$.
13:   x(n) – double array
n, the dimension of the array, must satisfy the constraint n > 0${\mathbf{n}}>0$.
An initial estimate of the original LP solution.

### Optional Input Parameters

1:     n – int64int32nag_int scalar
Default: The dimension of the arrays cvec, x, intvar. (An error is raised if these dimensions are not equal.)
n$n$, the number of variables.
Constraint: n > 0${\mathbf{n}}>0$.
2:     m – int64int32nag_int scalar
Default: The first dimension of the array a.
m$m$, the number of general linear constraints.
Constraint: m0${\mathbf{m}}\ge 0$.
3:     maxdpt – int64int32nag_int scalar
The maximum depth of the B&B tree used for branch and bound.
Default: 3 × n / 2$3×{\mathbf{n}}/2$
Constraint: maxdpt2${\mathbf{maxdpt}}\ge 2$.

### Input Parameters Omitted from the MATLAB Interface

lda liwork lrwork

### Output Parameters

1:     itmax – int64int32nag_int scalar
Unchanged if on entry itmax > 0${\mathbf{itmax}}>0$, else itmax = max (50,5 × (n + m))${\mathbf{itmax}}=\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(50,5×\left({\mathbf{n}}+{\mathbf{m}}\right)\right)$.
2:     toliv – double scalar
Unchanged if on entry toliv > 0.0${\mathbf{toliv}}>0.0$, else toliv = 105${\mathbf{toliv}}={10}^{-5}$.
3:     tolfes – double scalar
Unchanged if on entry tolfes > 0.0${\mathbf{tolfes}}>0.0$, else tolfes = sqrt(ε)${\mathbf{tolfes}}=\sqrt{\epsilon }$ (where ε$\epsilon$ is the machine precision).
4:     bigbnd – double scalar
Unchanged if on entry bigbnd > 0.0${\mathbf{bigbnd}}>0.0$, else bigbnd = 1020${\mathbf{bigbnd}}={10}^{20}$.
5:     x(n) – double array
With ${\mathbf{ifail}}={\mathbf{0}}$, x contains a solution which will be an estimate of either the optimum integer solution or the first integer solution, depending on the value of intfst. If ${\mathbf{ifail}}={\mathbf{9}}$, then x contains a solution which will be an estimate of the best integer solution that was obtained by searching maxnod nodes.
6:     objmip – double scalar
With ${\mathbf{ifail}}={\mathbf{0}}$ or 9${\mathbf{9}}$, objmip contains the value of the objective function for the IP solution.
7:     iwork(liwork) – int64int32nag_int array
8:     rwork(lrwork) – double array
9:     ifail – int64int32nag_int scalar
${\mathrm{ifail}}={\mathbf{0}}$ unless the function detects an error (see [Error Indicators and Warnings]).

## Error Indicators and Warnings

Note: nag_mip_ilp_dense (h02bb) may return useful information for one or more of the following detected errors or warnings.
Errors or warnings detected by the function:

Cases prefixed with W are classified as warnings and do not generate an error of type NAG:error_n. See nag_issue_warnings.

ifail = 1${\mathbf{ifail}}=1$
No feasible integer point was found, i.e., it was not possible to satisfy all the integer variables to within the integer feasibility tolerance (determined by toliv). Increase toliv and rerun nag_mip_ilp_dense (h02bb).
ifail = 2${\mathbf{ifail}}=2$
The original LP solution appears to be unbounded. This value of ifail implies that a step as large as bigbnd would have to be taken in order to continue the algorithm (see Section [Further Comments]).
ifail = 3${\mathbf{ifail}}=3$
No feasible point was found for the original LP problem, i.e., it was not possible to satisfy all the constraints to within the feasibility tolerance (determined by tolfes). If the data for the constraints are accurate only to the absolute precision σ$\sigma$, you should ensure that the value of the feasibility tolerance is greater than σ$\sigma$. For example, if all elements of A$A$ are of order unity and are accurate only to three decimal places, the feasibility tolerance should be at least 103${10}^{-3}$ (see Section [Further Comments]).
ifail = 4${\mathbf{ifail}}=4$
The maximum number of iterations (determined by itmax) was reached before normal termination occurred for the original LP problem (see Section [Further Comments]).
ifail = 5${\mathbf{ifail}}=5$
Not used by this function.
ifail = 6${\mathbf{ifail}}=6$
An input parameter is invalid.
W ifail = 7${\mathbf{ifail}}=7$
The IP solution reported is not the optimum IP solution. In other words, the B&B tree search for at least one of the branches had to be terminated since an LP sub-problem in the branch did not have a solution (see Section [Further Comments]).
ifail = 8${\mathbf{ifail}}=8$
The maximum depth of the B&B tree used for branch and bound (determined by maxdpt) is too small. Increase maxdpt (along with liwork and/or lrwork if appropriate) and rerun nag_mip_ilp_dense (h02bb).
W ifail = 9${\mathbf{ifail}}=9$
The IP solution reported is the best IP solution for the number of nodes (determined by maxnod) investigated in the B&B tree.
ifail = 10${\mathbf{ifail}}=10$
No feasible integer point was found for the number of nodes (determined by maxnod) investigated in the B&B tree.
ifail = 11${\mathbf{ifail}}=11$
Although the workspace sizes are sufficient to meet the documented restriction, they are not sufficiently large to accommodate an internal partition of the workspace that meets the requirements of the problem. Increase the workspace sizes.
Overflow$\mathbf{\text{Overflow}}$
It may be possible to avoid the difficulty by increasing the magnitude of the feasibility tolerance (tolfes) and rerunning the program. If the message recurs even after this change, see Section [Further Comments].

## Accuracy

nag_mip_ilp_dense (h02bb) implements a numerically stable active set strategy and returns solutions that are as accurate as the condition of the problem warrants on the machine.

The original LP problem may not have an optimum solution, i.e., nag_mip_ilp_dense (h02bb) terminates with ${\mathbf{ifail}}={\mathbf{2}}$, 3${\mathbf{3}}$ or 4${\mathbf{4}}$ or overflow may occur. In this case, you are recommended to relax the integer restrictions of the problem and try to find the optimum LP solution by using nag_opt_lp_solve (e04mf) instead.
In the B&B method, it is possible for an LP sub-problem to terminate without finding a solution. This may occur due to the number of iterations exceeding the maximum allowed. Therefore the B&B tree search for that particular branch cannot be continued. Thus the returned solution may not be optimal. (${\mathbf{ifail}}={\mathbf{7}}$). For the second and unlikely case, a solution could not be found despite a second attempt at an LP solution.

## Example

```function nag_mip_ilp_dense_example
itmax = int64(0);
msglvl = int64(10);
a = [2, 5;
2, -2;
3, 2];
bl = [0;
0;
-1e+20;
-1e+20;
5];
bu = [1e+20;
1e+20;
15;
5;
1e+20];
intvar = [int64(1);1];
cvec = [-3;
-4];
maxnod = int64(0);
intfst = int64(0);
toliv = 0;
tolfes = 0;
bigbnd = 1e+20;
x = [1;
1];
[itmaxOut, tolivOut, tolfesOut, bigbndOut, xOut, objmip, iwork, rwork, ifail] = ...
nag_mip_ilp_dense(itmax, msglvl, a, bl, bu, intvar, cvec, maxnod, intfst, toliv, ...
tolfes, bigbnd, x, 'maxdpt', int64(4));
itmaxOut, tolivOut, tolfesOut, bigbndOut, xOut, objmip, ifail
```
```

*** H02BBF

Parameters
----------

Linear constraints......         3        First integer solution..       OFF
Variables...............         2        Max depth of the tree...         4

Feasibility tolerance...  1.05E-08        Print level.............        10
Infinite bound size.....  1.00E+20        EPS (machine precision).  1.11E-16

Integer feasibility tol.  1.00E-05        Iteration limit.........        50
Max number of nodes.....      NONE

** Workspace provided with MAXDPT =     4: LRWORK =    84  LIWORK =   137
** Workspace required with MAXDPT =     4: LRWORK =    84  LIWORK =   137

*** Optimum LP solution ***   -17.50000

Varbl State     Value     Lower Bound   Upper Bound    Lagr Mult   Residual

V  1    FR    3.92857       0.00000         None        0.000       3.929
V  2    FR    1.42857       0.00000         None        0.000       1.429

L Con State     Value     Lower Bound   Upper Bound    Lagr Mult   Residual

L  1    UL    15.0000         None        15.0000      -1.000       0.000
L  2    UL    5.00000         None        5.00000     -0.5000     -8.8818E-16
L  3    FR    14.6429       5.00000         None        0.000       9.643

*** Start of tree search ***

Node  Parent   Obj       Varbl  Value      Lower      Upper      Value   Depth
No    Node   Value      Chosen Before     Bound      Bound      After
2     1   No Feas Soln    1    3.93       4.00       None       4.00       1
3     1    -16.2          1    3.93       0.00       3.00       3.00       1
4     3    -15.5          2    1.80       2.00       None       2.00       2
5     3    -13.0          2    1.80       0.00       1.00       1.00       2
*** Integer solution ***

Node  Parent   Obj       Varbl  Value      Lower      Upper      Value   Depth
No    Node   Value      Chosen Before     Bound      Bound      After
6     4   No Feas Soln    1    2.50       3.00       3.00       3.00       3
7     4    -14.8          1    2.50       0.00       2.00       2.00       3
8     7    -12.0     CO   2    2.20       3.00       None       3.00       4
9     7    -14.0          2    2.20       2.00       2.00       2.00       4
*** Integer solution ***

*** End of tree search ***

Total of     9 nodes investigated.

Exit H02BBF - Optimum IP solution found.

Final IP objective value =   -14.00000

Varbl State     Value     Lower Bound   Upper Bound    Lagr Mult   Residual

V  1    UL    2.00000       0.00000       2.00000      -3.000       0.000
V  2    EQ    2.00000       2.00000       2.00000      -4.000       0.000

L Con State     Value     Lower Bound   Upper Bound    Lagr Mult   Residual

L  1    FR    14.0000         None        15.0000       0.000       1.000
L  2    FR    0.00000         None        5.00000       0.000       5.000
L  3    FR    10.0000       5.00000         None        0.000       5.000

itmaxOut =

50

tolivOut =

1.0000e-05

tolfesOut =

1.0537e-08

bigbndOut =

1.0000e+20

xOut =

2
2

objmip =

-14

ifail =

0

```
```function h02bb_example
itmax = int64(0);
msglvl = int64(10);
a = [2, 5;
2, -2;
3, 2];
bl = [0;
0;
-1e+20;
-1e+20;
5];
bu = [1e+20;
1e+20;
15;
5;
1e+20];
intvar = [int64(1);1];
cvec = [-3;
-4];
maxnod = int64(0);
intfst = int64(0);
toliv = 0;
tolfes = 0;
bigbnd = 1e+20;
x = [1;
1];
[itmaxOut, tolivOut, tolfesOut, bigbndOut, xOut, objmip, iwork, rwork, ifail] = ...
h02bb(itmax, msglvl, a, bl, bu, intvar, cvec, maxnod, intfst, toliv, ...
tolfes, bigbnd, x, 'maxdpt', int64(4));
itmaxOut, tolivOut, tolfesOut, bigbndOut, xOut, objmip, ifail
```
```

*** H02BBF

Parameters
----------

Linear constraints......         3        First integer solution..       OFF
Variables...............         2        Max depth of the tree...         4

Feasibility tolerance...  1.05E-08        Print level.............        10
Infinite bound size.....  1.00E+20        EPS (machine precision).  1.11E-16

Integer feasibility tol.  1.00E-05        Iteration limit.........        50
Max number of nodes.....      NONE

** Workspace provided with MAXDPT =     4: LRWORK =    84  LIWORK =   137
** Workspace required with MAXDPT =     4: LRWORK =    84  LIWORK =   137

*** Optimum LP solution ***   -17.50000

Varbl State     Value     Lower Bound   Upper Bound    Lagr Mult   Residual

V  1    FR    3.92857       0.00000         None        0.000       3.929
V  2    FR    1.42857       0.00000         None        0.000       1.429

L Con State     Value     Lower Bound   Upper Bound    Lagr Mult   Residual

L  1    UL    15.0000         None        15.0000      -1.000       0.000
L  2    UL    5.00000         None        5.00000     -0.5000     -8.8818E-16
L  3    FR    14.6429       5.00000         None        0.000       9.643

*** Start of tree search ***

Node  Parent   Obj       Varbl  Value      Lower      Upper      Value   Depth
No    Node   Value      Chosen Before     Bound      Bound      After
2     1   No Feas Soln    1    3.93       4.00       None       4.00       1
3     1    -16.2          1    3.93       0.00       3.00       3.00       1
4     3    -15.5          2    1.80       2.00       None       2.00       2
5     3    -13.0          2    1.80       0.00       1.00       1.00       2
*** Integer solution ***

Node  Parent   Obj       Varbl  Value      Lower      Upper      Value   Depth
No    Node   Value      Chosen Before     Bound      Bound      After
6     4   No Feas Soln    1    2.50       3.00       3.00       3.00       3
7     4    -14.8          1    2.50       0.00       2.00       2.00       3
8     7    -12.0     CO   2    2.20       3.00       None       3.00       4
9     7    -14.0          2    2.20       2.00       2.00       2.00       4
*** Integer solution ***

*** End of tree search ***

Total of     9 nodes investigated.

Exit H02BBF - Optimum IP solution found.

Final IP objective value =   -14.00000

Varbl State     Value     Lower Bound   Upper Bound    Lagr Mult   Residual

V  1    UL    2.00000       0.00000       2.00000      -3.000       0.000
V  2    EQ    2.00000       2.00000       2.00000      -4.000       0.000

L Con State     Value     Lower Bound   Upper Bound    Lagr Mult   Residual

L  1    FR    14.0000         None        15.0000       0.000       1.000
L  2    FR    0.00000         None        5.00000       0.000       5.000
L  3    FR    10.0000       5.00000         None        0.000       5.000

itmaxOut =

50

tolivOut =

1.0000e-05

tolfesOut =

1.0537e-08

bigbndOut =

1.0000e+20

xOut =

2
2

objmip =

-14

ifail =

0

```