I'm using this code and want to add a constraint such that say item a and b are not assigned in the same bag
Asked
Active
Viewed 117 times
0
-
https://github.com/mbasilyan/binpacking/blob/master/binpacker.py?lipi=urn%3Ali%3Apage%3Ad_flagship3_pulse_read%3BVqIyMFQWR9epdBxSRfrU%2BA%3D%3D – Ankita Samariya Feb 24 '18 at 20:28
1 Answers
3
Let
x(i,j) = 1 if item i is placed in bin j
0 otherwise
Then
x(a,j) + x(b,j) <= 1 for all j
will prevent a and b to be placed in the same bin.

Erwin Kalvelagen
- 15,677
- 2
- 14
- 39
-
prob += lpSum([x["bread", i] + x["squash", i] for i in range(maxBins)]) < 1, ("Item Constraints -- " + str(j[0])) This is what i added. Doesn't work – Ankita Samariya Feb 24 '18 at 21:13
-
Indeed. That is something very different than what I suggested, So it should not work. – Erwin Kalvelagen Feb 24 '18 at 21:39
-
prob += lpSum([x["bread", i] + x["squash", i] for i in range(maxBins)]) <=1, ("Item Constraints -- " + str(j[0])) I did apply a "<=" as you suggested just accidentally posted wrong Is there any thing else that I should change? – Ankita Samariya Feb 24 '18 at 21:54