Something went wrong. Try again.
This repository has no description
Something went wrong. Try again.
2.0 kB · 85 lines
at develop
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586% 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%%-----------------------------------------------------------------------------%-----------------------------------------------------------------------------% Specificationint: 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];%-----------------------------------------------------------------------------% Modelarray[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 breakingconstraint forall (i in 1..n-1) ( if pack_s[i]=pack_s[i+1] then x[i] <= x[i+1] else true endif );% Capacity constraintsconstraint 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];