skimono

Week_4_Task_5

Mar 9th, 2026
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. include "globals.mzn";
  2.  
  3. int: num_tasks = 20;
  4. int: num_resources = 3;
  5.  
  6. set of int: TASKS = 1..num_tasks;
  7. set of int: RESOURCES = 1..num_resources;
  8.  
  9. array[TASKS] of int: duration =
  10. [6, 5, 4, 3, 3, 6, 5, 2, 8, 2, 8, 2, 3, 7, 3, 8, 7, 5, 6, 2];
  11. array[TASKS, RESOURCES] of int: demand = [|
  12. 1, 1, 2 | 1, 2, 1 | 2, 0, 2 | 2, 0, 2 | 2, 1, 2 |
  13. 1, 0, 1 | 1, 0, 1 | 0, 2, 2 | 1, 2, 0 | 2, 0, 2 |
  14. 1, 2, 2 | 2, 0, 0 | 1, 0, 2 | 2, 0, 2 | 1, 1, 0 |
  15. 0, 1, 1 | 0, 0, 1 | 1, 0, 2 | 1, 0, 2 | 0, 0, 2 |];
  16. array[RESOURCES] of int: capacity = [4, 4, 4];
  17.  
  18. array[TASKS] of var 0..100: start;
  19.  
  20. array[TASKS] of var int: end = [start[t] + duration[t] | t in TASKS];
  21.  
  22. constraint
  23. forall(r in RESOURCES) (
  24. let { array[TASKS] of int: demand_r = [demand[t,r] | t in TASKS] } in
  25. cumulative(start, duration, demand_r, capacity[r])
  26. );
  27.  
  28. constraint start[5] >= max([end[t] | t in 1..4]);
  29. constraint start[10] >= max([end[t] | t in 6..9]);
  30. constraint start[15] >= max([end[t] | t in 11..14]);
  31. constraint start[20] >= max([end[t] | t in 16..19]);
  32.  
  33. var int: makespan = max([end[t] | t in TASKS]);
  34. solve minimize makespan;
  35.  
  36. output [
  37. "Начало: ", show(start), "\n",
  38. "Конец ", show(end), "\n",
  39. "Итог: ", show(makespan)
  40. ];
Advertisement
Add Comment
Please, Sign In to add comment