solveLP               package:linprog               R Documentation

_s_o_l_v_e _L_i_n_e_a_r _P_r_o_g_r_a_m_m_i_n_g / _O_p_t_i_m_i_z_a_t_i_o_n _p_r_o_b_l_e_m_s

_D_e_s_c_r_i_p_t_i_o_n:

     Minimizes c'x, subject to A x >= b and x >= 0.

_U_s_a_g_e:

        solveLP( cvec, bvec, Amat, maximum=FALSE, maxiter=1000,
                 zero=1e-10, lpSolve=FALSE, verbose=FALSE )

_A_r_g_u_m_e_n_t_s:

    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)?

 maxiter: maximum number of iterations.

    zero: numbers smaller than this value (in absolute terms) are set
          to zero.

 lpSolve: logical. Should the package 'lpSolve' be used to solve the LP
          problem?

 verbose: an optional logic variable to indicate whether interim
          results should be printed.

_D_e_t_a_i_l_s:

     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 (<URL:
     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
     <URL: ftp://ftp.es.ele.tue.nl/pub/lp_solve>).
      Equality constraints are not implemented yet.

_V_a_l_u_e:

     '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 (is negative if it
          equals 'maxiter').

   iter2: iterations of Simplex algorithm in phase 2 (is negative if it
          equals 'maxiter').

  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.

 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.

_A_u_t_h_o_r(_s):

     Arne Henningsen ahenningsen@agric-econ.uni-kiel.de

_R_e_f_e_r_e_n_c_e_s:

     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), Einfhrung
     in die landwirtschaftliche Betriebslehre. Allgemeiner Teil, 5th
     ed., Ulmer, Stuttgart.

     Witte, Thomas; Jrg-Frieder Deppe and Axel Born (1975), Lineare
     Programmierung. Einfhrung fr Wirtschaftswissenschaftler,
     Gabler-Verlag, Wiesbaden.

_S_e_e _A_l_s_o:

     'readMps' and 'writeMps'

_E_x_a_m_p_l_e_s:

     ## example of Steinhauser, Langbehn and Peters (1992)
     ## Not run: library( linprog )

     ## Production activities
     cvec <- c(1800, 600, 600)  # gross margins
     names(cvec) <- c("Milk","Bulls","Pigs")

     ## Constraints (quasi-fix factors)
     bvec <- c(40, 90, 2500)  # endowment
     names(bvec) <- c("Land","Stable","Labor")

     ## Needs of Production activities
     Amat <- rbind( c(  0.7,   0.35,   0 ),
                    c(  1.5,   1,      3 ),
                    c( 50,    12.5,   20 ) )

     ## Maximize the gross margin
     solveLP( cvec, bvec, Amat, TRUE )

     ## example 1.1.3 of Witte, Deppe and Born (1975)
     ## Not run: library( linprog )

     ## Two types of Feed
     cvec <- c(2.5, 2 )  # prices of feed
     names(cvec) <- c("Feed1","Feed2")

     ## Constraints (minimum (<0) and maximum (<0) contents)
     bvec <- c(-10, -1.5, 12)
     names(bvec) <- c("Protein","Fat","Fibre")

     ## Matrix A
     Amat <- rbind( c( -1.6,  -2.4 ),
                    c( -0.5,  -0.2 ),
                    c(  2.0,   2.0 ) )

     ## Minimize the cost
     solveLP( cvec, bvec, Amat )

     ## There are also several other ways to put the data into the arrays, e.g.:
     bvec <- c( Protein = -10.0,
                Fat     =  -1.5,
                Fibre   =  12.0 )
     cvec <- c( Feed1 = 2.5,
                Feed2 = 2.0 )
     Amat <- matrix( 0, length(bvec), length(cvec) )
     rownames(Amat) <- names(bvec)
     colnames(Amat) <- names(cvec)
     Amat[ "Protein", "Feed1" ] <-  -1.6
     Amat[ "Fat",     "Feed1" ] <-  -0.5
     Amat[ "Fibre",   "Feed1" ] <-   2.0
     Amat[ "Protein", "Feed2" ] <-  -2.4
     Amat[ "Fat",     "Feed2" ] <-  -0.2
     Amat[ "Fibre",   "Feed2" ] <-   2.0
     solveLP( cvec, bvec, Amat )

