[R] Quadratic Constraints

vikrant S shimpi.vikrant at gmail.com
Tue Sep 22 14:00:58 CEST 2009


Hi Hans,
I am very much thankful to you for helping me to solve the problem. I went
through the
link provided by you and tried to solve the problem. But I think there's
some problem 
with the code. So it is not arriving at the optimal solution.In Some cases
it shows optimum
solution while in some it does not give optimum solution. i am writing my R 
code aong with this 
mail. Please See if i am making some mistake and help me out.
Our original problem is:- 
Miin z = 5 * X1 + 9* X2  + 7.15 *X3 + 2 * X4
subject to
 X1 + X2 + X3 +X4  = 9
 X1  + X4 < = 6.55 
Xi>= 0; i=1,2,4.
Here Ihave removed the third Quadratic constraint and  made my X3 variable
as a 
Semi Continuous variable. and define bound for it as 3.6 <= X3 <= inf.

I will write my R code for it.

library(lpSolveAPI)
lprec<-make.lp(0,4)
set.objfn(lprec,c(5,9,7.15,0.1))
add.constraint(lprec,c(1,1,1,1),"=",9)
add.constraint(lprec,c(1,0,0,1),"<=",6.55)
set.semicont(lprec,columns = 3,sc=TRUE)
set.bounds(lprec, lower = 3.6, upper = 10,columns =3)
solve(lprec)
get.objective(lprec)
get.variables(lprec)


Here the optimal solution is by this program is 26.28 and 
optimum solution is X1 = 0 , X2 = 0,X3 = 3.6, X4 = 5.4

Now I describe what is not workinig in this problem
Here if u calculate manually it should allocate maximum
no. of units from X4 i.e 6.55 as the  value associated with X4 in 
objective function is minimum  and remaining units should be taken 
from X2 as X3 should be minimum 3.6. In this case the optimum 
value is 22.70 and optimum solution should be 
 X1 = 0 , X2 = 2.45 ,X3 = 0, X4 = 6.55

However By declaring the X3 as a Semicontinuous it should
calculate the value of objective at X3 = 0 and  X3 = 3.6 automatically
and compare the optimum solutions and which ever is optimum it
should give as a solution.

Could U please Explain Me How Could I get the above descibed 
optimum solution .
.X1 = 0 , X2 = 2.45 ,X3 = 0, X4 = 6.55

Please Help me as soon as possible.



-- 
View this message in context: http://www.nabble.com/Quadratic-Constraints-tp25528480p25530692.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list