this repo has no description
at develop 950 B view raw
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 11function var int: manhattan(var int: x1, var int: y1, 12 var int: x2, var int: y2) = 13 abs(x1 - x2) + abs(y1 - y2); 14 15constraint forall(i,j in NUM where i < j) 16 (dist[i,j] >= max(i,j)-1); 17 18var int: obj = sum(i,j in NUM where i < j)(dist[i,j]); 19solve minimize obj; 20 21% Simplemente para mostrar el resultado. 22include "alldifferent_except_0.mzn"; 23array[NUM,NUM] of var 0..n: grid; 24constraint forall(i in NUM)(grid[x[i],y[i]] = i); 25constraint alldifferent_except_0([grid[i,j] | i,j in NUM]); 26 27output ["obj = \(obj);\n"] ++ 28 [ if fix(grid[i,j]) > 0 then show(grid[i,j]) else "." endif 29 ++ if j = n then "\n" else "" endif 30 | i,j in NUM ];