Class Transport
- All Implemented Interfaces:
Serializable
Class Transport solves the transportation problem which can be
described as follows: Let \(nw\) sources (or warehouses) be given that store
\(w_i\) (\(i=1,..,nw\)) units of a commodity. The sources are connected with
\(ns\) destinations (or sinks) that demand \(s_j\) (\(j = 1,...,ns\)) units
of the commodity. The transportation costs per unit from source i to
destination j are \(c_{ij}\). The goal is to transport the commodity
from the sources to the destinations in such a way that all demands are met
and the total transportation costs are minimized. If \(x_{ij}\) denotes the
desired quantity of the commodity transported from source i to
destination j, then the mathematical formulation of the transportation
problem is
$$ \min \sum_{i=1}^{nw}\sum_{j=1}^{ns}c_{ij}x_{ij}$$
subject to the constraints
$$\sum_{j=1}^{ns}x_{ij} \le w_i, i = 1,\ldots,nw \\ \sum_{i=1}^{nw}x_{ij} =
s_j, j = 1,\ldots,ns \\ x_{ij} \ge 0, i=1,\ldots,nw, j=1,\ldots,ns. $$
The revised simplex method is used to solve a very sparse linear programming
problem with nw + ns constraints and nw * ns
variables. If nw = ns = k, the work per iteration is
\(O(k^2)\), compared with \(O(k^3)\) when a dense simplex algorithm is used.
For more details, see Sewell (2014), Section 4.6.
Alternatively, the interior point method implemented in class
SparseLP can be used to solve the transportation problem.
Denoting the dual solution of the transportation problem as
dual, dual[i] gives the decrease in total cost per
unit increase in sources[i], for small increases, and
dual[nw + j] gives the increase in total cost per unit increase
in destinations[j].
References
Sewell, Granville (2014), Computational Methods of Linear Algebra,
third edition, World Scientific Publishing, Singapore.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumIndicates which algorithm is used to solve the transportation problem.static classMaximum number of iterations exceeded.static classAn unexpected error occurred. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondouble[]Returns the dual solution of the transportation problem.intReturns the maximum iteration number allowed in the solution of the transportation problem.intReturns the number ofjava.lang.Threadinstances used for parallel processing.double[][]Returns the optimal routing.Returns the algorithm used to solve the transportation problem.doubleReturns the total cost of the optimal routing.voidsetMaxIterations(int maxIterations) Sets the maximum number of iterations in the solver for the transportation problem.voidsetNumberOfThreads(int numberOfThreads) Sets the number ofjava.lang.Threadinstances to be used for parallel processing.voidSets the algorithm used to solve the transportation problem.final voidsolve()Solves a transportation problem using the revised simplex method or an interior-point method.
-
Constructor Details
-
Transport
public Transport(double[] sources, double[] destinations, double[][] costs) Construct the transportation problem from given sources, destinations and costs.- Parameters:
sources- adoublearray containing the source capacities. Since no internal copy of the array is made, the user should not change its content during the existence of the relatedTransportobject.destinations- adoublearray containing the destination requirements. Since no internal copy of the array is made, the user should not change its content during the existence of the relatedTransportobject.costs- adoublematrix containing the cost matrix. Ifnwis the length ofsourcesandnsthe length ofdestinations, thencostsis of sizenwbyns, andcosts[i][j]is the per unit cost to ship from sourceito destinationj. Since no internal copy of the matrix is made, the user should not change its content during the existence of the relatedTransportobject.
-
Transport
Copy constructor for the transportation problem.- Parameters:
transportProblem- theTransportobject to be copied
-
-
Method Details
-
solve
public final void solve() throws Transport.TooManyIterationsException, Transport.UnexpectedErrorException, SparseLP.DiagonalWeightMatrixException, SparseLP.CholeskyFactorizationAccuracyException, SparseLP.PrimalUnboundedException, SparseLP.PrimalInfeasibleException, SparseLP.DualInfeasibleException, SparseLP.InitialSolutionInfeasibleException, SparseLP.TooManyIterationsException, SparseLP.ProblemUnboundedException, SparseLP.ZeroColumnException, SparseLP.ZeroRowException, SparseLP.IncorrectlyEliminatedException, SparseLP.IncorrectlyActiveException, SparseLP.IllegalBoundsExceptionSolves a transportation problem using the revised simplex method or an interior-point method.- Throws:
Transport.TooManyIterationsException- is thrown by the simplex method if the maximum number of simplex steps is exceededTransport.UnexpectedErrorException- is thrown by the simplex method if an unexpected error occurredSparseLP.DiagonalWeightMatrixException- is thrown by the interior point method if a diagonal element of the diagonal weight matrix is too smallSparseLP.CholeskyFactorizationAccuracyException- is thrown by the interior point method if the Cholesky factorization failed because of accuracy problemsSparseLP.PrimalUnboundedException- is thrown by the interior point method if the primal problem is unboundedSparseLP.PrimalInfeasibleException- is thrown by the interior point method if the primal problem is infeasibleSparseLP.DualInfeasibleException- is thrown by the interior point method if the dual problem is infeasibleSparseLP.InitialSolutionInfeasibleException- is thrown by the interior point method if the initial solution for the one-row linear program is infeasibleSparseLP.TooManyIterationsException- is thrown by the interior point method if the maximum number of iterations has been exceededSparseLP.ProblemUnboundedException- is thrown by the interior point method if the problem is unboundedSparseLP.ZeroColumnException- is thrown by the interior point method if a column of the constraint matrix has no entriesSparseLP.ZeroRowException- is thrown by the interior point method if a row of the constraint matrix has no entriesSparseLP.IncorrectlyEliminatedException- is thrown by the interior point method if one or more LP variables are falsely characterized by the internal presolverSparseLP.IncorrectlyActiveException- is thrown by the interior point method if one or more LP variables are falsely characterized by the internal presolverSparseLP.IllegalBoundsException- is thrown by the interior point method if the lower bound is greater than the upper bound
-
setMaxIterations
public void setMaxIterations(int maxIterations) Sets the maximum number of iterations in the solver for the transportation problem.- Parameters:
maxIterations- anintscalar containing the maximum number of iterations allowed in the algorithm for the solution of the transportation problem.
IfSolutionMethod==RevisedSimplexMethod, then an upper bound for the simplex steps is set. FormaxIterations= 0, the number of simplex steps is unbounded.
IfSolutionMethod==InteriorPointMethod, then the maximum number of iterations in the interior-point method is set.By default,
maxIterations= 0 for the revised simplex method andmaxIterations= 200 for the interior-point method.
-
getMaxIterations
public int getMaxIterations()Returns the maximum iteration number allowed in the solution of the transportation problem.- Returns:
- an
intscalar containing the maximum number of iterations allowed for the revised simplex method or the primal-dual solver, depending on theSolutionMethodchosen
-
getDualSolution
public double[] getDualSolution()Returns the dual solution of the transportation problem.- Returns:
- a
doublearray containing the dual solution. The size of the solution isnw + ns, wherenwis the number of sources andnsis the number of destinations.
-
getTotalCost
public double getTotalCost()Returns the total cost of the optimal routing.- Returns:
- a
doublecontaining the total cost of the optimal solution
-
getOptimalRouting
public double[][] getOptimalRouting()Returns the optimal routing.- Returns:
- a
doublearray, size the same as input arraycosts, containing the optimal solution of the transportation problem
-
setSolutionMethod
Sets the algorithm used to solve the transportation problem.- Parameters:
method- aSolutionMethodconstant indicating if the revised simplex method or the interior-point method is used to solve the transportation problem.Default:
method=SolutionMethod.RevisedSimplexMethod.
-
getSolutionMethod
Returns the algorithm used to solve the transportation problem.- Returns:
- a
SolutionMethodconstant indicating if the revised simplex method or the interior-point method is used to solve the transportation problem.
-
setNumberOfThreads
public void setNumberOfThreads(int numberOfThreads) Sets the number ofjava.lang.Threadinstances to be used for parallel processing.- Parameters:
numberOfThreads- anintspecifying the number ofjava.lang.Threadinstances to be used for parallel processingDefault:
numberOfThreads= 1.
-
getNumberOfThreads
public int getNumberOfThreads()Returns the number ofjava.lang.Threadinstances used for parallel processing.- Returns:
- an
intcontaining the number ofjava.lang.Threadinstances used for parallel processing
-