Re: What am I doing wrong?

From: Joachim Schimpf <j.schimpf_at_icparc.ic.ac.uk>
Date: Thu 14 Mar 2002 12:19:38 PM GMT
Message-ID: <3C90955A.1BC1DE24@icparc.ic.ac.uk>
Marc van Dongen wrote:
> 
> 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.

As far as I can tell, your code is correct.

The only reason I can imagine for the behaviour you see is that
some of your delayed goals create choicepoints when they wake up.
Having delayed goals create choicepoints is not a recommended
programming style, but the system doesn't prevent it.



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

Just as an aside: this is inefficient because both shelf_get and
shelf_set need to copy T every time. You should use a 'bag'
instead of a shelf.


Finally, your code can be written more compactly as

sal(V, W, VWS ) :-
  findall([V,Ws], ( indomain(V), findall(W, indomain(W), Ws) ), VWS).


-- 
 Joachim Schimpf              /             phone: +44 20 7594 8187
 IC-Parc, Imperial College   /            mailto:J.Schimpf@ic.ac.uk
 London SW7 2AZ, UK         /    http://www.icparc.ic.ac.uk/eclipse
Received on Thu Mar 14 12:21:09 2002

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