Hello all,
I've been trying to learn Oz constraint programming. After some simple
examples I tried my hand at something "harder". However, I can't seem to
find a way to post a constraint that makes reference to a tuple. The
constraint problem to be solved is given a list of matches with each end of
the match having a colour, align the matches in a line such that all
adjacent ends have the same colour.

I tried also creating a local variable and using reified constraints. That
didn't work either as I think I'm a little over my head and mixing "=:" with
"==".

Any ideas on how to get this type of constraint working? Or how to
reformulate the problem?

Michal

============ file: Example.oz ====================

% The constraint to be posted is at the FIXME

functor

import
   FD
   Browser
   Search

define
   % Our matches, where each match has different coloured ends.
   % Different colours represented by different numbers.
   % Note that the matches are given in an order that provides a solution:
   %    0---1 1---0 0---2 2---2 2---0
   %
   % This is equavalent to the solution (see code):
   %    solution(flip:flip(0 0 0 0 0) pos:pos(1 2 3 4 5))
   %
   % Another solution might be:
   %    1---0 0---2 2---2 2---0 0---1
   %
   % This is equavalent to the solution (see code):
   %    solution(flip:flip(1 1 0 0 0) pos:pos(1 5 2 3 4))
   %
   NUM = 5
   M = matches(
           match(0 1)
           match(1 0)
           match(0 2)
           match(2 2)
           match(2 0)
       )

   % Our solver
   proc {Solve Root}
       % Which numbered match is in each position of the line.
       Pos = {MakeTuple pos NUM}

       % Whether we rotated the match or not
       Flip = {MakeTuple flip NUM}
   in
       % Post the solution
       Root = solution(pos:Pos flip:Flip)

       % Initialize the variable domains.
       Pos = {FD.tuple pos NUM 1#NUM}
       Flip = {FD.tuple flip NUM 0#1}


   /*    FIXME

       {For 1 NUM-1 1 proc {$ I}

           % The trailing edge of a placed match is the same the leading
edge
           % of the next match.
           M.(Pos.I).(2 - Flip.I) =: M.(Pos.(I+1)).(1 + Flip.(I+1))

       end}

   */


       % We can only place each match once.
       {FD.distinct Pos}

       {FD.distribute ff Pos}
       {FD.distribute ff Flip}
   end

   {Browser.browse {Search.base.one Solve}}
end
_________________________________________________________________________________
mozart-users mailing list                               
[email protected]
http://www.mozart-oz.org/mailman/listinfo/mozart-users

Reply via email to