3. From the model to Python/Gurobi
Class: implementation · Script: python/cap06_gurobi.py
The course uses one solver only, Gurobi from Python. The chapter shows how a model is written — one family of constraints per block, with the names of the mathematical model — how the results are read, including the case where the solver has not finished, and three complete models that the heuristics chapter takes up again.
Every number on these pages comes from a single script,
python/cap06_gurobi.py, and the chapter is organised into five sections.
-
3.1 Writing a model in gurobipy
The basic gurobipy instructions, the four classes of variables and the rule of the course: one family of constraints per block.
-
3.2 Reading the results
Status,SolCount,ObjVal,ObjBound,MIPGap,NodeCount, and the three cases whereObjValcannot be read. -
3.3 Tolerances and relaxations
"Integer" within
IntFeasTol, andrelax()to obtain the relaxation of the model just written. -
3.4 Three classic models
Bin packing, makespan and travelling salesman, from the statement to the instance: the three problems the heuristics take up again.
-
3.5 The protocol, and how to run it
The sequence every problem repeats, from the data to the table of bounds, and how the script is run.