Rglpk_solve_LP             package:Rglpk             R Documentation

_L_i_n_e_a_r _a_n_d _M_i_x_e_d _I_n_t_e_g_e_r _P_r_o_g_r_a_m_m_i_n_g _S_o_l_v_e_r _U_s_i_n_g _G_L_P_K

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

     High level R interface to the GNU Linear Programming Kit for
     solving linear as well as mixed integer linear programming
     problems (MILPs).

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

     Rglpk_solve_LP(obj, mat, dir, rhs, types = NULL, max = FALSE,
                    bounds = NULL, verbose = FALSE)

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

     obj: a vector with the objective coefficients

     mat: a vector or a matrix of the constraint coefficients

     dir: a character vector with the directions of the constraints.
          Each element must be one of '"<"', '"<="', '">"', '">="', or
          '"=="'.

     rhs: the right hand side of the constraints

   types: a vector indicating the types of the objective variables.
          'types' can be either '"B"' for binary, '"C"' for continuous
          or '"I"' for integer. By default all variables are of type
          '"C"'.

     max: a logical giving the direction of the optimization. 'TRUE'
          means that the objective is to maximize the objective
          function, 'FALSE' (default) means to minimize it.

  bounds: 'NULL' (default) or a list with elements 'upper' and 'lower'
          containing the indices and corresponding bounds of the
          objective variables.  The default for each variable is a
          bound between 0 and 'Inf'.

 verbose: a logical for turning on/off additional solver output:
          Default: 'FALSE'.

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

     The GNU Linear Programming Kit is open source.  The current
     version can be found at <URL:
     http://www.gnu.org/software/glpk/glpk.html>.  Package 'Rglpk'
     provides a high level solver function using the low level C
     interface of the GLPK solver.  There also exists an R interface
     done by Lopaka Lee which ports all low level C Interface routines
     of the GLPK API to R (R package 'glpk').

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

     A list containing the optimal solution, with the following
     components. 

solution: the vector of optimal coefficients

  objval: the value of the objective function at the optimum

  status: an integer with status information about the solution
          returned: 0 if the optimal solution was found, a non-zero
          value otherwise.

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

     Stefan Theussl and Kurt Hornik

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

     GNU Linear Programming Kit (<URL:
     http://www.gnu.org/software/glpk/glpk.html>).

     GLPK Interface to R  (<URL:
     http://cran.R-project.org/package=Rglpk>).

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

     'lp' in package 'lpSolve'; 'Rsymphony_solve_LP' in package
     'Rsymphony'.

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

     ## Simple linear program.
     ## maximize:   2 x_1 + 4 x_2 + 3 x_3
     ## subject to: 3 x_1 + 4 x_2 + 2 x_3 <= 60
     ##             2 x_1 +   x_2 +   x_3 <= 40
     ##               x_1 + 3 x_2 + 2 x_3 <= 80
     ##               x_1, x_2, x_3 are non-negative real numbers

     obj <- c(2, 4, 3)
     mat <- matrix(c(3, 2, 1, 4, 1, 3, 2, 2, 2), nrow = 3)
     dir <- c("<=", "<=", "<=")
     rhs <- c(60, 40, 80)
     max <- TRUE

     Rglpk_solve_LP(obj, mat, dir, rhs, max = max)

     ## Simple mixed integer linear program.
     ## maximize:    3 x_1 + 1 x_2 + 3 x_3
     ## subject to: -1 x_1 + 2 x_2 +   x_3 <= 4
     ##                      4 x_2 - 3 x_3 <= 2
     ##                x_1 - 3 x_2 + 2 x_3 <= 3
     ##                x_1, x_3 are non-negative integers
     ##                x_2 is a non-negative real number

     obj <- c(3, 1, 3)
     mat <- matrix(c(-1, 0, 1, 2, 4, -3, 1, -3, 2), nrow = 3)
     dir <- c("<=", "<=", "<=")
     rhs <- c(4, 2, 3)
     types <- c("I", "C", "I")
     max <- TRUE

     Rglpk_solve_LP(obj, mat, dir, rhs, types, max)

     ## Same as before but with bounds replaced by
     ## -Inf <  x_1 <= 4
     ##    0 <= x_2 <= 100
     ##    2 <= x_3 <  Inf

     bounds <- list(lower = list(ind = c(1L, 3L), val = c(-Inf, 2)),
                    upper = list(ind = c(1L, 2L), val = c(4, 100)))
     Rglpk_solve_LP(obj, mat, dir, rhs, types, max, bounds)

