[R] Optimization help
Petr Savicky
savicky at cs.cas.cz
Mon Jul 30 20:17:41 CEST 2012
On Mon, Jul 30, 2012 at 06:51:47AM -0700, Megh Dal wrote:
> Hi, I have following optimization problem:
>
> Min: x1 + x2 +...+ x7
> subject to:
>
> x1 + x2 >= 80
> x2 + x3 >= 65
> x3 + x4 >= 40
>
> all xi are ***positive integer***.
>
> Can somebody help me in this optimization problem?
Hi.
As stated, there are no constraints on x5, x6, x7. So, these will be 0.
Try the following
library(lpSolve)
mat <- rbind(
c(1, 1, 0, 0),
c(0, 1, 1, 0),
c(0, 0, 1, 1))
obj <- rep(1, times=ncol(mat))
dir <- rep(">=", times=nrow(mat))
rhs <- c(80, 65, 40)
out <- lp("min", objective.in=obj, const.mat=mat, const.dir=dir, const.rhs=rhs, all.int=TRUE)
out$solution
[1] 55 25 40 0
Hope this helps.
Petr Savicky.
More information about the R-help
mailing list