1
0
This repository has been archived on 2025-03-06. You can view files and clone it, but cannot push or open issues or pull requests.
Jip J. Dekker fad1b07018 Squashed 'software/minizinc/' content from commit 4f10c8205
git-subtree-dir: software/minizinc
git-subtree-split: 4f10c82056ffcb1041d7ffef29d77a7eef92cf76
2021-06-16 14:06:46 +10:00

41 lines
1.4 KiB
MiniZinc

include "all_different.mzn";
include "disjunctive.mzn";
include "fzn_cumulative.mzn";
include "fzn_cumulative_reif.mzn";
/** @group globals.scheduling
Requires that a set of tasks given by start times \a s, durations \a d, and
resource requirements \a r, never require more than a global resource bound
\a b at any one time.
Assumptions:
- forall \p i, \a d[\p i] >= 0 and \a r[\p i] >= 0
*/
predicate cumulative(array[int] of var int: s,
array[int] of var int: d,
array[int] of var int: r, var int: b) =
assert(index_set(s) == index_set(d) /\ index_set(s) == index_set(r),
"cumulative: the 3 array arguments must have identical index sets",
if length(s) >= 1 then
assert(lb_array(d) >= 0 /\ lb_array(r) >= 0,
"cumulative: durations and resource usages must be non-negative",
if
%% the previous test will not work for resources usages like [2,3,3,4,4] with a bound of 4 since the 2 appears exactly once
let { int: mr = lb_array(r);
int: mri = arg_min([ lb(r[i]) | i in index_set(r) ]) } in
forall(i in index_set(r))
(is_fixed(r[i]) /\ (fix(r[i]) + mr > ub(b) \/ i = mri))
then
if forall(i in index_set(d))(is_fixed(d[i]) /\ fix(d[i]) == 1)
then
all_different(s)
else
disjunctive(s, d)
endif
else
fzn_cumulative(s, d, r, b)
endif
)
endif);