Skip to content

Quadratic Constraints

4 messages · vikrant S, Hans W Borchers

#
HI All,
I am unable to solve a optimization Problem Please Help Me out of this to
solve. The Optimization problem is as follows :- 
My objective function is linear and one of the constraint is quadratic. 

Min z = 5 * X1 + 9* X2  + 7.15 *X3 + 2 * X4
subject to
 X1 + X2 + X3 +X4  = 9
 X1  + X4 < = 6.55
 X3(X3 - 3.5) >=0
 X1,X2,X3,X4 >=0
 Now the problem is how to solve this kind of problem. Which package should
be used to handle such problems. Please explain with an example. 
Another problem is that I have to cases to  be solve in this problem.
case 1:-) If X3 = 0
case 2 :-) If X3 > 0 then X3 > 3.6
I want to handle both this case in one problem so the quadratic constraints
is written
The thing is that I want to evaluate my objective function for both cases
and which ever is optimum that solution i need,
Here I don't want to use the If Else condition and repeat the program. IS
there any other better way in which i could solve this problem?
If not please try to provide me the solution for my original problem having
a quadratic constraint.
#
The package lpSolve (that I have recommended before) supports so-called
'semi-continuous variables', that is

    "Semi-continuous variables are variables that must take a value between
    their their minimum and maximum or zero. So these variables are treated
    the same as regular variables, except that a value of zero is also
    accepted, even if a minimum bigger than zero is set on the variable."

which exactly how you want to handle your variable x3.
For an example, see the documentation at <lpsolve.sourceforge.net/5.5/>.

By the way, the minimum of your problem is 44.64 (manual calculation).
vikrant S wrote:

  
    
1 day later
#
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.