Best modelling language for modelling LP/MILP? (NOT solver)
Asked Answered
T

4

9

I have a Gurobi licence and I am after a good MILP/LP modelling language, which should be

  1. free/open source

  2. intuitive, i.e. something that looks like (taken from MiniZinc)

    var int: x; constraint x >= 0.5; solve minimize x;

  3. fast: the time to build the model and send it to Gurobi should be of similar order to the best ones (AMPL GAMS etc.)

  4. flexible/powerful (ability to deal with 3D+ arrays, activate/deactivate constraints easily, provide initial solutions to the solver, etc.)

Of course, and correct me if I'm wrong, AMPL GAMS fail at 1), Python and R fail at 2) (and perhaps at 3)?).

How about GLPK, Minizinc, ZIMPL etc.? They satisfy 1) and 2) but what about 3) and 4)? Are they as good as AMPL in this regard? If not, is there a modelling language satisfying 1-4?

Thais answered 6/4, 2018 at 5:36 Comment(0)
O
5

I've used AMPL with Gurobi for mid-sized MIPs (~ 100k-1m variables?) and MiniZinc, mostly with Gecode, for smaller combinatorial problems. I've seen some Gurobi work done with R and Python, but haven't used it that way myself.

I'm less familiar with the other options. My understanding is that GAMS is quite similar to AMPL and much of what I have to say about AMPL may also be valid for GAMS, but I can't vouch for it.

Of course, and correct me if I'm wrong, AMPL GAMS fail at 1),

Yes, generally. There is an exception which probably isn't helpful for your specific requirements but might be useful to others: you can get free use of AMPL, Gurobi, and many other optimisation products, by using the NEOS web service. This is restricted to academic non-commercial purposes and you have to grant NEOS certain rights in relation to the problems you send them; definitely read those terms of service before using it. It also requires waiting for an available server, so if speed is a high priority this probably isn't the solution for you.

Python and R fail at 2) (and perhaps at 3)?).

In my limited experience, yes for (2). AMPL, GAMS, and MiniZinc are designed specifically for defining optimisation problems, so it's unsurprising that their syntax is more user-friendly for that purpose than languages like Python and R.

The flip-side to this is that if you want to do just about anything other than defining an optimisation problem with these languages, Python/R/etc. will probably be better for that purpose.

On speed: for the problems I usually work with, AMPL takes maybe a couple of seconds to build and presolve a MIP model which takes Gurobi a couple of minutes to solve. Obviously this is going to vary somewhat with hardware and details of the problem, but in general I would expect build time to be small compared to solve time for any of the solutions under discussion. Even with a good solver like Gurobi, big MIPs are hard. Many of the serious optimisation programmers I've met do use Python, so I presume the performance side is good enough.

However, that doesn't mean the choice of language/platform is irrelevant to speed. One of the nice features of AMPL (and also GAMS) is presolve, which attempts to reduce the problem size before sending it to the solver. My standard problems have a lot of redundant variables and constraints; AMPL identifies and eliminates many of these, reducing the problem size by about 80% and giving a noticeable improvement in solver time (as compared to runs where I switch off presolve, which I sometimes do for debugging-related reasons). This might be a consideration if you expect a lot of redundancy.

flexible/powerful (ability to deal with 3D+ arrays, activate/deactivate constraints easily, provide initial solutions to the solver, etc.)

MiniZinc handles up to 6D arrays, which may or may not be enough depending on your applications.

It's more flexible than AMPL in some areas and less so in others. AMPL has a lot of set-based functionality that I find useful (e.g. I can define a variable whose index set is something like "pairs of non-identical cities separated by no more than 500 km") and MiniZinc doesn't have this. OTOH, MiniZinc seems to be better than AMPL for solver-hopping, e.g. if I write a MZ model with a combinatorial constraint like "alldifferent" but then try to run it on a solver that doesn't recognise such constraints, MZ will translate it into something the solver can deal with.

I haven't tried deactivating constraints in MZ other than by commenting them out, so I can't help there, and similarly on providing initial solutions.

Overall, MiniZinc is a good choice to consider. Some pluses and minuses relative to AMPL ("free" being a big plus!) but it fills a similar niche.

Ourself answered 7/4, 2018 at 15:16 Comment(1)
Thank you for your very detailed answer.Thais
N
4

IMHO, there is no such system if you consider the Python interfaces/modeling environments to SCIP or Gurobi too complicated:

x = model.addVar()
y = model.addVar(vtype="INTEGER")
model.setObjective(x + y)
model.addCons(2*x - y*y >= 0)
model.optimize()

To me this looks quite natural and straight forward. The immense benefit of using an actual programming language instead of modeling language is that you can do anything in there, while there will always be boundaries in the latter.

If you are a looking for a modeling GUI, you should check out LITIC. It can be used almost entirely with drag-and-drop operations: https://litic.com/showcase.html

Northwester answered 8/4, 2018 at 20:7 Comment(1)
Thanks, that looks very natural indeed. I think that's what I'm after!Thais
J
4

I've used a lot of the options mentioned, and some not yet mentioned

  • GAMS
  • GAMS' Python API
  • GAMS' MATLAB API
  • AMPL
  • FICO Xpress Mosel
  • FICO Xpress Model's Python API
  • IBM ILOG OPL
  • Gurobi's Python API
  • PuLP (Python)
  • Pyomo (Python)
  • Python-MIP
  • JuMP (Julia)
  • MATLAB Optimization Toolbox
  • Google OR-Tools

Based on your requirements, I'd suggest trying Python-MIP, PuLP or JuMP. They are free and have easy syntax with no limit on array dimensionality.

Jaymejaymee answered 18/7, 2018 at 17:19 Comment(0)
V
0

Take a look at Google or-tools. I’m not sure if getting initial solution to the solver is available in all of its interfaces, but if you use it in python, it should probably satisfy all 1-4.

Visitation answered 7/4, 2018 at 4:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.