Inefficient solving of QIP
Awaiting user inputDear Gurobi community,
i have an issue regarding the solving of the following QIP. The solution is taking very long time, presumably because of an inefficient way of coding. The main challenge was the modelling of the objective and the variables since the variable set delta has three dimensions B,P and M where the length of M is also dependent on p in P. Delta is a binary variable. Because there are also constraints regarding different p as shown in the example, I can't split up the sum in the objective. That's why i thought it would be necessary to build the sum as shown at the bottom. I also worked with different settings for Parameters of Threads and Heuristics. Do you have any idea, how i could improve my code (in terms of efficiency, i know it has bad visual structure as well)?
#Add variables delta_{b,p,m} for every p in P
archetypes_category_0 = model2.addVars(range(0,len(attributes[0][1])), B, name="archetypes_category", vtype=GRB.BINARY)
archetypes_category_1 = model2.addVars(range(0,len(attributes[1][1])), B, name="archetypes_category1", vtype=GRB.BINARY)
archetypes_category_2 = model2.addVars(range(0,len(attributes[2][1])), B, name="archetypes_category2", vtype=GRB.BINARY)
archetypes_category_3 = model2.addVars(range(0,len(attributes[3][1])), B, name="archetypes_category3", vtype=GRB.BINARY)
archetypes_category_4 = model2.addVars(range(0,len(attributes[4][1])), B, name="archetypes_category4", vtype=GRB.BINARY)
archetypes_category_5 = model2.addVars(range(0,len(attributes[5][1])), B, name="archetypes_category5", vtype=GRB.BINARY)
#objective_function
obj = quicksum((weight_att[0] * quicksum(((attributes[0][n][m]/wohnungsfehler[0][n]) - quicksum(
archetype_node[n][b] * archetypes_category_0[m,b]
for b in B
))**2
for m in range(0,len(attributes[0][1]))
)) + (weight_att[1] * quicksum(((attributes[1][n][m]/wohnungsfehler[1][n]) - quicksum(
archetype_node[n][b] * archetypes_category_1[m,b]
for b in B
))**2
for m in range(0,len(attributes[1][1]))
)) + (weight_att[2] * quicksum(((attributes[2][n][m]/wohnungsfehler[2][n]) - quicksum(
archetype_node[n][b] * archetypes_category_2[m,b]
for b in B
))**2
for m in range(0,len(attributes[2][1]))
)) + (weight_att[3] * quicksum(((attributes[3][n][m]/wohnungsfehler[3][n]) - quicksum(
archetype_node[n][b] * archetypes_category_3[m,b]
for b in B
))**2
for m in range(0,len(attributes[3][1]))
)) + (weight_att[4] * quicksum(((attributes[4][n][m]/wohnungsfehler[4][n]) - quicksum(
archetype_node[n][b] * archetypes_category_4[m,b]
for b in B
))**2
for m in range(0,len(attributes[4][1]))
)) + (weight_att[5] * quicksum(((attributes[5][n][m]/wohnungsfehler[5][n]) - quicksum(
archetype_node[n][b] * archetypes_category_5[m,b]
for b in B
))**2
for m in range(0,len(attributes[5][1]))
))
for n in N)
-
Hi Marius,
Your code snippet is not reproducible, because multiple definitions of used lists and values are missing, cf. minimal reproducible example. Could you please update your post to make the code executable?
If all \(w_P\) values are positive, you might want to try introducing auxiliary continuous variables and equality constraints
\[\begin{align*}
x_{n,p,m} = d_{n,m,p} - \sum_{b\in B}\hat{\beta}_{n,m} \delta_{n,m,p}
\end{align*}\]and use \(x_{n,p,m}^2\) in the objective. This would lead to a convex quadratic problem with binary variables. It is not said that his solves faster but it might be worth a try.
Best regards,
Jaromił0
Please sign in to leave a comment.
Comments
1 comment