Gurobi is designed to be deterministic. You can always get the same results (meaning the same solution values and same algorithmic path) from the same inputs (model and parameters) on the same computer with the same Gurobi version. Gurobi is also deterministic for parallel optimization: you always get the same results with multiple threads. However, if you change any inputs, including small changes like
- parameter values
- rounding of coefficients
- order of variables or constraints
- starting solution
then you may get different results, even if everything else remains the same.
Gurobi may not be deterministic with time-dependent parameters such as
- the TimeLimit parameter, where the wall-clock timing can vary with the current machine workload,
- the NoRelHeurTime parameter for the same reason,
- the Method parameter, which determines which algorithms to run on continuous models or root relaxation. The default choice for the Method parameter (Method=-1) can run non-deterministic concurrent in some cases. To ensure determinism, use Method=0, 1, 2, or 4.
- the ConcurrentMIP parameter. Concurrent MIP is not deterministic. If runtimes for different independent solves are very similar, and if the model has multiple optimal solutions, you may get slightly different results from multiple runs on the same model. By default, Gurobi does not use ConcurrentMIP.
A deterministic substitute for the TimeLimit parameter is the WorkLimit parameter. The respective parameter to control the NoRel heuristic is NoRelHeurWork.
To ensure reproducibility of the results, the script that builds models to solve with Gurobi should also be deterministic. Some data structures, such as sets in Python, are not deterministic and may lead to different orderings of variables and constraints in a model, even when running the same code with the same data. To check if two models are the same, compare their fingerprints.
Changing the Seed parameter will encourage Gurobi to explore a different search path. By default, the seed parameter is a fixed value so does not need to be explicitly fixed to ensure determinism.
Further information
- Is Gurobi random?
- Why does Gurobi perform differently on different machines?
- What is the model fingerprint?
- What is the best seed value to use?