Re: Re:search/6 inside bagof/3?

From: Marco Gavanelli <mgavanelli_at_ing.unife.it>
Date: Mon 04 Nov 2002 02:31:33 PM GMT
Message-Id: <5.1.0.14.2.20021104152240.00a31e00@mail.ing.unife.it>
At 14.37 04/11/02, Warwick Harvey wrote:
>On Mon, Nov 04, 2002 at 01:03:28PM +0100, Marco Gavanelli wrote:
> > At 12.17 04/11/02, zeynep.kiziltan@dis.uu.se wrote:
> > >Dear Mark,
> > >
> > >Thank you for the help.
> > >
> > > > To get what you want you have to write:
> > > >
> > > 
> bagof([X,B],search(X,0,input_order,indomain_min,complete,[backtrack(B)]),Bag)
> > >
> > >I tried this, but somehow B is not instantiated to any value, so I 
> cannot see
> > >the number of failures when I have "write(B)" after bagof?
> >
> > In the solution by Mark, the number of backtracks is not in B, but in Bag.
> > Bag is a list of two-element lists. The second of the two-element list 
> is a
> > number, which represents the number of backtracks necessary to get to that
> > solution. If you want the total number, just consider the last one.
>
>Unfortunately, due to the design of the search library (it fails when there
>is no solution to return), there is no way to find out how many backtracks
>were required to prove that there are no more solutions after the last.

Yes, Warwick,
I did not consider the backtracks after the last solution.

>It
>is not clear how this could/should be fixed (suggestions welcome).

What about something like:

dummy_constraint(B,X) :-
         var(B), !,
         suspend.
dummy_constraint(0,X) :-
         impose_all_constraints(X).
dummy_constraint(1,X).

And, instead of:

program(X) :-
         impose_all_constraints(X),
         search(X,...).

writing something like:

program(X) :-
         B::0..1,
         dummy_constraint(B,X),
         search([B|X],...).

I am not happy at all of this solution, but maybe it could work for the 
problem of Zeynep.

Cheers,
Marco

:-
Marco Gavanelli, Ph.D.
Computer Science Division
DIF - Dipartimento di Ingegneria
University of Ferrara
Via Saragat 1 - 44100 Ferrara (Italy)
Fax  +39-0532-768602
Cell +39-329-4280354
http://www.ing.unife.it/docenti/MarcoGavanelli/
:- 
Received on Mon Nov 04 14:31:15 2002

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