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

From: Marco Gavanelli <mgavanelli_at_ing.unife.it>
Date: Mon 04 Nov 2002 12:03:28 PM GMT
Message-Id: <5.1.0.14.2.20021104130234.00a68760@mail.ing.unife.it>
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.

E.g.,
:- 
bagof([X,B],search(X,0,input_order,indomain_min,complete,[backtrack(B)]),Bag),
get_last_element(El,Bag),
El=[LastSolution,TotalNumberOfBacktracks].

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 12:03:11 2002

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