Divide by variable technique didn't work.
AnsweredI am trying to divide by decision variable by using the technique from
"How do I divide by a variable in Gurobi?"
Unfortunately it didn't work out well, so I am not sure that where is my mistake.
Noted here: y[j,k] is my decision variable and z[j,k] is an auxiliary variable to define as z[j,k] = 1/y[j,k].
Auxiliary_noise = m.addConstrs((z[j,k]*y[j,k] == 1 for j in Machines for k in Times), name = "Aux_Noise")
#Expo_noise_matrix having only 1 - Times = 1-16
Expo_noise_matrix = {}
Aux_Expo_noise1 = {}
Aux_Expo_noise2 = {}
for k in Times:
Aux_Expo_noise1[k] = (70*y[1,k]+60*y[2,k]+80*y[3,k])*(z[1,k]+z[2,k]+z[3,k])
Aux_Expo_noise2[k] = 0.8+0.2*y[1,k]+0.2*y[2,k]+0.2*y[3,k]
Expo_noise_matrix[k] = (Aux_Expo_noise[k]*Aux_Expo_noise2[k])
Here is the results.
<ipython-input-59-b16dfe9cfed7> in <module> 27 Aux_Expo_noise1[k] = (70*y[1,k]+60*y[2,k]+80*y[3,k])*(0.01+z[1,k]+z[2,k]+z[3,k]) 28 Aux_Expo_noise2[k] = 0.8+0.2*y[1,k]+0.2*y[2,k]+0.2*y[3,k] ---> 29 Expo_noise_matrix[k] = (Aux_Expo_noise[k]*Aux_Expo_noise2[k]) src\gurobipy\quadexpr.pxi in gurobipy.QuadExpr.__mul__() src\gurobipy\quadexpr.pxi in gurobipy.QuadExpr._mul() GurobiError: Invalid argument to QuadExpr multiplication
I am not sure what i did wrong and if you have any recommendations, please let me know,
Best regards,
Thunwa
-
Hi Thunwa,
I am not quite sure about your model.
But you need to use the m.addVars() method to create variables for Aux_Expo_noise1[k] and Aux_Expo_noise2[k] and also for Expo_noise_matrix[k] (if this should not be just 1).Then you need to add a constraint for each line in your for-loop, for example (here I assume matrix[k] needs to be 1):
aux1 = m.addVars(Times, vtype=gp.GRB.CONTINUOUS, name = "aux1")
aux2 = m.addVars(Times, vtype=gp.GRB.CONTINUOUS, name = "aux2")
for k in Times:
m.addConstr(aux1[k] == (70*y[1,k]+60*y[2,k]+80*y[3,k])*(z[1,k]+z[2,k]+z[3,k]))
m.addConstr(aux2[k] == 0.8+0.2*y[1,k]+0.2*y[2,k]+0.2*y[3,k])
m.addConstr(aux1[k] * aux2[k] == 1)I hope this information helps.
Best regards,
Marika0 -
Hi, Marika
This is really informative to my model.
Thank you a lot
Best regards,
Thunwa
0
Please sign in to leave a comment.
Comments
2 comments