Oh, now we get the real story! ;-)

If you really want to model a *set* of integers, then either use finite set constraints (they're done for that), or represent the set as an *ordered* list of integers.


With finite sets, you can match a list of FD vars with the elements of the set as:

S={FS.var.upperBound 1#(2*N)}   % S is a subset of {1,...,2N}
{FS.card S}=N                   % S has N elements
Es={FD.list N 1#(2*N)}   % Es is a list of ints
{FS.int.match S Es}      % Es are the elements of S in ascending order


With finite integers only, just impose a strict ordering:

Es={FD.list N 1#(2*N)}
for X in Es  Y in Es.2 do X<:Y end   % order all elements


The cost can be obtained by reification. Compute a binary integer that is equal to 1 iff two elements are consecutive. Then sum them (with FD.sum of course).

Cost={FD.decl}
Bs = for X in Es  Y in Es.2  collect:Collect do
        {Collect (X+1 =: Y)}   % reify constraint
     end
{FD.sum Bs '=:' Cost}   % the cost is the sum of the B in Bs


I hope this may help you.

Cheers,
raph

mostafa eslahi wrote:
I'm sorry, there was a problem,
let's me describe again:
I have a alldiff{x(1),..,x(n)} constraint that domain of variables is [1,..,2n],
This constraint for example (for n=10) produce sets like this {2,5,8,9,1}
now, In the cost function I want to count consecutive values, I mean cost({2,5,8,9,1})=2 (since 1,2 and 8,9 are 2 consecutive integer).
Now, I hope you get my problem.
Cheers,

_________________________________________________________________________________
mozart-users mailing list                               
[email protected]
http://www.mozart-oz.org/mailman/listinfo/mozart-users

Reply via email to