this repo has no description
1% RUNS ON mzn20_fd
2% RUNS ON mzn-fzn_fd
3% RUNS ON mzn20_mip
4% perfsq.mzn
5% vim: ft=zinc ts=4 sw=4 et
6% Ralph Becket
7% Thu May 31 11:44:33 EST 2007
8%
9% Perfect squares: find a set of integers the sum of whose squares is
10% itself a square.
11
12int: z = 10;
13
14array [0..z] of 0..z*z: sq = array1d(0..z, [x*x | x in 0..z]);
15
16array [0..z] of var 0..z: s; % Decreasing indices into sq.
17
18var 0..z: k; % We are summing to sq[k];
19
20var 1..z: j; % We want this many sub-squares.
21
22
23
24 % Symmetry breaking: s is an array of indices into sq. The indices are
25 % strictly decreasing until they reach zero, whereupon the remainder are
26 % also zero.
27 %
28constraint forall ( i in 1..z ) ( s[i] > 0 -> s[i - 1] > s[i] );
29
30 % sq[k], sq[k + 1], ... can't appear in the solution.
31 %
32constraint s[0] < k;
33
34 % We want the sum of the squares to be square.
35 %
36constraint sum ( i in 0..z ) ( sq[s[i]] ) = sq[k];
37
38 % We want the longest such sequence.
39 %
40constraint s[j] > 0;
41
42solve maximize j;
43
44output [
45 "perfsq\n",
46 show(k), "^2 = ",
47 show(s[0]), "^2 + ",
48 show(s[1]), "^2 + ",
49 show(s[2]), "^2 + ",
50 show(s[3]), "^2 + ",
51 show(s[4]), "^2 + ",
52 show(s[5]), "^2 + ",
53 show(s[6]), "^2 + ",
54 show(s[7]), "^2 + ",
55 show(s[8]), "^2 + ",
56 show(s[9]), "^2 + ",
57 show(s[10]), "^2\n",
58];