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

69 lines
1.7 KiB
MiniZinc

/***
!Test
expected:
- !Result
solution: !Solution
end: 11
objective: 11
s:
- [0, 2]
- [2, 7]
- !Result
solution: !Solution
end: 11
objective: 11
s:
- [0, 2]
- [3, 7]
- !Result
solution: !Solution
end: 11
objective: 11
s:
- [0, 2]
- [4, 7]
***/
%-----------------------------------------------------------------------------%
% Example from the MiniZinc paper:
% (square) job shop scheduling in MiniZinc
%-----------------------------------------------------------------------------%
%-----------------------------------------------------------------------------%
% Instance
size = 2;
d = [| 2,5
| 3,4 |];
%-----------------------------------------------------------------------------%
% Model
int: size; % size of problem
array [1..size,1..size] of int: d; % task durations
int: Total = sum(i,j in 1..size) (d[i,j]); % total duration
array [1..size,1..size] of var 0..Total: s; % start times
var 0..Total: end; % total end time
predicate no_overlap(var int:s1, int:d1, var int:s2, int:d2) =
s1 + d1 <= s2 \/ s2 + d2 <= s1;
constraint
forall(i in 1..size) (
forall(j in 1..size-1) (s[i,j] + d[i,j] <= s[i,j+1]) /\
s[i,size] + d[i,size] <= end /\
forall(j,k in 1..size where j < k) (
no_overlap(s[j,i], d[j,i], s[k,i], d[k,i])
)
);
solve minimize end;
output [
"jobshop2x2\n",
"s[1..2, 1..2] = [", show(s[1, 1]), " ", show(s[1, 2]), "\n",
" ", show(s[2, 1]), " ", show(s[2, 2]), "]\n"
];
%-----------------------------------------------------------------------------%