h Chapter Contents
h Chapter Introduction
NAG C Library Manual

# NAG Library Function Documentnag_transport (h03abc)

## 1  Purpose

nag_transport (h03abc) solves the classical transportation (‘Hitchcock’) problem.

## 2  Specification

 #include #include
 void nag_transport (const double cost[], Integer tdcost, const double avail[], Integer navail, const double req[], Integer nreq, Integer maxit, Integer *numit, double optq[], Integer source[], Integer dest[], double *optcost, double unitcost[], NagError *fail)

## 3  Description

nag_transport (h03abc) solves the transportation problem by minimizing
 $z = ∑ i m a ∑ j m b c ij x ij .$
subject to the constraints
 $∑ j m b x ij = A i availabilities ∑ i m a x ij = B j requirements$
where the ${x}_{\mathit{i}\mathit{j}}$ can be interpreted as quantities of goods sent from source $\mathit{i}$ to destination $\mathit{j}$, for $\mathit{i}=1,2,\dots ,{m}_{a}$ and $\mathit{j}=1,2,\dots ,{m}_{b}$, at a cost of ${c}_{ij}$ per unit, and it is assumed that ${\sum }_{i}^{{m}_{a}}{A}_{i}={\sum }_{j}^{{m}_{b}}{B}_{j}$ and ${x}_{ij}\ge 0$.
nag_transport (h03abc) uses the ‘stepping stone’ method, modified to accept degenerate cases.

## 5  Arguments

1:     cost[${\mathbf{navail}}×{\mathbf{tdcost}}$]const doubleInput
On entry: ${\mathbf{cost}}\left[\left(\mathit{i}-1\right)×{\mathbf{tdcost}}+\mathit{j}-1\right]$ contains the coefficients ${c}_{\mathit{i}\mathit{j}}$, for $\mathit{i}=1,2,\dots ,{m}_{a}$ and $\mathit{j}=1,2,\dots ,{m}_{b}$.
2:     tdcostIntegerInput
On entry: the stride separating matrix column elements in the array cost.
Constraint: ${\mathbf{tdcost}}\ge {\mathbf{nreq}}$.
3:     avail[navail]const doubleInput
On entry: ${\mathbf{avail}}\left[\mathit{i}-1\right]$ must be set to the availabilities ${A}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,{m}_{a}$;
On entry: the number of sources, ${m}_{a}$.
Constraint: ${\mathbf{navail}}\ge 1$.
5:     req[nreq]const doubleInput
On entry: ${\mathbf{req}}\left[\mathit{j}-1\right]$ must be set to the requirements ${B}_{\mathit{j}}$, for $\mathit{j}=1,2,\dots ,{m}_{b}$.
6:     nreqIntegerInput
On entry: the number of destinations, ${m}_{b}$.
Constraint: ${\mathbf{nreq}}\ge 1$.
7:     maxitIntegerInput
On entry: the maximum number of iterations allowed.
Constraint: ${\mathbf{maxit}}\ge 1$.
8:     numitInteger *Output
On exit: the number of iterations performed.
9:     optq[${\mathbf{navail}}+{\mathbf{nreq}}$]doubleOutput
On exit: ${\mathbf{optq}}\left[\mathit{k}-1\right]$, for $\mathit{k}=1,2,\dots ,{m}_{a}+{m}_{b}-1$, contains the optimal quantities ${x}_{ij}$ which, when sent from source $i={\mathbf{source}}\left[k-1\right]$ to destination $j={\mathbf{dest}}\left[k-1\right]$, minimize $z$.
10:   source[${\mathbf{navail}}+{\mathbf{nreq}}$]IntegerOutput
On exit: ${\mathbf{source}}\left[\mathit{k}-1\right]$, for $\mathit{k}=1,2,\dots ,{m}_{a}+{m}_{b}-1$, contains the source indices of the optimal solution (see optq above).
11:   dest[${\mathbf{navail}}+{\mathbf{nreq}}$]IntegerOutput
On exit: ${\mathbf{dest}}\left[\mathit{k}-1\right]$, for $\mathit{k}=1,2,\dots ,{m}_{a}+{m}_{b}-1$, contains the destination indices of the optimal solution (see optq above).
12:   optcostdouble *Output
On exit: the value of the minimized total cost.
13:   unitcost[${\mathbf{navail}}+{\mathbf{nreq}}$]doubleOutput
On exit: ${\mathbf{unitcost}}\left[\mathit{k}-1\right]$, for $\mathit{k}=1,2,\dots ,{m}_{a}+{m}_{b}-1$, contains the unit cost ${c}_{ij}$ associated with the route from source $i={\mathbf{source}}\left[k-1\right]$ to destination $j={\mathbf{dest}}\left[k-1\right]$.
14:   failNagError *Input/Output
The NAG error argument (see Section 3.6 in the Essential Introduction).

## 6  Error Indicators and Warnings

NE_2_INT_ARG_LT
On entry, ${\mathbf{tdcost}}=〈\mathit{\text{value}}〉$ while ${\mathbf{nreq}}=〈\mathit{\text{value}}〉$. These arguments must satisfy ${\mathbf{tdcost}}\ge {\mathbf{nreq}}$.
NE_ALLOC_FAIL
Dynamic memory allocation failed.
NE_INT_ARG_LT
On entry, ${\mathbf{maxit}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{maxit}}\ge 1$.
On entry, ${\mathbf{navail}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{navail}}\ge 1$.
On entry, ${\mathbf{nreq}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{nreq}}\ge 1$.
NE_REQ_AVAIL
The relative difference between the sum of availabilities and the sum of requirements is greater than machine precision. relative difference $\text{}=〈\mathit{\text{value}}〉$, .
NE_TOO_MANY
Too many iterations ($〈\mathit{\text{value}}〉$)

## 7  Accuracy

The computations are stable.

An a priori estimate of the run time for a particular problem is difficult to obtain.

## 9  Example

A company has three warehouses and three stores. The warehouses have a surplus of 12 units of a given commodity divided between them as follows:
 Warehouse Surplus 1 1 2 5 3 6
The stores altogether need 12 units of commodity, with the following requirements:
 Store Requirement 1 4 2 4 3 4
Costs of shipping one unit of the commodity from warehouse $i$ to store $j$ are displayed in the following matrix:
 Store 1 2 3 1 8 8 11 Warehouse 2 5 8 14 3 4 3 10
It is required to find the units of commodity to be moved from the warehouses to the stores, such that the transportation costs are minimized. The maximum number of iterations allowed is 200.

### 9.1  Program Text

Program Text (h03abce.c)

None.

### 9.3  Program Results

Program Results (h03abce.r)