Oz and Mozart Users Mailing List

Re: [Newbie] Blocking statement in constraint programming


From: Raphael Collet (raph@info.ucl.ac.be)
Date: Tue Apr 15 2003 - 11:17:37 CEST


Thomas LUDWIG wrote:
>
> I have to make a program that helps in music composition, so I chose
> Mozart for its constraint programming aspect.

Good choice, IMO. Music composition has already been done with Oz a few
years ago.

> To start, I have this trivial proc:
> declare Contre
> proc {Contre S C}
> {FD.tuple compose 15 48#72 C}
> {Browse S}
> % pas d'intervale superieur a la quinte:
> { For 2 15 1 proc {$ I} (C.I) <: (C.(I-1)) + 7 end}
> { For 2 15 1 proc {$ I} (C.I) >: (C.(I-1)) - 7 end}
> % pas d'intervale inferieure au ton:
> { For 2 15 1 proc {$ I} (C.I) \=: (C.(I-1)) + 1 end}
> { For 2 15 1 proc {$ I} C.I \=: C.(I-1) end}
> { For 2 15 1 proc {$ I} (C.I) \=: (C.(I-1)) - 1 end}
> % regle bidon 1:
> { For 1 15 1 proc {$ I} C.I \=: I+47 end}
> % regle bidon 2:
> { For 3 15 1 proc {$ I} C.I \=: C.(I-2) end}
> % regle entre sujet et contre sujet: pas de second dim:
> { For 1 15 1 proc {$ I} (C.I) \=: (S.I) - 1 end}
> { For 1 15 1 proc {$ I} (C.I) \=: (S.I) + 1 end}
> {FD.distribute ff C}
> end
(snip)
> {Browse {SearchOne {Contre Sujet}}}
> {Browse 'this is the end'}
>
> It doesn't reach to end, and I don't know why :/ in my previous version,
> I had :
> proc {Contre C} and no rules about S.I and it worked fine.
> But even if I suppress those rules, it's still blocking, so I guess i'm
> miscalling SearchOne (the call looked like that in the "MapColoring"
> exemple of the tutorial), but as I said, i'm a newbie and I don't know
> how to correct that.

You are right. You should call SearchOne with a one-argument
procedure. Here is a slight modification of Contre, that takes S as
argument, and returns a one-argument procedure. So the call {Contre
Sujet} returns a one-argument procedure that is given to SearchOne...

fun {Contre S}
   proc {$ C}
      {FD.tuple compose 15 48#72 C}
      % {Browse S}
      % pas d'intervale superieur a la quinte:
      { For 2 15 1 proc {$ I} (C.I) <: (C.(I-1)) + 7 end}
      { For 2 15 1 proc {$ I} (C.I) >: (C.(I-1)) - 7 end}
      % pas d'intervale inferieure au ton:
      { For 2 15 1 proc {$ I} (C.I) \=: (C.(I-1)) + 1 end}
      { For 2 15 1 proc {$ I} C.I \=: C.(I-1) end}
      { For 2 15 1 proc {$ I} (C.I) \=: (C.(I-1)) - 1 end}
      % regle bidon 1:
      { For 1 15 1 proc {$ I} C.I \=: I+47 end}
      % regle bidon 2:
      { For 3 15 1 proc {$ I} C.I \=: C.(I-2) end}
      % regle entre sujet et contre sujet: pas de second dim:
      { For 1 15 1 proc {$ I} (C.I) \=: (S.I) - 1 end}
      { For 1 15 1 proc {$ I} (C.I) \=: (S.I) + 1 end}
      {FD.distribute ff C}
   end
end

If you're not familiar with the $ notation, you can write the function
as a procedure like below. This is exactly the same, only the way to
write it changes.

proc {Contre S P}
   proc {P C}
      ...
   end
end

Cheers,

-- 
Raphaël Collet - raph@info.ucl.ac.be - http://www.info.ucl.ac.be/~raph/
-
Please send submissions to users@mozart-oz.org
and administriva mail to users-request@mozart-oz.org.
The Mozart Oz web site is at http://www.mozart-oz.org/.
Please send bug reports to bugs@mozart-oz.org.



This archive was generated by hypermail 2b29.