Switching from Another Solver to Speaker Introduction

• Dr. Sonja Mars

• Technical Account Manager at Gurobi Optimization

• Ph.D. in Mathematics, FAU Erlangen-Nuremberg

• Helping people around the world with Gurobi

2 Copyright 2017, Gurobi Optimization, Inc. Overview

• Decision Criteria • Common Scenarios • Switching Examples

3 Copyright 2017, Gurobi Optimization, Inc. Optimization Projects – Decision for a Solver

4 Copyright 2017, Gurobi Optimization, Inc. Solver Overview

• Commercial solvers • For example, Gurobi or CPLEX

• Open source solvers • For example, lp_solve and GLPK

• Modeling languages and frameworks • Commercial • For example, AMPL, GAMS • Open Source • For example, , PuLP, JuMP

5 Copyright 2017, Gurobi Optimization, Inc. Decision Criteria

Criterion Advantage Budget and licensing Free tools Performance and scalability Commercial tools Professional support Commercial tools Active development Commercial tools & some free tools Deployment Commercial tools Ease of use Commercial solvers & modeling frameworks Complexity of switching later Modeling frameworks

6 Copyright 2017, Gurobi Optimization, Inc. Budget and Licensing

• Free tools: • No license fees • No licensing • Possibility to look at the code and change it

• Commercial tools: • Budget • Include licensing mechanism • Black box solver

• Get started with Gurobi for free: • Free academic licenses • Take Gurobi with you • Evaluation licenses

7 Copyright 2017, Gurobi Optimization, Inc. Performance

• Free tools: • Fast for easy problems • Many issues with real-world problems • Sometimes huge setup times for models with large data

• Commercial tools: • Optimized for real-world problems • Tuned and parallel algorithms • Light-weight APIs with fast data-handling

8 Copyright 2017, Gurobi Optimization, Inc. Performance – Comparing Solvers

• Just a few numbers for runs on 1 thread from MIPLIB 2010 benchmark set (time limit 2 hours):

Solver # of Benchmark Problems Solved Relative MIP Performance (out of the 87)

GLPK 0 (no models solved) n/a lp_solve 5 too few solved to compare CBC 53 32 SCIP + SoPlex 71 9.32 XPRESS 86 1.51 CPLEX 87 1.42 Gurobi 87 1.0 (fastest)

• More numbers can be found here: http://plato.asu.edu/ftp/milpc.html

9 Copyright 2017, Gurobi Optimization, Inc. Performance – Comparing API and Modeling Tools

• Build and solve the same model (2500000 variables, 5000 constraints and 500848 nonzeros)

API Runtime in seconds

Gurobi’s Python API 22 JuMP 40 Pyomo 146 PuLP 203

• Gurobi solve run just takes 3 seconds

10 Copyright 2017, Gurobi Optimization, Inc. Professional Support

• Free tools: • Motivated developers but limited support

• Commercial tools: • Dedicated team of experts • At Gurobi: • PhD level support • Fast response times guaranteed • Offers 2 hours free consulting • Parameter tuning

11 Copyright 2017, Gurobi Optimization, Inc. Active Development

• Commercial tools: • Continual performance improvements • Dedicated team of experts

Gurobi Development over time – number of unsolved models 600 538

500 456

400 371 335 286 300 200 200 92 100 46

0 v1.1 v2.0 v3.0 v4.0 v5.0 v6.0 v7.0 v7.5

Time limit: 10000 sec. MIP test set has 3420 models: Intel Xeon CPU E3-1240 v3 @ 3.40GHz - 217 discarded due to inconsistent answers 4 cores, 8 hyper-threads - 788 discarded that none of the versions can solve 32 GB RAM

12 Copyright 2017, Gurobi Optimization, Inc. Deployment

• Free solvers: • Support of different operating systems very limited • As source code is available • Can be compiled for a lot of systems • No additional support if issues occur

• Modeling frameworks: • Another software that needs to be deployed • Sometimes complicated because file based

• Commercial solvers: • Available for a lot of operating systems • Flexible reaction on new situations

13 Copyright 2017, Gurobi Optimization, Inc. Ease of Use

• Free solvers: • Sometimes only or C++ APIs • Complicated usage

• Modeling frameworks: • Nice syntax • Easy to learn

• Commercial solvers: • APIs in all popular programming languages • At Gurobi: • Additional nice extensions for Python

14 Copyright 2017, Gurobi Optimization, Inc. Complexity of Switching

• Free and commercial solvers: • Use their own APIs • Not designed to make switching easy

• Modeling frameworks: • Very easy to change solvers

15 Copyright 2017, Gurobi Optimization, Inc. Time to Switch?

