Interface customization

The Gurobi interactive shell lives within a full featured scripting language. This allows you to perform a wide range of customizations to suit your particular needs. Creating custom functions requires some knowledge of the Python language, but you can achieve a lot by using a very limited set of language features.

Let us consider a simple example. Imagine that you store your models in a certain directory on your disk. Rather than having to type the full path whenever you read a model, you can create your own custom read method:

gurobi> def myread(filename):
.......   return read('/home/john/models/'+filename)
Note that the indentation of the second line is required.

Defining this function allows you to do the following:

gurobi> m = myread('stein9')
Read MPS format model from file /home/john/models/stein9.mps

If you don't want to type this function in each time you start the Gurobi shell, you can store it in a file. The file would look like the following:

from gurobipy import *

def myread(filename):
  return read('/home/john/models/'+filename)
The from gurobipy import * line is required in order to allow you to use the read method from the Gurobi shell in your custom function. The name of your customization file must end with a .py suffix. If the file is named custom.py, you would then type:
gurobi> from custom import *
in order to import this function. One file can contain as many custom functions as you'd like (see custom.py in <installdir>/examples/python for an example). If you wish to make site-wide customizations, you can also customize the gurobi.py file that is included in <installdir>/lib.

Try Gurobi for Free

Choose the evaluation license that fits you best, and start working with our Expert Team for technical guidance and support.

Evaluation License
Get a free, full-featured license of the Gurobi Optimizer to experience the performance, support, benchmarking and tuning services we provide as part of our product offering.
Academic License
Gurobi supports the teaching and use of optimization within academic institutions. We offer free, full-featured copies of Gurobi for use in class, and for research.
Cloud Trial

Request free trial hours, so you can see how quickly and easily a model can be solved on the cloud.

Search