﻿ h02bb Method
h02bb solves ‘zero-one’, ‘general’, ‘mixed’ or ‘all’ integer programming problems using a branch and bound method. The method 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

C#
```public static void h02bb(
ref int itmax,
int msglvl,
int n,
int m,
double[,] a,
double[] bl,
double[] bu,
int[] intvar,
double[] cvec,
int maxnod,
int intfst,
int maxdpt,
ref double toliv,
ref double tolfes,
ref double bigbnd,
double[] x,
out double objmip,
int[] iwork,
double[] rwork,
H..::..h02bbOptions options,
out int ifail
)```
Visual Basic
```Public Shared Sub h02bb ( _
ByRef itmax As Integer, _
msglvl As Integer, _
n As Integer, _
m As Integer, _
a As Double(,), _
bl As Double(), _
bu As Double(), _
intvar As Integer(), _
cvec As Double(), _
maxnod As Integer, _
intfst As Integer, _
maxdpt As Integer, _
ByRef toliv As Double, _
ByRef tolfes As Double, _
ByRef bigbnd As Double, _
x As Double(), _
<OutAttribute> ByRef objmip As Double, _
iwork As Integer(), _
rwork As Double(), _
options As H..::..h02bbOptions, _
<OutAttribute> ByRef ifail As Integer _
)```
Visual C++
```public:
static void h02bb(
int% itmax,
int msglvl,
int n,
int m,
array<double,2>^ a,
array<double>^ bl,
array<double>^ bu,
array<int>^ intvar,
array<double>^ cvec,
int maxnod,
int intfst,
int maxdpt,
double% toliv,
double% tolfes,
double% bigbnd,
array<double>^ x,
[OutAttribute] double% objmip,
array<int>^ iwork,
array<double>^ rwork,
H..::..h02bbOptions^ options,
[OutAttribute] int% ifail
)```
F#
```static member h02bb :
itmax : int byref *
msglvl : int *
n : int *
m : int *
a : float[,] *
bl : float[] *
bu : float[] *
intvar : int[] *
cvec : float[] *
maxnod : int *
intfst : int *
maxdpt : int *
toliv : float byref *
tolfes : float byref *
bigbnd : float byref *
x : float[] *
objmip : float byref *
iwork : int[] *
rwork : float[] *
options : H..::..h02bbOptions *
ifail : int byref -> unit
```

#### Parameters

itmax
Type: System..::..Int32%
On entry: an upper bound on the number of iterations for each LP problem.
On exit: unchanged if on entry ${\mathbf{itmax}}>0$, else ${\mathbf{itmax}}=\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(50,5×\left({\mathbf{n}}+{\mathbf{m}}\right)\right)$.
msglvl
Type: System..::..Int32
On entry: the amount of printout produced by h02bb, as indicated below (see [Description of Printed Output] for a description of the printed output). All output is written to the current advisory message unit (as defined by (X04ABF not in this release)).
 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.
