The answer depends a bit on the details (are the variables integers, are all values in the domain covered). Here is a reference that may be of interest:
Williams, H. Paul and Yan, Hong (2001), Representations of the
'all_different' predicate of constraint satisfaction in integer
programming, Informs Journal on Computing, 13 (2). 96-103.
Let's define the problem more precisely. Say we have n
integers, x[i]
, that take unique values between 1,...,n
. We can implement this as:
We can introduce binary variables
y[i,k] = 1 if x[i]=k
0 otherwise
With this, we can write:
x[i] = sum(k, k*y[i,k]) (1)
sum(k, y[i,k]) = 1 ∀i (2)
sum(i, y[i,k]) = 1 ∀k (3)
y[i,k] ∈ {0,1}
where i ∈ {1,..,n}
and k ∈ {1,..,n}
.
If you have fewer variables than n
, say i ∈ {1,..,m}
with m < n
, then we need to replace (3) by:
sum(i, y[i,k]) ≤ 1 ∀k (3a)