pragathichi
2009-Sep-22 10:34 UTC
[R] Semi continous variable- define bounds using lpsolve
How to define bounds for a semi continous variable in lp_solve. Min 5x1 +9x2 +7.15x3 +0.1x4 subject to x1+x2+x3+x4=6.7 x1+x4 <= 6.5 And x3 can be 0 or greater than 3.6 hence x3 is a semi continous variable how to define bounds as well as semicontinous function because using set.semicont and set. bound simantaneously doesn't seem to work.Thanks in advance for the help -- View this message in context: http://www.nabble.com/Semi-continous-variable--define-bounds-using-lpsolve-tp25530668p25530668.html Sent from the R help mailing list archive at Nabble.com.
Hans W. Borchers
2009-Sep-22 20:56 UTC
[R] Semi continous variable- define bounds using lpsolve
I played around a bit with the original 'lp-solve' program --- i.e., not the R package but the program to be downloaded from Sourceforge ---, at least version 5.5.0.15 through its IDE. I was not even able to reproduce the example on semi-continuous variables in the reference documentation at <http://lpsolve.sourceforge.net/5.5/>. It appears as if a bug has been introduced in newer versions of 'lp-solve' that prevent these semi-continuous variables from being handled correctly. So maybe it's not the fault of the R package 'lpsolve' and can only be amended by the 'lp-solve' team itself. Hans Werner pragathichi wrote:> > How to define bounds for a semi continous variable in lp_solve. > Min 5x1 +9x2 +7.15x3 +0.1x4 > subject to > x1+x2+x3+x4=6.7 > x1+x4 <= 6.5 > And x3 can be 0 or greater than 3.6 > hence x3 is a semi continous variable > how to define bounds as well as semicontinous function because using > set.semicont and set. bound simantaneously doesn't seem to work.Thanks in > advance for the help >-- View this message in context: http://www.nabble.com/Semi-continous-variable--define-bounds-using-lpsolve-tp25530668p25530901.html Sent from the R help mailing list archive at Nabble.com.
Hans W. Borchers
2009-Sep-22 22:57 UTC
[R] Semi continous variable- define bounds using lpsolve
But of course, it is always possible to emulate a semi-continuous variable by introducing a binary variable and use some "big-M" trick. That is, with a new binary variable b we add the following two conditions: x3 - 3.6 * b >= 0 and x3 - 10 * b <= 0 # Big-M trick, here M >= 10 (If b = 0, then x3 = 0, and if b = 1, then x3 >= 3.6 !) As I do not trust 'lpSolve' too much anymore I used package 'Rglpk' with the following code: #-- snip --- library(Rglpk) obj<- c(5, 9, 7.15, 0.1, 0) mat <- matrix(c(1,1,1,1,0, 1,0,0,1,0, 0,0,1,0,-3.6, 0,0,1,0,-10, 0,0,0,0,1), byrow=TRUE, ncol=5) dir <- c("==", "<=", ">=", "<=", "<=") rhs <- c(9, 6.55, 0, 0, 1) types <- c("C", "C", "C", "C", "I") max <- FALSE Rglpk_solve_LP(obj, mat, dir, rhs, types, max = max) # $optimum # [1] 22.705 # # $solution # [1] 0.00 2.45 0.00 6.55 0.00 # # $status # [1] 0 #-- snap --- Semi-continuous variables are sometimes preferred as with a good implementation the solution is reached much faster (that's why I suggested them), but they can always be modelled with binary variables. Hans Werner pragathichi wrote:> > How to define bounds for a semi continous variable in lp_solve. > Min 5x1 +9x2 +7.15x3 +0.1x4 > subject to > x1+x2+x3+x4=6.7 > x1+x4 <= 6.5 > And x3 can be 0 or greater than 3.6 > hence x3 is a semi continous variable > how to define bounds as well as semicontinous function because using > set.semicont and set. bound simantaneously doesn't seem to work.Thanks in > advance for the help >-- View this message in context: http://www.nabble.com/Semi-continous-variable--define-bounds-using-lpsolve-tp25530668p25530929.html Sent from the R help mailing list archive at Nabble.com.
Seemingly Similar Threads
- semi-continuous variables in lpSolve package
- R and marine protected areas: algorithms for site selection
- lpSolve doesn't compile because of a malloc.h error
- Solve linear program without objective function
- Package Installation produces "linux/limits.h: No such file or directory" error when installing the lpSolve package