Topic
5 replies Latest Post - ‏2013-02-08T10:20:32Z by TobiasUni-Hohenheim
TobiasUni-Hohenheim
TobiasUni-Hohenheim
7 Posts
ACCEPTED ANSWER

Pinned topic Find maximum of function with 2 variables

‏2013-02-06T22:05:42Z |
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!
Updated on 2013-02-08T10:20:32Z at 2013-02-08T10:20:32Z by TobiasUni-Hohenheim
  • T_O
    T_O
    444 Posts
    ACCEPTED ANSWER

    Re: Find maximum of function with 2 variables

    ‏2013-02-06T22:52:18Z  in response to TobiasUni-Hohenheim
    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
    • TobiasUni-Hohenheim
      TobiasUni-Hohenheim
      7 Posts
      ACCEPTED ANSWER

      Re: Find maximum of function with 1 variable

      ‏2013-02-07T18:09:42Z  in response to T_O
      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!
      • SystemAdmin
        SystemAdmin
        7929 Posts
        ACCEPTED ANSWER

        Re: Find maximum of function with 1 variable

        ‏2013-02-07T22:16:09Z  in response to TobiasUni-Hohenheim
        You can't do it directly with CPLEX. You could implement a cutting plane method (which is very old-school) using CPLEX, but it would be easier to use a program designed to solve nonlinear optimization problems.

        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)
      • SystemAdmin
        SystemAdmin
        7929 Posts
        ACCEPTED ANSWER

        Re: Find maximum of function with 1 variable

        ‏2013-02-08T00:58:29Z  in response to TobiasUni-Hohenheim
        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
        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 2014-03-24T22:40:25Z at 2014-03-24T22:40:25Z by iron-man