Next: , Previous: FDBG Writing Legend Printers, Up: FDBG Advanced Usage


10.14.4.4 Showing Selected Constraints (simple version)

Sometimes the programmer is not interested in every constraint, only some selected ones. Such a filter can be easily implemented with a user-defined visualizer. Suppose that you are interested in the constraints all_different/[1,2] and all_distinct/[1,2] only:

     %% spec_filter(+Constraint, +Actions):  Call fdbg_show for all constraints
     %%   for which interesting_event(Constraint) succeeds.
     %%
     %%   Use this filter by giving the constraint_hook(spec_filter) option to
     %%   fdbg_on.
     spec_filter(Constraint, Actions) :-
             interesting_event(Constraint),
             fdbg_show(Constraint, Actions).
     
     interesting_event(all_different(_)).
     interesting_event(all_different(_,_)).
     interesting_event(all_distinct(_)).
     interesting_event(all_distinct(_,_)).

Here is a session using the visualizer. Note that the initialization part (domain/3 events), are filtered out, leaving only the all_distinct/[1,2] constraints:

     | ?- [library('clpfd/examples/suudoku')].
     [...]
     | ?- fdbg_on([constraint_hook(spec_filter)]).
     % The clp(fd) debugger is switched on
     % advice
     | ?- suudoku([], 1, domain).
     all_distinct([1,<fdvar_1>,<fdvar_2>,8,<fdvar_3>,
                    4,<fdvar_4>,<fdvar_5>,<fdvar_6>],[consistency(domain)])
         fdvar_1 = 1..9 -> (2..3)\/(5..7)\/{9}
         fdvar_2 = 1..9 -> (2..3)\/(5..7)\/{9}
         fdvar_3 = 1..9 -> (2..3)\/(5..7)\/{9}
         fdvar_4 = 1..9 -> (2..3)\/(5..7)\/{9}
         fdvar_5 = 1..9 -> (2..3)\/(5..7)\/{9}
         fdvar_6 = 1..9 -> (2..3)\/(5..7)\/{9}
     
     [...]
     
     all_distinct([7,6,2,5,8,4,1,3,9],[consistency(domain)])
         Constraint exited.
     1 5 6 8 9 4 3 2 7
     9 2 8 7 3 1 4 5 6
     4 7 3 2 6 5 9 1 8
     3 6 2 4 1 7 8 9 5
     7 8 9 3 5 2 6 4 1
     5 1 4 9 8 6 2 7 3
     8 3 1 5 4 9 7 6 2
     6 9 7 1 2 3 5 8 4
     2 4 5 6 7 8 1 3 9
     yes
     % advice
     | ?- fdbg_off.
     % The clp(fd) debugger is switched off

Note that failure of spec_filter/2 doesn't cause any unwanted output.


Send feedback on this subject.