Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int: n = 30;
- int: bin_capacity = 12;
- array[1..n] of int: size =
- [6, 6, 6, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4,
- 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2];
- int: total_size = sum(i in 1..n)(size[i]);
- int: lb = ceil(total_size / bin_capacity);
- int: ub = n;
- array[1..n] of var lb..ub: bin_of;
- array[lb..ub] of var 0..bin_capacity: load;
- constraint
- forall(b in lb..ub) (
- load[b] = sum(i in 1..n where bin_of[i] == b)(size[i])
- );
- constraint
- forall(b in lb..ub) (
- load[b] <= bin_capacity
- );
- constraint
- bin_of[1] == lb;
- constraint
- forall(i in 2..n)(
- bin_of[i] <= max([bin_of[j] | j in 1..i-1]) + 1
- );
- constraint
- forall(s in {6,5,4,3,2})(
- let { array[int] of int: indices = [i | i in 1..n where size[i] == s] } in
- forall(k in 1..length(indices)-1)(
- bin_of[indices[k]] <= bin_of[indices[k+1]]
- )
- );
- var lb..ub: ans;
- constraint
- ans = max(bin_of);
- solve minimize ans;
- /*
- bin_of = [10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 14, 15, 15, 15, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 12, 13, 16, 18, 19, 19];
- load = [10: 12, 11: 11, 12: 12, 13: 12, 14: 12, 15: 12, 16: 12, 17: 12, 18: 11, 19: 4, 20: 0, 21: 0, 22: 0, 23: 0, 24: 0, 25: 0, 26: 0, 27: 0, 28: 0, 29: 0, 30: 0];
- obj = 19;
- _objective = 19;
- */
Advertisement
Add Comment
Please, Sign In to add comment