16 Copyright 2017, Gurobi Optimization, Inc. Common Scenarios …

… we’ve seen from our customers

• “Our model is getting larger and takes too long to solve with a free solver.”

• “Our model is getting more complex and a competing commercial solver is running into performance issues.”

• “The results we are getting are not robust and reliable.”

• “We need help on parameter tuning.”

17 Copyright 2017, Gurobi Optimization, Inc. First Test

• Export MPS files to check performance • How to export MPS files: http://www.gurobi.com/resources/switching-to-gurobi/exporting--files- from-competing-solvers

• Ask for a Gurobi evaluation license

• Run MPS File in Gurobi: gurobi_cl TimeLimit=3600 MIPGap=0.01 myModel.mps

• Or send the files to [email protected]

18 Copyright 2017, Gurobi Optimization, Inc. Common Scenarios …

… when switching to Gurobi is a good idea

• Robustness • Scalability • Gurobi Compute Server • Solving speed • Maintenance and support

19 Copyright 2017, Gurobi Optimization, Inc. Switching Examples

20 Copyright 2017, Gurobi Optimization, Inc. The Gurobi Python API – a short Overview

m = Model("mip")

x = m.addVar(vtype=GRB.BINARY, name="x") y = m.addVar(vtype=GRB.CONTINUOUS, name="y") z = m.addVar(vtype=GRB.INTEGER, name="z")

m.setObjective(x + y + 2 * z, GRB.MAXIMIZE)

m.addConstr(x + 2 * y + 3 * z <= 4, "c0") m.addConstr(x + y >= 1, "c1")

m.optimize()

21 Copyright 2017, Gurobi Optimization, Inc. The Gurobi Python API – a few nice Features

• Old: x= {} for i in I: for j in J: x[i,j] = model.addVar(obj=costs[i,j])

for i in I: model.addConstr(sum(x[i,j] for j in J) == d[i])

• New: x = model.addVars(I, J, obj=costs)

model.addConstrs(x.sum(i, '*’) == d[i] for i in I)

22 Copyright 2017, Gurobi Optimization, Inc. The Gurobi Python API – a few nice Features

• A network flow problem: • Lists commodities, nodes, tuplelist arcs and dictionaries inflow, cost, capacity

• Add variables: flow = m.addVars( commodities, arcs, obj=cost, name="flow" )

• Add capacity constraints: m.addConstrs( (flow.sum('*',i,j) <= capacity[i,j] for i,j in arcs), "cap" )

• Add flow conservation constraints: m.addConstrs( (flow.sum(h,'*',j) + inflow[h,j] == flow.sum(h,j,'*') for h in commodities for j in nodes), "node" )

23 Copyright 2017, Gurobi Optimization, Inc. Switching Solvers inside Modeling Frameworks

• Only need to change this line: • PuLP prob.solve( GUROBI_CMD() ) • Pyomo opt = SolverFactory('gurobi') • JuMP m = Model( solver=GurobiSolver() ) • AMPL option solver gurobi_ampl; • GAMS Option MIP = Gurobi;

• Adjustment needed for solver parameters

24 Copyright 2017, Gurobi Optimization, Inc. Switching from PuLP

• PuLP • Gurobi’s Python API prob = LpProblem( "assignment", LpMinimize ) m = Model( "assignment" )

x = LpVariable.dicts( ”x", (workers, shifts), x = m.addVars( avail, ub=1, name="x" ) 0, 1, LpContinuous )

prob += lpSum( [pay[w] * x[w][s] m.setObjective( quicksum(pay[w]*x[w,s] for w in workers for w,s in avail ), for s in shifts] ), "" GRB.MINIMIZE )

for s in shifts: reqCts = m.addConstrs( prob += lpSum( [avail[w, s] * x[w][s] ( x.sum('*', s) == shiftReq[s] for w in workers for s in shifts ), "_" ) if avail[w, s] != 0] ) == shiftReq[s], ""

prob.solve( GUROBI_CMD() ) m.optimize()

25 Copyright 2017, Gurobi Optimization, Inc. More Help

• Gurobi website • Documentation • Examples

26 Copyright 2017, Gurobi Optimization, Inc. Getting Started

• Get started with Gurobi for free: • Free Academic (site) licenses • Take Gurobi With You (TGWY) Program for your transition into industry • Working with Gurobi consulting partners • Obtain free evaluation licenses • PhD level support • Offers 2 hours free consulting • Parameter tuning

• Ask [email protected] for a free Gurobi evaluation license • Run MPS file in Gurobi: gurobi_cl TimeLimit=3600 MIPGap=0.01 myModel.mps or • Send the files to [email protected]

27 Copyright 2017, Gurobi Optimization, Inc.