问题
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?
回答1:
Up until the mid 90's the only practical options for using a MIP solver with large scale problems (so excluding spreadsheets) were
- creating mps files
- using the low-level C interface (known as the callable library in cplex)
- using a domain specific language like AMPL or GAMS.
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.
回答2:
There are several advantages of using AMPL with Gurobi compared to Gurobi API:
- The ability to easily switch to other solvers if you'll need it in the future.
- 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.
- 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.
- AMPL provides built-in functionality to import data from and export to databases and spreadsheets.
- 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.
来源:https://stackoverflow.com/questions/26858236/using-gurobi-with-java-vs-gurobi-with-ampl