# Setting up Branching Priority for GUROBI in Pyomo

I am currently experimenting with GUROBI and would appreciate some kind advice on the following:

In Pyomo: Setting variable branching priorities, there was a response to doing so for CPLEX, hence I would like to ask if anyone has managed to do so for GUROBI too.

In addition to @Richard's answer, you can simply change any of Gurobi's attributes from your Pyomo code as follow:

msolver = SolverFactory('gurobi')
msolver.options['TimeLimit'] = 100
msolver.options['BranchPriority'] = 0


You can set the BranchPriority to whatever value you decided.

You can control the branching priorities in Gurobi using the BranchPriority attribute, which you can then store in an .ord file.

This file can then be provided as an input using the InputFile parameter.

If you cannot add a parameter through the pyomo API, you can always create a gurobi.env file in the directory where your script is located and store all your parameter modifications there.

Edit:

The InputFile parameter cannot be added as a parameter in the gurobi.env. Instead, you should follow @Oguz's approach:

msolver.options['InputFile'] = '<path-to-ord-file>'

• Hi, thank you for replying. Could you help me by providing an example of the code on the file and the associated workflow for invoking it as it seems to be a protracted process? Thank you!
– Mike
May 17 at 10:32
• Hi, it seems that InputFile is only meant for use in command-line, I tried using it in the gurobi.env and an error message was returned stating that it was unrecognized.
– Mike
May 19 at 10:48
• Also, I have look up the bin directory of the latest version, it does not contain the sample gurobi.env file
– Mike
May 19 at 10:56
• He, that's interesting: there are some parameters which you can only set on the model level, not on the environment level, and this is one of them. Your best bet at this point is probably what Oguz wrote:  msolver.options['InputFile'] = '<path-to-file>'  Sorry for the confusion, I should have known better (I work for Gurobi) May 20 at 12:57
• Unfortunately, those are only meant for Cplex, I have tried them to no avail.
– Mike
May 20 at 16:17