Re: [eclipse-clp-users] How to use custom functions in searches

From: Sergey Dymchenko <kit1980_at_gmail.com>
Date: Fri, 27 May 2011 01:48:37 +0300
I believe I found the answer, thanks to
http://sourceforge.net/mailarchive/message.php?msg_id=20510733

On Fri, May 27, 2011 at 1:06 AM, Sergey Dymchenko <kit1980_at_gmail.com> wrote:
> Hi!
>
> I'm very new to Prolog and ECLiPSe.
>
> I can't understand how to use custom functions in searches.
>
> For example, I have a list A and I want to find all variants of list B
> such that maximum elements in vector product A*B is not greater than
> 20.
> The code I wrote:
>
>
> :- lib(ic).
>
> max_vector_product(L1, L2, R) :-
>        (foreach(E1, L1),
>         foreach(E2, L2),
>         foreach(Product, Product_list)
>        do
>        Product is E1 * E2
>        ),
>        R #= max(Product_list).
> arithmetic_function(max_vector_product/2).
>
> solve :-
>        A = [7, 8, 1],
>
>        length(A, N),
>        length(B, N),
>        B :: 0..3,
>        max_vector_product(A, B) #=< 20,
>        labeling(B),
>        writeln(B),
>        fail.
>
>
> But I get an error with the code: instantiation fault in *(7,
> _135682{0 .. 3}, _135754)
> How to deal with that?
>
> And the code works, for example, if I just want to limit maximum of B to 2 -
> max(B) #=< 2,
> but not with my custom function (and the custom function works on its own).
>
Received on Thu May 26 2011 - 22:48:43 CEST

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