solveLP: Solve Linear Programming / Optimization Problems In linprog: Linear Programming / Optimization

Description

Minimizes (or maximizes) c'x, subject to A x <= b and x >= 0.

Note that the inequality signs <= of the individual linear constraints in A x <= b can be changed with argument const.dir.

Usage

 1 2 3 4 solveLP( cvec, bvec, Amat, maximum = FALSE, const.dir = rep( "<=", length( bvec ) ), maxiter = 1000, zero = 1e-9, tol = 1e-6, dualtol = tol, lpSolve = FALSE, solve.dual = FALSE, verbose = 0 )

Arguments

 cvec vector c (containing n elements). bvec vector b (containing m elements). Amat matrix A (of dimension m \times n). maximum logical. Should we maximize or minimize (the default)? const.dir vector of character strings giving the directions of the constraints: each value should be one of "<," "<=," "=," "==," ">," or ">=". (In each pair the two values are identical.) maxiter maximum number of iterations. zero numbers smaller than this value (in absolute terms) are set to zero. tol if the constraints are violated by more than this number, the returned component status is set to 3. dualtol if the constraints in the dual problem are violated by more than this number, the returned status is non-zero. lpSolve logical. Should the package 'lpSolve' be used to solve the LP problem? solve.dual logical value indicating if the dual problem should also be solved. verbose an optional integer variable to indicate how many intermediate results should be printed (0 = no output; 4 = maximum output).

Details

This function uses the Simplex algorithm of George B. Dantzig (1947) and provides detailed results (e.g. dual prices, sensitivity analysis and stability analysis).
If the solution x=0 is not feasible, a 2-phase procedure is applied.
Values of the simplex tableau that are actually zero might get small (positive or negative) numbers due to rounding errors, which might lead to artificial restrictions. Therefore, all values that are smaller (in absolute terms) than the value of zero (default is 1e-10) are set to 0.
Solving the Linear Programming problem by the package lpSolve (of course) requires the installation of this package, which is available on CRAN (http://cran.r-project.org/src/contrib/PACKAGES.html#lpSolve). Since the lpSolve package uses C-code and this (linprog) package is not optimized for speed, the former is much faster. However, this package provides more detailed results (e.g. dual values, stability and sensitivity analysis).
This function has not been tested extensively and might not solve all feasible problems (or might even lead to wrong results). However, you can export your LP to a standard MPS file via writeMps and check it with other software (e.g. lp_solve, see ftp://ftp.es.ele.tue.nl/pub/lp_solve).
Equality constraints are not implemented yet.

Value

solveLP returns a list of the class solveLP containing following objects:

 opt optimal value (minimum or maximum) of the objective function. solution vector of optimal values of the variables. iter1 iterations of Simplex algorithm in phase 1. iter2 iterations of Simplex algorithm in phase 2. basvar vector of basic (=non-zero) variables (at optimum). con matrix of results regarding the constraints: 1st column = maximum values (=vector b); 2nd column = actual values; 3rd column = differences between maximum and actual values; 4th column = dual prices (shadow prices); 5th column = valid region for dual prices. allvar matrix of results regarding all variables (including slack variables): 1st column = optimal values; 2nd column = values of vector c; 3rd column = minimum of vector c that does not change the solution; 4th column = maximum of vector c that does not change the solution; 5th column = derivatives to the objective function; 6th column = valid region for these derivatives. status numeric. Indicates if the optimization did succeed: 0 = success; 1 = lpSolve did not succeed; 2 = solving the dual problem did not succeed; 3 = constraints are violated at the solution (internal error or large rounding errors); 4 = simplex algorithm phase 1 did not find a solution within the number of iterations specified by argument maxiter; 5 = simplex algorithm phase 2 did not find the optimal solution within the number of iterations specified by argument maxiter. lpStatus numeric. Return code of lp (only if argument lpSolve is TRUE). dualStatus numeric. Return code from solving the dual problem (only if argument solve.dual is TRUE). maximum logical. Indicates whether the objective function was maximized or minimized. Tab final 'Tableau' of the Simplex algorith. lpSolve logical. Has the package 'lpSolve' been used to solve the LP problem. solve.dual logical. Argument solve.dual. maxiter numeric. Argument maxiter.

Arne Henningsen

References

Dantzig, George B. (1951), Maximization of a linear function of variables subject to linear inequalities, in Koopmans, T.C. (ed.), Activity analysis of production and allocation, John Wiley \& Sons, New York, p. 339-347.

Steinhauser, Hugo; Cay Langbehn and Uwe Peters (1992), Einfuehrung in die landwirtschaftliche Betriebslehre. Allgemeiner Teil, 5th ed., Ulmer, Stuttgart.

Witte, Thomas; Joerg-Frieder Deppe and Axel Born (1975), Lineare Programmierung. Einfuehrung fuer Wirtschaftswissenschaftler, Gabler-Verlag, Wiesbaden.