Reduced Cost Attributes
Hello,
I have a restricted master problem that runs just fine. But I'm not able to access the reduced cost or the shadow price attributes for the problem. All of the variables are continuous. I tried accessing the reduced cost by individual variable too (ex. r[0,1] ) but that does not work either. Any suggestions? Also, is there a method yet to access the reduced cost for integer variables? Thank you in advance!
m = Model("Master Problem")
m.Params.OutputFlag=1
m.read("m_param.prm")
m.update()
r = {}
s = {}
z = {}
r = m.addVars(airports,uc,lb=0,ub=1,vtype=GRB.CONTINUOUS,name='r')
s = m.addVars(secmea,airports,uc,lb=0,vtype=GRB.CONTINUOUS,name='s')
z = m.addVars(secmea,airports,uc,lb=0,vtype=GRB.CONTINUOUS,name='z')
objn1 = quicksum(r[k,j]*Rx[int(uniquecombon[j])] for k in range(airports) for j in range(uc))
objn2 = -1*quicksum(
(1-SA[SAP,1])*fr[0]*r[k,j]*qnew1[int(uniquecombon[j])] + (1-SA[SAP,2])*fr[1]*r[k,j]*qnew2[int(uniquecombon[j])]
for k in range(airports) for j in range(uc))
objn3 = quicksum(SL[k,int(uniquecombon[j])]*z[d,k,j] for d in range(secmea) for k in range(airports) for j in range(uc))
m.setObjectiveN(objn1,index=0,priority=0,weight=1)
m.setObjectiveN(objn2,index=1,priority=0,weight=1)
m.setObjectiveN(objn3,index=2,priority=0,weight=1)
c0 = {}
c1 = {}
c2 = {}
c3 = {}
c4 = {}
c5 = {}
for d in range(secmea):
c0[d] = m.addConstr(quicksum(z[d,k,j] for k in range(airports) for j in range(0,uc)) >= E[d],"Existing_Avail_"+str(d))
c1[d] = m.addConstr(quicksum(z[d,k,j] for k in range(airports) for j in range(0,uc)) <= U[d],"Resource_Avail_"+str(d))
for k in range(airports):
c2[k] = m.addConstr(quicksum(r[k,j] for j in range(uc)) == 1, 'Airport_'+str(k))
for d in range(secmea):
c3[d,k] = m.addConstr(quicksum(z[d,k,j] for j in range(uc)) <= quicksum(K[d,k] for j in range(uc)),"linearity1_"+str(d)+str(k))
c4[d,k] = m.addConstr(quicksum(s[d,k,j] - (1-r[k,j])*K[d,k] for j in range(uc)) <= quicksum(z[d,k,j] for j in range(uc)),"linearity2_"+str(d)+str(k))
c5[d,k] = m.addConstr(quicksum(z[d,k,j] for j in range(uc)) <= quicksum(s[d,k,j] for j in range(uc)),"linearity3_"+str(d)+str(k))
m.update
m.optimize()
shadow_price = m.getAttr(GRB.Attr.Pi)
print("Master Complete")
mval = m.ObjVal
r.RC
s.RC
z.RC
Thanks,
Taylor
-
Official comment
This post is more than three years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum. Or why not try our AI Gurobot?. -
Concerning your question about integer variables: There are no (trivial) duals / reduced costs in MIPs. What you might want to do is to fix the integer solution and solve the remaining LP.
Concerning your other (continous) question: The code seems incomplete, so I cannot test it. What do you mean by "does not work"? Do you get an exception? Do you get zeros (which might be perfectly ok)? For a very simple LP I just tested, the code
print m.getAttr(GRB.Attr.RC)
print m.getAttr(GRB.Attr.Pi)works.
0 -
Hi Thomas, thanks for the reply. The error I get when optimizing a standard linear program with continuous variables is
AttributeError: 'tupledict' object has no attribute 'RC'
I understand that zeros are fine, but I did not expect to receive no attribute because I know that the solution is not the optimal one.
Thank you,
Taylor
0 -
Ah, I see.
You are calling:
r.RC
s.RC
z.RCI guess, this should be something like:
r.getAttr(GRB.Attr.RC)
s.getAttr(GRB.Attr.RC)
z.getAttr(GRB.Attr.RC)0
Post is closed for comments.
Comments
4 comments