[R] Semi continous variable- define bounds using lpsolve
Hans W. Borchers
hwborchers at googlemail.com
Wed Sep 23 00:57:47 CEST 2009
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.
More information about the R-help
mailing list