Russ Abbott wrote:
Because much of the computation is encapsulated within a SearchAll, I found it difficult to debug. {Ozcar.breakpoint} doesn't seem to be triggered. I've been reduced to running very small subsections of the code in isolation or including a lot of output statements. Are there better ways?

Ozcar does not work with computation spaces: http://www.mozart-oz.org/documentation/ozcar/node9.html#chapter.limitations

I don't know any better way in your situation :-( It is easier if you use FD constraints, since you can run propagators in the toplevel space, and observe how they prune variable domains. Distributors cannot be run at the toplevel (for the reasons I explained in former emails).

In any event, I've written a logic program version of the Zebra puzzle: http://www.mozart-oz.org/documentation/fdt/node23.html#section.elimination.zebra <http://www.mozart-oz.org/documentation/fdt/node23.html#section.elimination.zebra>. I followed the FD strategy as closely as I could, which was quite closely. It's a pretty straightforward translation--although it runs on a bit. The strategy is to fill in the house numbers for one of the groups of properties. (I used Colors, but it doesn't matter.) It then runs all the constraints. Finally, it fills in any values that had not been filled in by the constraints.

I had a closer look at your program. That's very close to the FD one, indeed. The Colors trick is because the expression Nb.green > Nb.white blocks until both values are known.

As you will see if you look at it, I couldn't figure out how to write a decent Adjacent. So the current version is just brute force. When I tried to use X+1 and X-1 etc., I couldn't get it to work. I still don't know why, so I've given up for now.

Here is an Adjacent predicate that generates all possibilies for X and Y in the range 1..N, and then makes a choice with it.

   %% X and Y are adjacent integers between 1 and N
   proc {Adjacent N X Y}
      Nums = {List.number 1 N-1 1}   % the smallest one
      Alts = {Append
              {Map Nums fun {$ I} proc {$} X=I Y=I+1 end end}
              {Map Nums fun {$ I} proc {$} Y=I X=I+1 end end}}
   in
      {ChoiceList Alts}
   end

   %% makes a choice with a non-empty list of procedures
   proc {ChoiceList Ps}
      case Ps
      of [P]  then {P}
      [] P|Pr then choice {P} [] {ChoiceList Pr} end
      end
   end

I also forced myself to solve this problem in a "pure" logic style. The difficulty to grasp performance issues really bothered me more than what I expected. Reasoning with the FD solution is much simpler IMHO... Prolog now definitively looks like the COBOL of logic languages to me.

Cheers,
raph

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

Reply via email to