What am I doing wrong?

From: Marc van Dongen <dongen_at_cs.ucc.ie>
Date: Thu 14 Mar 2002 09:02:47 AM GMT
Message-ID: <20020314090247.L16835@cs.ucc.ie>
Dear group,


Recently, I have started with ECLiPSe and I like it.
At the moment I am trying to implement a prdicate called
sal (Satisfiable Association Lists).

   % sal/3( +V, +W, -VWS ).
   % V, W fd variables, VWS association list.
   % Create an association list with members of the form [V_,WS_]
   % such that WS_ \= [] and for each W in WS the assignment
   % V = V_ and W = W_ is allowed by the current constraint store.

The code is strongly inspired by the example to count
the number of backtracks that came with ECLiPSe.

In the implementtation included below, I must be doing something
wrong. The predicate always works fine if it is run from the command
line. However, if used when there are suspended constraints acting
upon the domains of the first two arguments of sal/3 then the
list VWS contains duplicates and some of the elements [V_,WS_] of
VWS are  such that WS_ also contains duplicates.

What am I overlooking/doing wrong? Any help will be greatly
appreciated.

   % sal/3( +V, +W, -VWS ).
   % V, W fd variables, VWS association list.
   % Create an association list with members of the form [V_,WS_]
   % such that WS_ \= [] and for each W in WS the assignment
   % V = V_ and W = W_ is allowed by the current constraint store.
   sal( V, W, VWS ) :-
     shelf_create( stack( [] ), SHELF_VW ),
     shelf_create( stack( [] ), SHELF_W ),
     sal_vw( SHELF_VW, SHELF_W, V, W, VWS ),
     shelf_abolish( SHELF_W ),
     shelf_abolish( SHELF_VW ).

   % sal_vw/5
   sal_vw( SHELF_VW, SHELF_W, V, W, _ ) :-
     indomain( V ),
     sal_vw( SHELF_VW, SHELF_W, V, W ),
     fail.
   sal_vw( SHELF_VW, _, _, _, VWS ) :-
     shelf_get( SHELF_VW, 1, RVWS ),
     reverse( RVWS, VWS ).

   % sal_vw/4
   sal_vw( SHELF_VW, SHELF_W, V, W ) :-
     shelf_set( SHELF_W, 1, [] ),
     sal_w( SHELF_W, W, WS ),
     ( null( WS ) ->
         true
     ;
         push_shelf( SHELF_VW, [V,WS] )
     ).

   % sal_w( +SHELF, +W, -WS ).
   % SHELF is a scratch shelf, W is an fd variable, and
   % WS is the list consisting of the members from the
   % domain of W whose assignment to W is allowed by the
   % constraint store.
   sal_w( SHELF_W, W, _ ) :-
     indomain( W ),
     push_shelf( SHELF_W, W ),
     fail.
   sal_w( SHELF_W, _, WS ) :-
     shelf_get( SHELF_W, 1, RWS ),
     reverse( RWS, WS ).

   push_shelf( SHELF, H ) :-
     shelf_get( SHELF, 1, T ),
     shelf_set( SHELF, 1, [H|T] ).



Regards,


Marc van Dongen
-- 
M.R.C. van Dongen  | CS Dept University College Cork    |        ()
  dongen@cs.ucc.ie | Cork Constraint Computation Centre |        /\
 +353(0)21 4903578 | Western Road                       |   ASCII ribbon
                   | Cork, Ireland                      | against html mail
Received on Thu Mar 14 09:06:54 2002

This archive was generated by hypermail 2.1.8 : Wed 16 Nov 2005 06:07:13 PM GMT GMT