Hi there,
I am new to CPLEX. Is there a way for cplex to find the maximum of a function with 2 linear variables? For example, find maximum of
f(x,y) = 3x  2y
I was hoping cplex will give me (x,y) where f(x,y) is maximal. Of course, x and y may be in some predefined bounds.
How can I implement such a model?
Thanks!
Topic

Re: Find maximum of function with 2 variables
20130206T22:52:18ZThis is the accepted answer. This is the accepted answer.Hi Tobias,
this sounds trivial. Do you really have a linear objective function and only constraints that are in fact bounds of variables? Then you can trivially calculate the optimal value. Just take the upper or lower bound of every variable depending on the sign of the corresponding objective coefficient.
In your case, take the upper bound of x and the lower bound of y, because you are maximizing.
Of course, you can do this with CPLEX but I think you can do this faster with a trivial code.
Or are your "bounds" more difficult (e.g. linear functions)?
Best regards,
Thomas 
Re: Find maximum of function with 1 variable
20130207T18:09:42ZThis is the accepted answer. This is the accepted answer. T_O
 20130206T22:52:18Z
Hi Tobias,
this sounds trivial. Do you really have a linear objective function and only constraints that are in fact bounds of variables? Then you can trivially calculate the optimal value. Just take the upper or lower bound of every variable depending on the sign of the corresponding objective coefficient.
In your case, take the upper bound of x and the lower bound of y, because you are maximizing.
Of course, you can do this with CPLEX but I think you can do this faster with a trivial code.
Or are your "bounds" more difficult (e.g. linear functions)?
Best regards,
Thomas
f(x) = 4 * sqrt(x)  2 * x
This is not possible with cplex, or?
Thanks! 
Re: Find maximum of function with 1 variable
20130207T22:16:09ZThis is the accepted answer. This is the accepted answer. TobiasUniHohenheim
 20130207T18:09:42Z
Thanks! But sorry, it was my fault. I am looking to find the (local) maximum of a function like this:
f(x) = 4 * sqrt(x)  2 * x
This is not possible with cplex, or?
Thanks!
Paul
Mathematicians are like Frenchmen: whenever you say something to them, they translate it into their own language, and at once it is something entirely different. (Goethe) 
Re: Find maximum of function with 1 variable
20130208T00:58:29ZThis is the accepted answer. This is the accepted answer. TobiasUniHohenheim
 20130207T18:09:42Z
Thanks! But sorry, it was my fault. I am looking to find the (local) maximum of a function like this:
f(x) = 4 * sqrt(x)  2 * x
This is not possible with cplex, or?
Thanks!
var x >= 0; var y; maximize obj: 4*y  2*x; subj to ydef: y^2 <= x;
and CPLEX happily solved it:
ampl: option solver cplex; ampl: solve; CPLEX 12.5.0.0: optimal solution; objective 1.999999999 7 barrier iterations No basis. ampl: display x, y; x = 0.999999 y = 0.999999
(Probably the reported objective would be exactly 2 if you set some tolerances a little tighter.) In the documentation of the CPLEX quadratic solvers, there's some discussion of the kinds of quadratic problems that can be solved.Updated on 20140324T22:40:25Z at 20140324T22:40:25Z by ironman 
Re: Find maximum of function with 1 variable
20130208T10:20:32ZThis is the accepted answer. This is the accepted answer. SystemAdmin
 20130208T00:58:29Z
Your function f(x) is concave, so any local maximum will be globally maximal. In general you cannot solve nonlinear problems using CPLEX, but in this case your problem can be made into a conic quadratic that CPLEX can handle: maximize 4*y  2*x, subject to y^2 <= x and x >= 0. Indeed I wrote it in AMPL as
<pre class="java dw" dataeditorlang="java" datapbcklang="java" dir="ltr">var x >= 0; var y; maximize obj: 4*y  2*x; subj to ydef: y^2 <= x; </pre>
and CPLEX happily solved it:
<pre class="java dw" dataeditorlang="java" datapbcklang="java" dir="ltr">ampl: option solver cplex; ampl: solve; CPLEX 12.5.0.0: optimal solution; objective 1.999999999 7 barrier iterations No basis. ampl: display x, y; x = 0.999999 y = 0.999999 </pre>
(Probably the reported objective would be exactly 2 if you set some tolerances a little tighter.) In the documentation of the CPLEX quadratic solvers, there's some discussion of the kinds of quadratic problems that can be solved.