On Thu, May 24, 2012 at 07:16:20AM -0700, Haio wrote: > 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??
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. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.