Gurobi: Starting from a solution for Mixed Integer Programming Problem by Using Interactive Shell

14 06 2012

As you may know, Gurobi is a powerful solver for MIP formulations. In this post, I will briefly explain how to start simplex algorithm by using an initial solution.

Gurobi can read and write files in “.mst” format for loading/saving solutions. Suppose, you have a formulation and know a good solution for starting. In order to load the solution, you need to write your own .mst file. MST format is easy to handle; click here for reference. You need to start with hash sign (#) and list variable names and their values by placing a space between. Then you can use the following code in interactive shell:

gurobi> m=read(“yourmodelname.lp”)
gurobi> m.optimize()

Simple, isn’t it? You will see that your solution will be loaded as initial solution.

Now, suppose you have two formulations where only objective functions are different. Then, you can record solution of the first one in mst format. Here:

gurobi> m=read(“yourfirstmodel.lp”)
gurobi> m.optimize()
… stuff stuff
gurobi> m.write(“mymstfile.mst”)
gurobi> n=read(“yoursecondmodel.lp”)
gurobi> n.optimize()

Well you can interrupt first model at any time by pressing Ctrl+C and can apply the same procedure.

Hope it helps, you can ask your questions.