Since Gurobi is essentially a library for performing mathematical optimization, it will always be integrated in an application. The first benchmark in benchmarking Gurobi against other solvers is therefore to perform this integration into an existing codebase. In this article we describe the various scenarios you may encounter, and how to integrate Gurobi for the purpose of benchmarking.
Note: After you have completed benchmarking and in case you decide to continue working with Gurobi, you may want to change the way you integrate. For example, when using a modeling framework for benchmarking, there will be benefits in switching to our Gurobi-native APIs.
Note: All scenarios below require a Gurobi license. We provide evaluation licenses when you consider using Gurobi for your project. Feel free to reach out to us to discuss options.
Using a modeling framework
Many developers initially use a modeling framework. Such frameworks provide a unified API that allows you to define a mathematical optimization model and then choose any available solver for performing the actual optimization task. Using such a framework makes it easy to replace one solver for another during benchmarking.
We provide guidance for integrating Gurobi with the most commonly used modeling frameworks in our knowledge base. Usually this integration is a matter of installing Gurobi (as package or full installation), adding a Gurobi license key and instructing the framework to use Gurobi for optimization.
There are a few caveats when benchmarking using modeling frameworks. These are outlined in our article "What to measure during benchmarking" and include the overhead added by the frameworks, the fact that the model representation or solver parameters may be influenced by the framework and the importance of using the right measurements to get the exact solver runtime.
Using a third-party application
In some cases, you may be using a third-party application for which you may or may not have access to the source code. In such a scenario, here are the options you may consider.
- Some applications allow you to export the generated model during the solution process. If you see such an option (often labeled "MPS export"), consider generating such an export. Such an export is an exact representation of the model being solved within the application and is therefore useful for benchmarking. You can then let Gurobi solve the exported model, either through the command-line or a simple Python script that reads and solves the model.
- Consider collaborating with the application provider. They may be able to provide a (test) integration with Gurobi which allows you to benchmark an end-to-end scenario against the default solver provided with the application.
- If your application is using Gurobi already but you don't have access to the source code or call Gurobi through a third-party API, consider using the
GURO_PAR_DUMPparameter as described in this article.
Using an alternative solver directly
If you have an existing application with access to the source code and you've been using an alternative solver in the past, you might be calling the API for that solver directly. In this situation, there are two options for performing a benchmark.
- Let the other solver make an MPS export as described in the previous section and run Gurobi from the command-line. The specific instructions required depend on the solver being used, but MPS is a fairly common file format available for export in most solvers.
- Create an alternative implementation using the Gurobi API. While every solver provides a slightly different syntax and different optional features, all solvers provide similar APIs for constructing a mathematical model (create variables, constraints and objectives). Especially when you've organized your codebase in a clean way and grouped your optimization-related code in a single place, it is usually not too hard to add a second implementation that calls Gurobi.
When you don't have a model yet
Sometimes, there is no implementation with any solver yet.
- When you have defined the mathematical model already (e.g. written down the variables, constraints and objectives), you may want to try an initial implementation with the Gurobi API. The translation from model to code is usually not too hard, and we're happy to answer your questions.
- When the model is yet to be defined, you may want to reach out to us first for an initial conversation. We can point you to the right resources to get you started and may be able to provide sample models that perform a similar task to what you aim to achieve.