Decision Optimization

Decision Optimization

Delivers prescriptive analytics capabilities and decision intelligence to improve decision-making.

 View Only
  • 1.  CPLEX in Python vs C++ and C

    Posted Thu November 21, 2019 12:27 PM

    Originally posted by: amindehghanian


    Hello,

     

    As you know Python is a high level language, and it is easier to work with. However, I expect CPLEX to perform more weakly in Python compared to C and C++. I was wondering if there is any systemic study which clarifies how much we are losing when we use CPLEX in Python vs C and C++.

     

    Thanks


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: CPLEX in Python vs C++ and C

    Posted Thu November 21, 2019 02:33 PM

    I'm not aware of any studies, but I suspect the answer is likely to be (a) not much in percentage terms and (b) it depends on what you are doing. Bear in mind that most of the computing is being done in the same CPLEX library regardless of which API you use (particularly when solving MIPs, as opposed to LPs, since MIPs have longer solve times than comparable size LPs). For large models, your code will spend some time building the model, and there some programming languages may be faster than others. Also, if you are using a decomposition technique (such as Dantzig-Wolfe or Benders) or using custom heuristics or branching strategies via callbacks, your code will be running interspersed with CPLEX (as opposed to a traditional LP/MIP solution, in which your code starts the solver and then just sits back and waits for the result). In those cases, efficiency of your code will matter, although I suspect that in most instances the time your code is executing will be considerably less than the time CPLEX is executing.

    Bottom line: I don't think CPLEX performs "more weakly" using one API than another, since the bulk of what CPLEX does is handled by a highly optimized library (written in C, I think) regardless of which API you use.


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: CPLEX in Python vs C++ and C

    Posted Thu November 21, 2019 04:02 PM

    Originally posted by: amindehghanian


    Thanks for your reply Paul!

     

    Q1. Do you mean if I am using callback functions, choice of API matters?

    Q2. Do you mean that API influences the time necessary to construct the MIP  (LP) problem?

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: CPLEX in Python vs C++ and C

    Posted Thu November 21, 2019 04:25 PM

    Potentially. It depends on what you are doing inside the callbacks. If you are just recording things like the current incumbent value or number of nodes so far, or doing basic branching decisions, probably not. If you are solving some complicated subproblem each time the callback is invoked, potentially yes. If you are doing something complicated in the callback, but you are doing it using third-party libraries, then it is at least in part a question of how fast the libraries are. For instance, in one project I may need to do matrix decompositions (QR, SVD) in a callback. If I were writing my own matrix decomposition code (and if I knew what I was doing), C or C++ might be measurably faster than Java, which might be faster than Python. On the other hand, if I'm calling a library, then using Java to call a library coded in C with a Java wrapper is not much slower than calling the same library from C or C++.

    You need to ask yourself where most of your CPU cycles will be spent. If they will be spent by CPLEX crunching an LP/MIP or by some other library, I don't think you need to worry about which language you are using. The stuff your code typically does (setting up models, retrieving solutions, ...) tends to be a small portion of the overall run time. Usually.


    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: CPLEX in Python vs C++ and C

    Posted Thu November 21, 2019 05:34 PM

    Originally posted by: amindehghanian


    Thank you so much!


    #CPLEXOptimizers
    #DecisionOptimization