4
$\begingroup$

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.

$\endgroup$
3
$\begingroup$

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.

$\endgroup$
2
3
$\begingroup$

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>'
$\endgroup$
16
  • $\begingroup$ 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! $\endgroup$
    – Mike
    May 17 at 10:32
  • $\begingroup$ 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. $\endgroup$
    – Mike
    May 19 at 10:48
  • $\begingroup$ Also, I have look up the bin directory of the latest version, it does not contain the sample gurobi.env file $\endgroup$
    – Mike
    May 19 at 10:56
  • $\begingroup$ 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) $\endgroup$
    – Richard
    May 20 at 12:57
  • $\begingroup$ Unfortunately, those are only meant for Cplex, I have tried them to no avail. $\endgroup$
    – Mike
    May 20 at 16:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.