n
Type: System..::..Int32
On entry: $n$, the number of variables.
Constraint: ${\mathbf{n}}>0$.
m
Type: System..::..Int32
On entry: $m$, the number of general linear constraints.
Constraint: ${\mathbf{m}}\ge 0$.
a
Type: array<System..::..Double,2>[,](,)[,][,]
An array of size [dim1, dim2]
Note: dim1 must satisfy the constraint: $\mathrm{dim1}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{m}}\right)$
Note: the second dimension of the array a must be at least ${\mathbf{n}}$ if ${\mathbf{m}}>0$ and at least $1$ if ${\mathbf{m}}=0$.
On entry: the $\mathit{i}$th row of a must contain the coefficients of the $\mathit{i}$th general constraint, for $\mathit{i}=1,2,\dots ,m$.
If ${\mathbf{m}}=0$ then the array a is not referenced.
bl
Type: array<System..::..Double>[]()[][]
An array of size [${\mathbf{n}}+{\mathbf{m}}$]
On entry: bl must contain the lower bounds and bu the upper bounds, for all the constraints in the following order. The first $n$ elements of each array must contain the bounds on the variables, and the next $m$ elements the bounds for the general linear constraints (if any). To specify a nonexistent lower bound (i.e., ${l}_{j}=-\infty$), set ${\mathbf{bl}}\left[j\right]\le -{\mathbf{bigbnd}}$ and to specify a nonexistent upper bound (i.e., ${u}_{j}=+\infty$), set ${\mathbf{bu}}\left[j\right]\ge {\mathbf{bigbnd}}$. To specify the $j$th constraint as an equality, set ${\mathbf{bl}}\left[j\right]={\mathbf{bu}}\left[j\right]=\beta$, say, where $\left|\beta \right|<{\mathbf{bigbnd}}$.
Constraints:
• ${\mathbf{bl}}\left[\mathit{j}\right]\le {\mathbf{bu}}\left[\mathit{j}\right]$, for $\mathit{j}=0,1,\dots ,{\mathbf{n}}+{\mathbf{m}}-1$;
• if ${\mathbf{bl}}\left[j\right]={\mathbf{bu}}\left[j\right]=\beta$, $\left|\beta \right|<{\mathbf{bigbnd}}$.
bu
Type: array<System..::..Double>[]()[][]
An array of size [${\mathbf{n}}+{\mathbf{m}}$]
On entry: bl must contain the lower bounds and bu the upper bounds, for all the constraints in the following order. The first $n$ elements of each array must contain the bounds on the variables, and the next $m$ elements the bounds for the general linear constraints (if any). To specify a nonexistent lower bound (i.e., ${l}_{j}=-\infty$), set ${\mathbf{bl}}\left[j\right]\le -{\mathbf{bigbnd}}$ and to specify a nonexistent upper bound (i.e., ${u}_{j}=+\infty$), set ${\mathbf{bu}}\left[j\right]\ge {\mathbf{bigbnd}}$. To specify the $j$th constraint as an equality, set ${\mathbf{bl}}\left[j\right]={\mathbf{bu}}\left[j\right]=\beta$, say, where $\left|\beta \right|<{\mathbf{bigbnd}}$.
Constraints:
• ${\mathbf{bl}}\left[\mathit{j}\right]\le {\mathbf{bu}}\left[\mathit{j}\right]$, for $\mathit{j}=0,1,\dots ,{\mathbf{n}}+{\mathbf{m}}-1$;
• if ${\mathbf{bl}}\left[j\right]={\mathbf{bu}}\left[j\right]=\beta$, $\left|\beta \right|<{\mathbf{bigbnd}}$.
intvar
Type: array<System..::..Int32>[]()[][]
An array of size [n]
On entry: indicates which are the integer variables in the problem. For example, if ${x}_{\mathit{j}}$ is an integer variable then ${\mathbf{intvar}}\left[\mathit{j}\right]$ must be set to $1$, and $0$ otherwise.
Constraints:
• ${\mathbf{intvar}}\left[\mathit{j}\right]=0$ or $1$, for $\mathit{j}=0,1,\dots ,{\mathbf{n}}-1$;
• ${\mathbf{intvar}}\left[\mathit{j}\right]=1$ for at least one value of $\mathit{j}$.
cvec
Type: array<System..::..Double>[]()[][]
An array of size [n]
On entry: the coefficients ${c}_{j}$ of the objective function $F\left(x\right)={c}_{1}{x}_{1}+{c}_{2}{x}_{2}+\dots +{c}_{n}{x}_{n}$. The method attempts to find a minimum of $F\left(x\right)$. If a maximum of $F\left(x\right)$ is desired, ${\mathbf{cvec}}\left[\mathit{j}\right]$ should be set to $-{c}_{\mathit{j}}$, for $\mathit{j}=1,2,\dots ,n$, so that the method will find a minimum of $-F\left(x\right)$.
maxnod
Type: System..::..Int32
On entry: the maximum number of nodes that are to be searched in order to find a solution (optimum integer solution). If ${\mathbf{maxnod}}\le 0$ and ${\mathbf{intfst}}\le 0$, then the B&B tree search is continued until all the nodes have been investigated.
intfst
Type: System..::..Int32
On entry: specifies whether to terminate the B&B tree search after the first integer solution (if any) is obtained. If ${\mathbf{intfst}}>0$ then the B&B tree search is terminated at node $k$ say, which contains the first integer solution. For ${\mathbf{maxnod}}>0$ this applies only if $k\le {\mathbf{maxnod}}$.
maxdpt
Type: System..::..Int32
On entry: the maximum depth of the B&B tree used for branch and bound.
Suggested value: ${\mathbf{maxdpt}}=3×{\mathbf{n}}/2$.
Constraint: ${\mathbf{maxdpt}}\ge 2$.
toliv
Type: System..::..Double%
On entry: 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 ${x}_{j}$ is near unity then ${x}_{j}$ is considered to be integer only if $\left(1-{\mathbf{toliv}}\right)\le {x}_{j}\le \left(1+{\mathbf{toliv}}\right)$.
On exit: unchanged if on entry ${\mathbf{toliv}}>0.0$, else ${\mathbf{toliv}}={10}^{-5}$.
tolfes
Type: System..::..Double%
On entry: 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.
On exit: unchanged if on entry ${\mathbf{tolfes}}>0.0$, else ${\mathbf{tolfes}}=\sqrt{\epsilon }$ (where $\epsilon$ is the machine precision).
bigbnd
Type: System..::..Double%
On entry: 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$.
On exit: unchanged if on entry ${\mathbf{bigbnd}}>0.0$, else ${\mathbf{bigbnd}}={10}^{20}$.
x
Type: array<System..::..Double>[]()[][]
An array of size [n]
On entry: an initial estimate of the original LP solution.
On exit: with ${\mathbf{ifail}}={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}}={9}$, then x contains a solution which will be an estimate of the best integer solution that was obtained by searching maxnod nodes.
objmip
Type: System..::..Double%
On exit: with ${\mathbf{ifail}}={0}$ or ${9}$, objmip contains the value of the objective function for the IP solution.
iwork
Type: array<System..::..Int32>[]()[][]
An array of size [liwork]
the dimension of the array iwork.
On entry: the dimension of the array iwork as declared in the (sub)program from which h02bb is called.
Constraint: ${\mathbf{liwork}}\ge \left(25+{\mathbf{n}}+{\mathbf{m}}\right)×{\mathbf{maxdpt}}+5×{\mathbf{n}}+{\mathbf{m}}+4$.
rwork
Type: array<System..::..Double>[]()[][]
An array of size [lrwork]
the dimension of the array rwork.
On entry: the dimension of the array rwork as declared in the (sub)program from which h02bb is called.
Constraint: ${\mathbf{lrwork}}\ge {\mathbf{maxdpt}}×\left({\mathbf{n}}+1\right)+2×{\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{n}},{\mathbf{m}}+1\right)}^{2}+14×{\mathbf{n}}+12×{\mathbf{m}}$.
If ${\mathbf{msglvl}}>0$, the amounts of workspace provided and required (with ${\mathbf{maxdpt}}=3×{\mathbf{n}}/2$) are printed. As an alternative to computing maxdpt, liwork and lrwork from the formulas given above, you may prefer to obtain appropriate values from the output of a preliminary run with the values of maxdpt, liwork and lrwork set to $1$. If however only liwork and lrwork are set to $1$, then the appropriate values of these parameters for the given value of maxdpt will be computed and printed unless ${\mathbf{maxdpt}}<2$. In both cases h02bb will then terminate with ${\mathbf{ifail}}={6}$.
options
Type: NagLibrary..::..H..::..h02bbOptions
An Object of type H.h02bbOptions. Used to configure optional parameters to this method.
ifail
Type: System..::..Int32%
On exit: ${\mathbf{ifail}}={0}$ unless the method detects an error or a warning has been flagged (see [Error Indicators and Warnings]).

