this repo has no description
1int: n;
2set of int: NUM = 1..n;
3
4array[NUM] of var NUM: x;
5array[NUM] of var NUM: y;
6array[NUM,NUM] of var 0..2*n-2: dist =
7 array2d(NUM,NUM,[
8 if i < j then manhattan(x[i],y[i],x[j],y[j]) else 0 endif
9 | i,j in NUM ]);
10
11% manf
12function var int: manhattan(var int: x1, var int: y1,
13 var int: x2, var int: y2) =
14 abs(x1 - x2) + abs(y1 - y2);
15
16constraint forall(i,j in NUM where i < j)
17 (dist[i,j] >= max(i,j)-1);
18
19var int: obj = sum(i,j in NUM where i < j)(dist[i,j]);
20solve minimize obj;
21
22% simply to display result
23include "alldifferent_except_0.mzn";
24array[NUM,NUM] of var 0..n: grid;
25constraint forall(i in NUM)(grid[x[i],y[i]] = i);
26constraint alldifferent_except_0([grid[i,j] | i,j in NUM]);
27
28output ["obj = \(obj);\n"] ++
29 [ if fix(grid[i,j]) > 0 then show(grid[i,j]) else "." endif
30 ++ if j = n then "\n" else "" endif
31 | i,j in NUM ];