Skip to content

Upper an lower bound in linear programing

2 messages · Haio, Petr Savicky

#
Hello everyone!
I?m trying to solve a linear optimization problem with r using the LPsolve
function and i want to set upper and lower bounds for the obejctive
function.  Any idea?s on how to do this??


--
View this message in context: http://r.789695.n4.nabble.com/Upper-an-lower-bound-in-linear-programing-tp4631202.html
Sent from the R help mailing list archive at Nabble.com.
#
On Thu, May 24, 2012 at 07:16:20AM -0700, Haio wrote:
Hello:

The formulation of an LP problem allows to use the objective
function also as a row in the constraint matrix. So, it is
possible to set a constraint on it. For example,
maximizing x + y
under the constraints
  x/4 <= y <= 2 + x/3
  x + y <= 9  (constraint on the objective function)
may be done as follows

  library(lpSolve)
 
  crit <- c(1, 1)
  mat <- rbind(
  c(-1/4, 1),
  c(-1/3, 1),
  c( 1,   1))
  dir <- c(">=", "<=", "<=")
  rhs <- c(0, 2, 9)
 
  out <- lp("max", objective.in=crit, const.mat=mat, const.dir=dir, const.rhs=rhs)
  out

  Success: the objective function is 9

  out$solution

  [1] 7.2 1.8

Hope this helps.

Petr Savicky.