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]);