Skip to content

3. From the model to Python/Gurobi

Class: implementation · Script: python/cap06_gurobi.py

Open in Colab

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.

    The section

  • 3.2 Reading the results


    Status, SolCount, ObjVal, ObjBound, MIPGap, NodeCount, and the three cases where ObjVal cannot be read.

    The section

  • 3.3 Tolerances and relaxations


    "Integer" within IntFeasTol, and relax() to obtain the relaxation of the model just written.

    The section

  • 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.

    The section

  • 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.

    The section