Modification of RHS of constraints

188 views
Skip to first unread message

Siamak Naderi

unread,
Apr 6, 2017, 4:59:01 AM4/6/17
to Gurobi Optimization
Dear All, 

I am writing a Benders Decomposition type of algorithm where I need to modify some constraints. At the moment I remove and add contrarians with new values which doesn't make sense (It increases the computational time). I found GBRConstr.Set(GRB.DoubleAttr.RHS, newValue)  to update the RHS but it doesn't work for me.  Here is the code. I want to update the RHS of the these two sets of constraints (x_opt is input, which causes this change). 

        psp_constr1 = {}
        psp_constr2 = {}
        for i in stores:
            for o in options:
                for k in sizes:
                     psp_constr1[i,o,k] = psp.addConstr(z[(i,o,k)] <= sum(supply[(j,o,k)]*x_opt[(j,i,o)] for j in stores) )
                    
        for i in stores:
            for j in stores:
                for o in options:
                    if i!=j:
                       psp_constr2[i,j,o] = psp.addConstr(y[(i,j)] >= x_opt[(i,j,o)] ) 

Any help is appreciated, 
SNV

Daniel Espinoza

unread,
Apr 6, 2017, 6:17:49 PM4/6/17
to Gurobi Optimization
SNV,

What do you mean it did not work? did you write the LP before/after the changes? Maybe you missed an update call?

Best
Daniel

Siamak Naderi

unread,
Apr 7, 2017, 5:16:17 AM4/7/17
to Gurobi Optimization
Dear Daniel, 

When I add "psp_constr1[0,0,0].Set(GRB.DoubleAttr.RHS, 200)" right after the constraints (as above), I receive this error: AttributeError: 'gurobipy.Constr' object has no attribute 'Set' . 
Appreciate if you could help me, 
SNV

Siamak Naderi

unread,
Apr 7, 2017, 11:36:33 AM4/7/17
to Gurobi Optimization
I made it using "model.setAttr("RHS", m.getConstrs(), newvalue)". 

Thanks anyways, 

Greg DeYong

unread,
Sep 19, 2017, 12:31:23 AM9/19/17
to Gurobi Optimization
How did you get this to work? I get an error message "gurobipy.Model object has no attribute 'setAttr'". I also get the same original error you noted before "gurobipy.Constr object has no attribute 'Set' if I try to use the approach you attempted first.

Tobias Achterberg

unread,
Sep 19, 2017, 5:47:06 AM9/19/17
to gur...@googlegroups.com
Which Gurobi version are you using? The Python API was extended quite a bit in versions
7.0 and 7.5.

Regards,

Tobias
Reply all
Reply to author
Forward
0 new messages