# Description

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
 $Fx=c1x1+c2x2+⋯+cnxn$
subject to
 $∑j=1naijxj=≤≥bi, i=1,2,…,m$
 $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$$1$ values (i.e., ${l}_{j}=0$ and ${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 ${x}_{k}$ takes a noninteger value ${x}_{k}^{*}$, two LP sub-problems are created by branching, imposing ${x}_{k}\le \left[{x}_{k}^{*}\right]$ and ${x}_{k}\ge \left[{x}_{k}^{*}\right]+1$ respectively, where $\left[{x}_{k}^{*}\right]$ denotes the integer part of ${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 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

# Error Indicators and Warnings

Note: h02bb may return useful information for one or more of the following detected errors or warnings.
Errors or warnings detected by the method:
Some error messages may refer to parameters that are dropped from this interface (LDA) In these cases, an error in another parameter has usually caused an incorrect value to be inferred.
${\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 h02bb.
${\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 [Further Comments]).
${\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$ are of order unity and are accurate only to three decimal places, the feasibility tolerance should be at least ${10}^{-3}$ (see [Further Comments]).
${\mathbf{ifail}}=4$
The maximum number of iterations (determined by itmax) was reached before normal termination occurred for the original LP problem (see [Further Comments]).
${\mathbf{ifail}}=5$
Not used by this method.
${\mathbf{ifail}}=6$
An input parameter is invalid.
${\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 [Further Comments]).
${\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 h02bb.
${\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.
${\mathbf{ifail}}=10$
No feasible integer point was found for the number of nodes (determined by maxnod) investigated in the B&B tree.
${\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.
$\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 [Further Comments].
${\mathbf{ifail}}=-9000$
An error occured, see message report.
${\mathbf{ifail}}=-6000$
Invalid Parameters $〈\mathit{\text{value}}〉$
${\mathbf{ifail}}=-4000$
Invalid dimension for array $〈\mathit{\text{value}}〉$
${\mathbf{ifail}}=-8000$
Negative dimension for array $〈\mathit{\text{value}}〉$
${\mathbf{ifail}}=-6000$
Invalid Parameters $〈\mathit{\text{value}}〉$

# Accuracy

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.

# Parallelism and Performance

None.

The original LP problem may not have an optimum solution, i.e., h02bb terminates with ${\mathbf{ifail}}={2}$${3}$ or ${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 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}}={7}$). For the second and unlikely case, a solution could not be found despite a second attempt at an LP solution.

# Example

This example solves the integer programming problem:
maximize
 $Fx=3x1+4x2$
subject to the bounds
 $x1≥0x2≥0$
and to the general constraints
 $2x1+5x2≤152x1-2x2≤53x1+2x2≥5$
where ${x}_{1}$ and ${x}_{2}$ are integer variables.
The initial point, which is feasible, is
 $x0=1,1T,$
and $F\left({x}_{0}\right)=7$.
The optimal solution is
 $x*=2,2T,$
and $F\left({x}^{*}\right)=14$.
Note that maximizing $F\left(x\right)$ is equivalent to minimizing $-F\left(x\right)$.

Example program (C#): h02bbe.cs

Example program data: h02bbe.d

Example program results: h02bbe.r