Fred,

I don't think it is possible to align data in columns in the Browser or the Inspector. So I quickly made a small window in QTk that shows the current state of the variables in a sudoku grid. The window is automatically updated whenever the domains change. I even added a "flash" effect, so that you can visually see which variables are updated.

The small program is attached.  Enjoy!

Cheers,
raph

Fred Spiessens wrote:
I have to give a presentation of CP (at IMEC) and I want to show live how far propagation alone can get you with a sudoku example. I want to show how the variable domains are updated by the propagators every time I assign a value to a sudoku field from the OPI. Browsing the square as a tuple of FD.tuples in the browser can achieve this, but is there simple way to make the columns line out nicely in the browser?
Did anybody make such a showcase already?

declare
[QTk]={Module.link ['x-oz://system/wp/QTk.ozf']}

%% return a label description for the variable X
fun {MakeLabel X}
   H
   proc {Init}
      Sz={FD.reflect.size X}
   in
      {H set(text:{Value.toVirtualString X 10 10})}
      thread {Loop Sz} end
   end
   proc {Loop Sz}
      %% keeps updating the widget
      if {FD.watch.size X Sz} then
         Sz1={FD.reflect.size X}
      in
         {H set(text:{Value.toVirtualString X 10 10})}
         %% "flash" effect; comment out if you want
         {H set(bg:yellow)}
         {Delay 500}
         {H set(bg:white)}
         %% end of "flash"
         {Loop Sz1}
      end
   end
in
   label(handle:H onCreation:Init anchor:center
         width:12 height:3 bg:white glue:nswe)
end

%% display a window for the given sudoku grid (tuple or row tuples)
proc {ShowSudoku Grid}
   _|Ls = for Row in {Record.toList Grid}   collect:Collect do
             {Collect newline}
             for X in {Record.toList Row} do
                {Collect {MakeLabel X}}
             end
          end
   Desc={List.toTuple lr Ls}
   Window={QTk.build Desc}
in
   {Window show}
end

Grid={MakeTuple grid 9}
{Record.forAll Grid proc {$ Row} Row={FD.tuple row 9 1#9} end}

%% alldiff constraints
for I in 1..9 do
   {FD.distinctD Grid.I}
end
for J in 1..9 do
   {FD.distinctD {Record.map Grid fun {$ Row} Row.J end}}
end
for BI in 0..2 do
   for BJ in 0..2 do
      Block = for I in 1..3   collect:Collect do
                 for J in 1..3 do
                    {Collect Grid.(3*BI+I).(3*BJ+J)}
                 end
              end
   in
      {FD.distinctD Block}
   end
end

{ShowSudoku Grid}

%% feed assignments (or constraints) here
Grid.1.1=3
Grid.1.5=7
_________________________________________________________________________________
mozart-users mailing list                               
[email protected]
http://www.mozart-oz.org/mailman/listinfo/mozart-users

Reply via email to