Change parameters

Examples: callback, fixanddive, lp, lpmethod, mip2, params, sensitivity

This section illustrates the use of Gurobi parameters. Example params reads a MIP model from a file, then solves the model using four different values of the MIPFocus parameter, running for five seconds per value (MIPFocus chooses the high-level strategy that the MIP solver uses to solve the problem). It then chooses the parameter value that produced the smallest MIP gap, and continues solving the model until it achieves optimality.

The mechanics of setting a parameter are quite simple. To set the MIPFocus parameter in C, do the following:

  GRBsetintparam(GRBgetenv(model), GRB_INT_PAR_MIPFOCUS, i);
In C++:
  model.set(GRB_IntParam_MIPFocus, i);
In Java:
  model.set(GRB.IntParam.MIPFocus, i);
In C#:
  model.Parameters.MIPFocus = 1
or
  model.Set(GRB.IntParam.MIPFocus, i);
In Python:
  model.Params.MIPFocus = i

We should add a comment on how parameter settings propagate between different models. When we set the TimeLimit parameter on the base model, then make a copy of that model, the parameter setting is carried over to the copy. When we set the MIPFocus parameter on the copy, that parameter change has no effect on the other copies, nor on the original model.

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