Adding Quadratic Constraint python
回答済みPij = Is a matrix that includes processing times, for order(j) in truck(i). (integer matrix)
Sik =Is a decision variable that represents the starting time of an order in a truck(i) in truck's slot(k). (cont)
Cj = Decision variable represents the completion time of order(j). (cont or int)
Xijk= Is a binary decision variable (1 if order j assigned to truck i at kth slot)
As can be seen from the above constraint, we need to multiply the Xijk binary decision variable and the continuous decision variable (Sik) and assign it to Cj.
We are having a problem with adding constraint that has quadratic multiplication expression (binary*cont) , (in a summation).
-
It looks like a parentheses issue. Could you try
model.addConstrs((gurobipy.quicksum(Xijk[truck,order,position] * Sik[truck,position]) == Cj[order] for order in orders), name='Completion Time of Order3')
0 -
Thank you for the response! Jaromił Najman
As we got in our previous attempts, now we get a "Quad Exp. object is not iterable" error.0 -
You are currently using 2 \(\texttt{for}\)-loops to generate the sums. However, the quicksum function does this for you already. The following code should work
model.addConstrs((gurobipy.quicksum(Xijk[truck,order,position] * Sik[truck,position] for truck in trucks for position in positions) == Cj[order] for order in orders), name='Completion Time of Order3)
The reason for the error is because the quicksum function requires iterable data as input argument, e.g., a list. However, the object \(\texttt{Xijk * Sik}\) is a QuadExpr. You could have used the 2 \(\texttt{for}\)-loops to construct the sums, but this would make the code more clumsy and harder to read. Thus, using the quicksum function is recommended here.
Best regards,
Jaromił1 -
Hi again,
Now it work smoothly, thank you for the detailed explanation!
Regards,
Umur.0
サインインしてコメントを残してください。
コメント
4件のコメント