On Wed, Sep 14, 2005 at 07:33:25PM -0700, Lyle Kopnicky wrote:
> Hi folks,
> 
> I'm a newbie, found Mozart on the web and thought it sounded neat.  I 
> have a background in functional and OO programming, but am interested in 
> constraints.  The only constraint language I've used before now is 

Mozart doesn't do constraint programming unless you specifically ask
for it.  Oz isn't quite that magic.  The usual execution of Oz
programs involves unification, which means that you can do things like

local X Y in
   [X 2] = [1 Y]
   {Browse [X Y]} % will show [1 2]
end

Unification ends up doing sometimes what you'd expect from full
constraint programming, especially if you sprinkle some thread...end
pairs in there to avoid suspending.  But not always.

> b) Y = 2 - X ^ Z = 3 + X + Y ^ Z = 4
> 
> I wrote that in Oz as:
> 
> local X Y Z in
>   Y = 2 - X
>   Z = 3 + X + Y
>   Z = 4
>   {Browse [X Y Z]}
> end
> 
> It didn't show an answer.  Since it is an unsatisfiable problem, I had 
> hoped to get an exception.

This exhibits Oz's semantics on using undefined values.  Instead of
throwing an exception or starting some sort of a search automatically
to see if it could find (some or all) answer(s), it suspends.  This
comes in use when you create more threads and share the variables
between them and bind them in other threads to allow suspended threads
to continue operation.  But I'm getting a bit ahead of myself here.

The point is that your execution suspends after Y = 2 - X since it
tries to use the value bound to the variable X, but X is unbound at
that point.  You would only get exception if you did something that
Mozart knew to be outright impossible, like 1 = 2.

I suggest that you look at the finite domain constraint programming
tutorial.  There you can find out how to write a script to state
constraint problems and how to search for solutions for them.

> local X Y in
>   X + Y = 5
>   X - Y = 12
>   {Browse [X Y]}
> end
> 
> I think it should give the answer [8.5 ~3.5], but it returned nothing.

First off, Mozart doesn't do implicit conversions from integers to
floats.

Oz's constraint programming involves finite domains, I'm afraid that
this kind of problems can't be solved with them anyway.  Though there
are sometimes ways to work around it and the set of problems solvable
by them is quite large already.

I hope this clears the situation somewhat.
_________________________________________________________________________________
mozart-users mailing list                               
[email protected]
http://www.mozart-oz.org/mailman/listinfo/mozart-users

Reply via email to