8
$\begingroup$

When working with Gurobi, CPLEX and the like the user can choose between many different APIs, for example Python, C++, R, Java, Matlab or C. Some of these API are more efficient than others. For example, in R the user does not need to declare any data types like int, str and the like. R tries to find this out on its own while interpreting the code. This obviously comes with the cost that R code is slower interpreted than, for example, the same code written in C++.

Thus, when writing optimization models it might happen that the same model is built faster in one API than in another. However, I was wondering what happens when the model has been built and it is passed to Gurobi (or CPLEX)? Will the the API have additional effects on the solution times of Gurobi? Or does Gurobi solve equally fast with all the APIs? Formulated in a different way: will gurobi(model) in R, model.optimize() in Python or C++ take the same amount of time (for the same model) in all the APIs or does the choice of API affect the time needed to find the optimum of the model passed to Gurobi?

$\endgroup$
8
$\begingroup$

In addition to @Richard's answer:
The time for setting up the model, i.e. declaring variables and constraints, surely depends on the programming language you use. After the model is ready, solving does no longer depend on the language unless you use callbacks while doing the optimization. This is a more advanced technique where for example you provide the solver with feasible (not necessarily optimal) solutions (e.g. by a custom made heuristic) or you calculate cutting planes based on the current relaxation. In this cases the time spent in the callback depends on the programming language (and of course on your skill when implementing the calculations).

In most cases, when using the programming language only to set up the problem, a larger amount of time will be spent by the solver computing the solution compared to the time needed to set up the model.

| improve this answer | |
$\endgroup$
8
$\begingroup$

Once it’s passed to the underlying C library, it does not matter which API it came from. However, there may be some overhead when you are retrieving the solution through the API (for the same reasons that you ready mentioned).

| improve this answer | |
$\endgroup$
  • 1
    $\begingroup$ Time for setting up the model surely might depend on the programming language you choose. If the model is ready, solving does no longer depend on the language UNLESS you use some callbacks. Then the solving time depends on the speed that the calculations in the callbacks take - thus here it matters. $\endgroup$ – JakobS Jun 4 '19 at 11:56
  • $\begingroup$ I agree @LarrySnyder610 , I actually totally forgot about callbacks and that might be interesting whether there is a big performance hit on that. Does anyone know? $\endgroup$ – Richard Jun 4 '19 at 13:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.