Change parameters

Examples: callback, fixanddive, lp, 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 VarBranch parameter, running for ten seconds per value (VarBranch controls the variable selection strategy in the MIP branch-and-cut tree). 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 VarBranch parameter in C, do the following:

  GRBsetintparam(GRBgetenv(model), GRB_INT_PAR_VARBRANCH, i);
In C++:
  model.getEnv().set(GRB_IntParam_VarBranch, i);
In Java:
  model.getEnv().set(GRB.IntParam.VarBranch, i);
In Python:
  model.Params.VarBranch = i

Note how parameter settings affect the behavior of the 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. The copy gets its own environment that is a copy of the original. When we set the VarBranch parameter on the copy, that parameter change has no effect on the other copies, nor on the original model.