Shuai Wang
2 min readSep 12, 2019

Construction Speed in Popular Open Source Math Modeling Tools: minizinc vs pyomo vs JuMP

In this post, we will compare the popular mathematic programming
language/package: python’s pyomo, minizinc, and Juila’s JuMP on the context of model building. Please see the other post for the syntax comparison.

The inspiration comes from that the model my colleague was built using pyomo costs about 25 minutes just to construct(1.2 million variables and 2.5
million constraints)!!!

The modeling tools I tested are: python’s pyomo, Julia’s JuMP, and Minizinc.
I used CBC as MIP solver. The machine I used has i7 6820HQ cpu with 16gb ram.

The problem is from stackoverflow:
[pyomo is slow](https://stackoverflow.com/questions/51269351/pyomo-seems-very-slow-to-write-models),
which states as:

Here are the comparisons.

python:

import pyomo.environ as pyo
import time

size = 500000
start_time = time.time()
model = pyo.ConcreteModel()
model.set = pyo.RangeSet(0, size)
model.x = pyo.Var(model.set, within=pyo.Reals)
model.constrList = pyo.ConstraintList()

for i in range(size):
model.constrList.add(expr = model.x[i] >= 1)

model.obj = pyo.Objective(expr=sum(model.x[i] for i in range(size)), sense=pyo.minimize)

opt = pyo.SolverFactory(‘cbc’, io_format=’python’)

res = opt.solve(model, report_timing=True)
print(“>>> total time () in {:.2f}s”.format(time.time() — start_time))
#print(res)

Julia


import Pkg
using JuMP
using Cbc
using Dates

a = Dates.now()

N = 500000
m=Model(with_optimizer(Cbc.Optimizer))
@variable(m,x[1:N])
@objective(m, Min, sum(x))
@constraint(m, x .>= 1)
JuMP.optimize!(m)

b=Dates.now()
print(b-a)

Minizinc

int: size = 500000; 
set of int: N = 1..size;

array[N] of var float: x;
constraint forall( n in N)(x[n] >= 1);

var float: objective = sum(n in N)(x[n]);
solve minimize objective;

The time consists of constructing and solve time. The actually solving time are approximately the same because they all call CBC as solver.

The results (in seconds) are shown below:

+----------+----------+-----------+-----------+-----------+
| Tools | N=500000 | N=1000000 | N=2500000 | N=5000000 |
+----------+----------+-----------+-----------+-----------+
| pyomo | 28 | 57 | 185 | 377 |
+----------+----------+-----------+-----------+-----------+
| JuMP | 36 | 48 | 114 | 450 |
+----------+----------+-----------+-----------+-----------+
| Minizinc | 9 | 22 | 53 | 109 |
+----------+----------+-----------+-----------+-----------+

Minizinc is the fastest, which also having the best syntax style IMO.

My current to go tool is using python’s pymzn package to call minizinc.