Here (http://cs.calstatela.edu/~wiki/index.php/Courses/CS_460/Fall_2005/Notes_for_Oct_8#Second_Zebra_solution
) is my version of Zebra using the list of records representation:
Nb = [neighbor(color:white dring:juice ...) neighbor(color:blue drink:tea ...) ...]
It seems quite intuitive to me.
Here's the code for green comes after white. (Since it's only used once, it's inline.) The call
{Neighbor [color#white]}
creates a neighbor record in which color:white.
local Rest in
{Append _ {Neighbor [color#white]} | Rest Nb}
{IsMember {Neighbor [color#green]} Rest}end
-- Russ
On 10/7/05, Raphael Collet <[EMAIL PROTECTED]> wrote:
Russ Abbott wrote:
> I'm taken by your remark that Prolog is the COBOL of logic programming
> languages. Are you saying that logic programming in Oz is that much
> better than logic programming in Prolog or that FD in better than logic
> programming? Much of the recent discussion was a defense of Oz as a
> logic programming language, one that was not just a super FD system.
Here you deserve an explanation.
First, I apologize. I did not put a smiley next to the sentence, but
should definitively have put one! I intended to be provocative, but
only a bit. The reason is that I have been struggling with an element
in the problem.
The constraint Nb.green > Nb.white is tricky to implement efficiently
when you are limited to sequential programming with nondeterministic
choice. The statement
Nb.green > Nb.white = true
can only *check* that the values are ordered appropriately. Hence the
need to instanciate the "color" variables before that check. I have
tried to write that constraint such that it could instanciate the
variables. I came up with something like
%% X < Y in the range 1..N
proc {LessThan N X Y}
Alts = {Flatten
{Map {List.number 1 N-1 1}
fun {$ I}
{Map { List.number I+1 N 1}
fun {$ J} proc {$} X=I Y=J end end}
end}}
in
{ChoiceList Alts}
end
I thought it was pretty good, since it explicitly generates all pairs of
values that satisfy X<Y. No need to instanciate the color variables
anymore. But when I tried that version, suddenly the amount of search
to find the solution was multiplied by 15 or so! I was out of intuition
to explain the phenomenon. That explains my sad remark.
The fact is, I find FD programming simpler to reason about. You
basically separate the concerns. First choose the model, constraints,
and propagators that will ensure maximal pruning of the variables'
domains. Then think about heuristics. Which variable, once determined,
will allow much propagation on other variables?
I am probably mind-twisted myself ;-)
Cheers,
raph
_________________________________________________________________________________
mozart-users mailing list [email protected]
http://www.mozart-oz.org/mailman/listinfo/mozart-users
--
_____________________________________________
Professor, Computer Science
California State University, Los Angeles
o Check out my blog at http://russabbott.blogspot.com/
_________________________________________________________________________________ mozart-users mailing list [email protected] http://www.mozart-oz.org/mailman/listinfo/mozart-users
