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.
on-restart-benchmarks/share/minizinc/std/fzn_sliding_sum.mzn
Jip J. Dekker f2a1c4e389 Squashed 'software/mza/' content from commit f970a59b17
git-subtree-dir: software/mza
git-subtree-split: f970a59b177c13ca3dd8aaef8cc6681d83b7e813
2021-07-11 16:34:30 +10:00

16 lines
769 B
MiniZinc
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

predicate fzn_sliding_sum(int: low, int: up, int: seq, array[int] of var int: vs) =
/* CS decomposition: see S. Brand, N. Narodytska, C-G. Quimper, P.J. Stuckey, and T. Walsh. Encodings of the sequence constraint. In C. Bessiere, editor, Proceedings of the 13th International Conference on Principles and Practice of Constraint Programming, volume 4741 of LNCS, pages 210224. Springer-Verlag, 2007.
*/
let { int: lx = min(index_set(vs));
int: ux = max(index_set(vs));
array[lx-1..ux] of var int: S;
} in
S[lx-1] = 0 /\
forall (i in lx .. ux) (
S[i] = vs[i] + S[i-1]
) /\
forall (i in lx-1 .. ux - seq) (
S[i] <= S[i+seq] - low /\
S[i+seq] <= S[i] + up
);