Please note that starting with version 11.0.2, the Gurobi Interactive Shell has been deprecated.
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 in your current directory. The file would look like the following:
from gurobipy import * def myread(filename): return read("/home/john/models/"+filename)
The from gurobipy import * line allows 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 the following to import this function:
gurobi> from custom import *
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.
Comments
0 comments
Article is closed for comments.