Re: [eclipse-clp-users] Using sets ... generating two sets and their sums

From: Claudio Cesar de Sá <claudio_at_colmeia.udesc.br>
Date: Mon, 5 Dec 2011 03:55:27 +0100
Hi

Thanks for the helping, really, the problem are the libraries.
Now the code works, but I need a sum or weight of a set.  The weight
predicate has an array as second argument, how to set it for any/arbitrary
set? I want just a  elements' sum of a set.  Look my newest code:

Thanks once

claudio

:-lib(fd).
:-lib(fd_sets).
%%:-lib(branch_and_bound).


%% data
veloc(1,[61,66,63,69]).
veloc(4,[12,122,18,1,9,7]).

go :-
     veloc(1,L1), model(L1).
     %%veloc(4,L4), model(L4).

model(L) :-
      length(L,N), writeln( n: N), writeln( l: L),
      sort(L, Dominio),
      writeln( dom: Dominio),

      find_2_others(N, N1, N2),

      writeln( n1: N1) ,
      writeln( n2: N2) ,
      Weights = [](1, 1),

       fd_sets:(L1 :: [] .. Dominio),
       fd_sets:(L2 :: [] .. Dominio),
       fd_sets:(L3 :: [] .. Dominio),

     #(L1, N1),
     #(L2, N2),
     #(L3, N),

%%%%  HOW TO WORKs?
%%%%  weight(L1, Weights, W),).

     %% I need for THESE TWO CONSTRAINTS
     %%sum(L) #= (sum(L1) + sum(L2)),
     %%(Diff #= abs( sum(L1) - sum(L2) )),

     fd_sets:(union(L1, L2, L3)),
     label_sets([L1, L2]),
     write('Solutions: ........'), nl,
     writeln( solL1: L1) ,
     writeln( solL2: L2).


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
label_sets([]).
    label_sets([S|Ss]) :-
    insetdomain(S,_,_,_),
    %%%Instantiate Set to a possible value
    label_sets(Ss).

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 find_2_others(N,N1,N2):-
     Int is (N // 2),
     Rem is rem(N,2),
     N1 is Int,
     N2 is (Int + Rem).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%






2011/12/4 Joachim Schimpf <jschimpf_at_coninfer.com>

> Claudio Cesar de Sá wrote:
> > Hi
> >
> > Please ... what is my mistake in this trivial example with sets:
> >
> > %%:-lib(ic).
> > %%:-lib(branch_and_bound).
> > :-lib(fd).
> > :-lib(fd_sets).
> >
> > %% data
> > veloc(1,[61,66,63,69]).
> > veloc(4,[12,122,18,1,9,7]).
> >
> > go :-
> > veloc(1,L1), model(L1),
> > veloc(4,L4), model(L4).
> >
> > model(L) :-
> > length(L,N), writeln( n: N), writeln( l: L),
> > sort(L, Dominio),
> > writeln( dom: Dominio),
> >
> > find_2_others(N, N1, N2),
> >
> > writeln( n1: N1) ,
> > writeln( n2: N2) ,
> > write('xxxxxxxx is it correct this definition?'),
> >   L1 :: [ ] .. Dominio,
> >   L2 :: [ ] .. Dominio,
> >   L3 :: [ ] .. Dominio,
> >
> > #(L1, N1),
> > #(L2, N2),
> > #(L3, N),
> >
> > union(L1, L2, L3),
> >
> > label_sets([L1, L2]).
> >
> > The error is:
> >
> > undefined arithmetic expression in _472 is [] in module fd_domain
>
> You are calling the 'fd' version of the :: predicate (which is for
> declaring
> integer-variables), but you want the 'fd_sets' version (for set-variables).
> As Sergey already mentioned, when loading your code you got this warning:
>
> Ambiguous import of :: / 2 from [fd, fd_sets] in module eclipse
>
> telling you about this name conflict (which is due to an unfortunate
> design decision by myself a couple of years ago...).
>
> To tell ECLiPSe which version you want, you can write, for example:
>
>    fd_sets:(L1 :: Dominio)
>
> You need to do the same with the call to the union/3 constraint (which
> conflicts with the union/3 predicate for standard lists), e.g.
>
>    fd_sets:union(L1,L2,L3)
>
> Alternative ways to resolve such name conflicts are described in
> http://www.eclipseclp.org/doc/userman/umsroot040.html
>
>
> -- Joachim
>
>
> ------------------------------------------------------------------------------
> All the data continuously generated in your IT infrastructure
> contains a definitive record of customers, application performance,
> security threats, fraudulent activity, and more. Splunk takes this
> data and makes sense of it. IT sense. And common sense.
> http://p.sf.net/sfu/splunk-novd2d
> _______________________________________________
> ECLiPSe-CLP-Users mailing list
> ECLiPSe-CLP-Users_at_lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/eclipse-clp-users
>



-- 
claudio



    (
    ))
   |""|-.
   |__|-'


**********************************************************************
Skype: claudio_cesar_sa
http://claudiocesar.wordpress.com/about/
***********************************************************************
Received on Mon Dec 05 2011 - 02:55:35 CET

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