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 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

86 lines
1.9 KiB
MiniZinc

% RUNS ON mzn20_fd
% RUNS ON mzn-fzn_fd
% TOO LONG mzn20_fd_linear
% TOO LONG mzn20_mip
%-----------------------------------------------------------------------------
% Packing squares into a rectangle
%
% Guido Tack, tack@gecode.org
% 2007-02-22
%
% Ported from the Gecode example
%
%-----------------------------------------------------------------------------
%-----------------------------------------------------------------------------
% Specification
int: pack_x;
int: pack_y;
int: n;
array[1..n] of int: pack_s;
% Instance
%pack_x = 4;
%pack_y = 4;
%n = 4;
%pack_s = [2,2,2,2];
pack_x = 112;
pack_y = 112;
n = 21;
pack_s = [50,42,37,35,33,29,27,25,24,19,18,17,16,15,11,9,8,7,6,4,2];
%-----------------------------------------------------------------------------
% Model
array[1..n] of var 0..pack_x-1: x;
array[1..n] of var 0..pack_y-1: y;
constraint
forall (i in 1..n) (
x[i] <= pack_x - pack_s[i] /\
y[i] <= pack_y - pack_s[i]
)
/\
forall (i in 1..n, j in i+1..n) (
x[j] - x[i] >= pack_s[i] \/
x[i] - x[j] >= pack_s[j] \/
y[j] - y[i] >= pack_s[i] \/
y[i] - y[j] >= pack_s[j]
);
% Symmetry breaking
constraint
forall (i in 1..n-1) (
if pack_s[i]=pack_s[i+1] then
x[i] <= x[i+1]
else
true
endif
);
% Capacity constraints
constraint
forall (cx in 0..pack_x-1) (
sum (i in 1..n) (pack_s[i]*bool2int(x[i] in cx-pack_s[i]+1..cx)) = pack_x
)
/\
forall (cy in 0..pack_y-1) (
sum (i in 1..n) (pack_s[i]*bool2int(y[i] in cy-pack_s[i]+1..cy)) = pack_y
);
solve ::seq_search([int_search(x,smallest,indomain_min,complete),
int_search(y,smallest,indomain_min,complete)])
satisfy;
output [
"packing ",show(n)," squares into a ",show(pack_x),"x",show(pack_y),
" rectangle:\n"] ++
[ "square "++show(i)++
", size "++show(pack_s[i])++"x"++show(pack_s[i])++
", at ("++show(x[i])++", "++show(y[i])++")\n" | i in 1..n];