Showing Selected Constraints (simple version)

Sometimes the programmer is not interested in every global 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 and all_distinct/1 only:

     %% spec_filter(+Constraint, +Actions):  Call fdbg_show for all constraints
     %%   for which intresting_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_distinct(_)).
     

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

     | ?- [library('clpfd/examples/suudoku')].
     [...]
     | ?- fdbg_on(constraint_hook(spec_filter)).
     % The clp(fd) debugger is switched on
     % advice
     | ?- suudoku([], 1, P).
     all_different([1,<fdvar_1>,<fdvar_2>,8,<fdvar_3>,
                    4,<fdvar_4>,<fdvar_5>,<fdvar_6>])
         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_different([7,6,2,5,8,4,1,3,9])
         Constraint exited.
     
     P = [...] ;
     no
     % advice
     | ?- fdbg_off.
     % The clp(fd) debugger is switched off
     

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