skimono

Week_4_Task_4

Mar 9th, 2026
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. int: n = 30;
  2. int: bin_capacity = 12;
  3. array[1..n] of int: size =
  4. [6, 6, 6, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4,
  5. 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2];
  6.  
  7. int: total_size = sum(i in 1..n)(size[i]);
  8. int: lb = ceil(total_size / bin_capacity);
  9. int: ub = n;
  10.  
  11. array[1..n] of var lb..ub: bin_of;
  12.  
  13. array[lb..ub] of var 0..bin_capacity: load;
  14. constraint
  15. forall(b in lb..ub) (
  16. load[b] = sum(i in 1..n where bin_of[i] == b)(size[i])
  17. );
  18.  
  19. constraint
  20. forall(b in lb..ub) (
  21. load[b] <= bin_capacity
  22. );
  23.  
  24. constraint
  25. bin_of[1] == lb;
  26. constraint
  27. forall(i in 2..n)(
  28. bin_of[i] <= max([bin_of[j] | j in 1..i-1]) + 1
  29. );
  30.  
  31. constraint
  32. forall(s in {6,5,4,3,2})(
  33. let { array[int] of int: indices = [i | i in 1..n where size[i] == s] } in
  34. forall(k in 1..length(indices)-1)(
  35. bin_of[indices[k]] <= bin_of[indices[k+1]]
  36. )
  37. );
  38.  
  39. var lb..ub: ans;
  40. constraint
  41. ans = max(bin_of);
  42. solve minimize ans;
  43.  
  44. /*
  45. 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];
  46. 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];
  47. obj = 19;
  48. _objective = 19;
  49. */
Advertisement
Add Comment
Please, Sign In to add comment