Using gurobi optimize variable
AnsweredIn the below code, A[i,k] is optimize variable (decision). This decision variable will change the value of PN. So i am trying to update the PN for when A[i][k] ==1. For example if M is 5 and P is 15, then it decides the which which k is best A[1][1], A[1][2], A[1][3], A[1][4], A[1][5] such that A[1][1]+A[1][2]+ A[1][3]+A[1][4]+ A[1][5]=1
i am getting the following error (#error line) "TypeError: unsupported operand type(s) for -=: 'NoneType' and 'float' " in the constrs line. Kindly help to figure out mistake.
A_initial=nmp1.array([0,1,2,3,1,2,3,1,2,3,4,5,3,4,5,3,4]) #1 to 16, index 0 is unused
PN= nmp1.array([[0,0,0,0,0,0,0,0,0],[0,1,2,3,4,5,6,7,8],[0,9,10,11,12,13,14,15,16]]) # PN[1], PN[2], PN[0] unused
CR=[0,1,1,1,2,2]
bw=nmp.uniform(1,1000,size=(16,5)) # matrix bw[1][1], bw[1][2]....bw[1][5], bw[2][1],....
for i in range(1,16):
for j in range(1,6):
A[i][j].Start=0
for i in range(1,16):
A[i][A_initial[i]]=1
for i in range(1,16):
m.addConstr(t[i]==(t1[i]+ sum(bw[i,k]*A[i,k] for k in range(1,M+1))),"t") #optimize
for j in range(1,R+1):
for i in range(1,P+1):
PN[j,i]=0
for i in range(1,P+1):
for k in range(1,M+1):
m.addConstr((A[i,k]==1) >> (PN[CR[k],i]==1)) #error line
-
Your example is not reproducible. But I think the issue is that you need to define PN as Gurobi variables as well if you want to change the values.
This is not possible:
A= m.addVar(vtype='B')
B= 3
m.addConstr((A==1) >> (B==2))and will produce the error
TypeError: unsupported operand type(s) for -=: 'NoneType' and 'float'
B needs to be defined as a variable as well
A= m.addVar(vtype='B')
B= m.addVar(vtype='I')
m.addConstr((A==1) >> (B==2))0
Please sign in to leave a comment.
Comments
1 comment