DISCRETE LINEAR OPTIMIZATION
Get these two pieces of code!
Compile these in the order shown. This order is important since Fortran modules are used. Missing routines and modules are found in the IMSL Fortran 90 MP Library product.
The routine KNAP_SACK solves the
optimization problem:
maximize![]()
subject to the constraint![]()
and the integer constraints ![]()
If the xj = 0 or 1, use boundsj = 1. The input to the routine is the data aj , cj , j=1,...,n and b. If there are bounds on any variables then all variables must have a positive upper bound. If no upper bound is required for an individual xj , set boundsj = huge(1), the Fortran 90 elemental function for the largest default type integer . If upper bounds are not required as part of the problem statement, no bound information needs to be input. This is explained below with the optional argument X_BOUNDS(:). The routine checks that the data are consistent in the sense: aj > 0, cj > 0, boundsj > 0, j = 1,...,n.
CALL KNAP_SACK(DEPTH, A, B, C, X_BEST, BEST_VALUE, X_BOUNDS)
Subroutine KNAP_SACK implements a branch-and-bound method
for solving the knapsack problem. This is given in the book Linear
Programming, (1983), Vi?ek Chvátal, W. H. Freeman,
Inc., New York, NY, page 206, inset Box 13.1. We have added the
additional feature of bounding each component of the solution to the
algorithm. The pruning of solutions is accomplished after first sorting
the efficiency ratios:
. The new order implied by the sort is obtained as a
product of cyclic interchanges. Both arrays A(:) and
C(:) are moved to this internal order and then moved back
again, just before the routine exits. The array X_BEST(:)
is moved to correspond with the input order of A(:) and
C(:). The IMSL MP Library routine SORT_REAL
returns the cyclic interchanges. This complication is normally hidden
from the user of KNAP_SACK but we mention it so that the
user is not tempted to do sorting in their own program.
The program unit KNAPSACK_ILLUSTRATOR in "knapex.f90" solves three small knapsack problems. The coefficients and solution are listed with the IMSL MP Library generic array printing subroutine SHOW found in the IMSL MP Library version 3. The first two problems allow only two values 0-1 for the solution. Thus the upper bounds are included as an optional argument, each with the value 1. The third problem has no prior bound on any component, so we do not use the optional argument for the bounds.