How can I set branch priority into a variable?

1,170 views
Skip to first unread message

zuhal kartal

unread,
Aug 24, 2016, 12:11:48 AM8/24/16
to Gurobi Optimization
Hi,

I wanna set the branch priority attribute one of my binary variables.

I tried to use this:
m.getVars()[h].BranchPriority = 9

However, I got this error message:

 

m.getVars()[h].BranchPriority = 9

TypeError: list indices must be integers, not list.


So, if anyone can help me, how can I set branch priority on a variable?


Thank you so much,

Zuhal

Sonja Mars

unread,
Aug 24, 2016, 3:01:08 AM8/24/16
to gur...@googlegroups.com
Hi,

What is "h"? The error message indicates that it is a list. It needs to be an integer, if you want to use it as an index for a list.

Additionally, if you are only interested in one variable, it might me more efficient to use the method getVarByName():
http://www.gurobi.com/documentation/6.5/refman/py_model_getvarbyname.html

Best regards,
Sonja


----
Dr. Sonja Mars
Gurobi Optimization - Technical Support
> --
>
> ---
> You received this message because you are subscribed to the Google Groups "Gurobi Optimization" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to gurobi+un...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

zuhal kartal

unread,
Aug 24, 2016, 5:55:39 AM8/24/16
to Gurobi Optimization
Hi Sonja,

Firstly, thanks for the reply.

"h" is a binary variable. I defined "h" in the formulation:

h = []
for i in N:
h.append(m.addVar(vtype=GRB.BINARY, name="h%s"))

And I want to give branch priority on my "h" variable which can be done in CPLEX like: 
m.setPriorityOrder(h,1,"UP")

Is there any way that I can make the same thing in GUROBI as well?

Regards,
Zuhal

Sonja Mars

unread,
Aug 24, 2016, 6:20:27 AM8/24/16
to gur...@googlegroups.com
Hi Zuhal,

So "h" is a list of Gurobi Variable objects. This cannot be used as index of a list.

There are a few ways to do exactly what you want in Gurobi. I give two examples:

First:

for h_var in h:
h_var.BranchPriority = 9



Second:

m.setAttr("BranchPriority", h, [9]*len(h))

assuming your want to set the Branch Priority to 9 for all h variables. Also see here for more details on setAttr: http://www.gurobi.com/documentation/6.5/refman/py_model_setattr.html

zuhal kartal

unread,
Aug 24, 2016, 8:53:07 AM8/24/16
to Gurobi Optimization
Thanks Sonja,

It is working right now:)

Zuhal.

Reply all
Reply to author
Forward
0 new messages