mark richardson wrote:
Hi,

I'm slowly working through tutorials on FD's and constraint based programming, working up to a final year degree project next year and there is something I'm not sure I understand fully. I was trying to find details about user defined propagators. I know that you can write your own in C++ but why can't you create one using standard Oz? or can you?

For example, say you have a function {Between X} that returns true if X is between 7 and 10.
Why can't this be used as a constraint? or if you can, how?

If some patient person could explain this a little I would be most grateful (or even just point me to some reference I haven't found yet).

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

I'm getting this confused I think.
I want to use an Oz function to 'constrain' not propagate.
Sorry about that, but I'm still confused about whether I can use a standard Oz function as a constraint.


Hi,

yes :-) In fact you could probably use a normal function as a constraint, but given that the function does no propagation this would just serve as an "assert" or something like that. The search itself would be just generate-and-test, which is probably not what you want.

If say your function was what you said,

fun {Constr X}
  7 =< X andthen X =< 10
end

(I hope my Oz syntax is still OK :-)) then saying "thread {Constr X}=true end" (threaded so that it looks like a propagator) should do it.

You have to understand what it actually does - "7 =< X" waits for X to get bound within the space where the thread runs. When that happens, the function compares the actual value with the bounds and, since the result is already constrained (bound) to "true", an unification exception is thrown when the condition does not hold. An exception in a space might turn into a failure in the case of unification error (I'm not sure...), however in case that it doesn't you can still wrap your function call like

thread
  try
    {Constr X}=true
  catch _ then
    fail
  end
end

This works for other errors as well, BUT you should try to have a specific filter in your "catch" clause (not just "_") so that you don't treat your programming errors as logical failures in your space!

However, writing Oz constraints is not impossible, you can just have an Oz thread hanging around waiting for some events on FD (or other) variables. For example, you can have a loop in your "propagator thread", use FD.watch.min to wait for a domain change (multiple waits can be combined e.g. using Value.waitOr), then use some reflection like FD.reflect.min to get actual domain info and then, if needed, post some new constraint or just perform a domain reduction as a reaction.

Hope this helps,
Filip

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

Reply via email to