Re: [eclipse-users] Count number of non-ground variables in a list

From: Kish Shen <kisshen_at_cisco.com>
Date: Thu, 17 Jan 2008 20:45:57 +0000
Stephen Flinter wrote:
> Kish,
>
> thanks for the feedback.
>
> I'm using the IC solver.  I should, of course, have written C #= 
> count_nongound(Xs).  Apologies for the error on my part.
>
>
> ------------------------------------------------------------------------
Sorry, I forgot to mention this in my last reply: in the way you are 
using branch_and_bound/minimize, you should not be using a constraint 
here -- C (the cost variable for the objective) should be instantiated 
by your search procecure, i.e. you should be instantiating it rather 
than trying to write a constraint for it.

To count the number of variables in a list, assuming that each element 
of the list is simply either a variable or an integer, you can simply 
traverse the list and count the number of variables, something like:

count_nonground(Xs, N) :-
    (foreach(X, Xs), fromto(0, N1,N2, N) do
         (var(X) -> N2 is N1 + 1 ; N2 = N1)
    ).

Cheers,

Kish
Received on Thu Jan 17 2008 - 20:46:11 CET

This archive was generated by hypermail 2.2.0 : Thu Feb 02 2012 - 02:31:58 CET