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
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
readmethod from the Gurobi shell in your custom function. The name of your customization file must end with a
.pysuffix. 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
<installdir>/examples/pythonfor an example). If you wish to make site-wide customizations, you can also customize the
gurobi.pyfile that is included in