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.

19 lines
585 B
MiniZinc

include "alldifferent_except_0.mzn";
int: n; % size
array[1..n,0..n] of int: p; % prize for edge (i,j), p[i,0] = 0
array[1..n] of var 0..n: next; % next posn in tour
array[1..n] of var 0..n: pos; % posn on node i in path, 0=not in
array[1..n] of var int: prize = [p[i,next[i]] | i in 1..n];
% prize for outgoing edge
constraint forall(i in 1..n)(
(pos[i] = 0 <-> next[i] = 0) /\
(next[i] > 1 -> pos[next[i]] = pos[i] + 1)
);
constraint alldifferent_except_0(next) /\ pos[1] = 1;
solve minimize sum(i in 1..n)(prize[i]);