Using gurobi with java vs gurobi with ampl

1.7k views Asked by At

What are the advantages of using Gurobi with AMPL instead of using Gurobi direct API (java, C#, C++, etc.) for solving large MIP problems? Are there performance benefits when using Gurobi's API instead of AMPL?

2

There are 2 answers

3
David Nehme On BEST ANSWER

Up until the mid 90's the only practical options for using a MIP solver with large scale problems (so excluding spreadsheets) were

At the time, for MIP models of nontrivial complexity, the AMPL models would be much more concise, readable and easier to maintain. Even today and AMPL model is going to look much more like a mathematical formulation than anything else.

One advantage of AMPL is its data structures, however today the standard libraries for C#, Java and C++ all have great data structures. Another advantage of AMPL is that its syntax looks very intuitive

subject to {j in J} sum {i in I} x[i,j] <= b[j]

but the new C++0x and the latest versions of Java have syntax that more closely mimics this.

AMPL is portable between solvers, however the interfaces don't differ that much between solvers. While it's not a trivial task to port an application from one solver to another, for me it hasn't been as big of a deal as trying to switch databases (say from MySQL to Postgres).

There are some specific disadvantages of AMPL. For most business applications, introducing AMPL to a project means adding another programming language to the mix. Time spent learning AMPL will be useful only for writing math programming models. AMPL has a tiny user base compared with Java, C# or even C++ and improvements to the underlying technology come from only one small company (full of very smart people, but a single small company nonetheless). If you want to use a hybrid approach to solving your optimization problem (for example, a column generation strategy with a heuristic to generate additional columns), you are left to some kludges. If you want to do something like run your solver until 1% of optimality, but run for at least 10 seconds, you can't do that with AMPL, but could do it with callbacks using one of the Gurobi APIs.

Python may offer the best of both worlds. It is a general purpose programming language that is a wide variety of application areas. Gurobi has its own Python API, but there are internal domain specific languages like PuLP and Pyomo which portable between solvers.

0
vitaut On

There are several advantages of using AMPL with Gurobi compared to Gurobi API:

  1. The ability to easily switch to other solvers if you'll need it in the future.
  2. Declarative AMPL models are usually easier to read and are more high-level than procedural code that is used to construct problems via an API.
  3. AMPL isolates the solver process which can be beneficial for large problems. For example, if the solver runs out of memory this will not affect AMPL.
  4. AMPL provides built-in functionality to import data from and export to databases and spreadsheets.
  5. AMPL has an active community which is arguably larger than the one of any individual solver including Gurobi. For example, AMPL Google Group has over 1700 members and growing rapidly. Of course, AMPL cannot compete with general-purpose languages like C++ or Java in terms of user base, but only a tiny fraction of C++ or Java users do mathematical optimization.

There might be performance benefits when using the Gurobi API directly, at least the native C API. However, the overhead added by AMPL is usually small compared to the solution time, especially in the case of MIP problems.

Disclaimer: I am a software developer at AMPL.