How to set the MIP gap

There is a MIP gap for every mixed-integer problem. The default MIP gap for Gurobi is 1e-4. However, you could do some settings to change this value. It can be any non-negative value.

Warning: Most of the time, a MIP gap of 1e-4 is perfectly fine. Please don’t change it unless you really need to.

All you need to do is to add one line after you creat the Gurobi model. Let’s say you name the model as MyModel using GRBModel MyModel = GRBModel(env);, and you would like the new MIP gap to be 0.01, then you just need to add the following line after you create the Gurobi model:

MyModel.set(GRB_DoubleParam_MIPGap, 0.01);

There are also other parameters that you could set in Gurobi: https://www.gurobi.com/documentation/9.0/refman/parameters.html

The variable type of the parameter MIPgap is double. There are also other types of parameters, like int and string. Here is the guidance for setting other types of parameters: https://www.gurobi.com/documentation/9.0/refman/cpp_model_set.html#cppmethod:GRBModel::set

Some additional examples on parameter setting and querying: https://www.gurobi.com/documentation/9.0/refman/cpp_parameter_examples.html#C++ParameterExamples

Thank you Dr. Sang. It was a big help. I was simulating a DSSC problem on a large test bed system containing 2000 buses. Initially, it took me more than 10 hours to simulate with the default MIP gap of Gurobi; i.e. 1e-4. Setting up the MIP gap into 1e-2 significantly reduces the overall solution time, which is now less than 45 minutes. Nevertheless, the objective value varied insignificantly.

1 Like