Hi, I have made progress in my program. I have almost a solution, but I would need to use : alldifferent_matrix on the columns, but I can’t find what type is expected. Regards Annick Fron :-lib(ic). :-lib(ic_global). :-lib(listut). :-lib(lists). :-lib(arrays). :- lib(matrix_util). :- import sequence/4 from ic_global_gac. :- import alldifferent_matrix/1 from ic_global_gac. essai(N,Span,Cols,Rows) :- Nb is (N*(N-1)//2), matrix(Nb,N,Rows,Cols), (foreach(XList,Cols),param(Span) do array_list(X,XList), dim(X,[Nb]), X #::0..1, sequence(0,1,Span,X) ), (foreach(RowList,Rows),param(N) do array_list(Row,RowList), dim(Row,[N]), Row #:: 0..1, sum(Row[1..N]) #= 2 ), (foreach(RowList,Rows),param(N) do array_list(Row,RowList), labeling(Row)) . Le 22 juin 2016 à 13:43, Joachim Schimpf <jschimpf_at_coninfer.com> a écrit : > On 22/06/16 11:19, Annick Fron wrote: >> Hi, >> >> I have a small program like this (see below). I want to generate a >> permutationof all matches, and put a sequence constraints on the >> columns, but I am not able to transform the generated list into an >> array, > > To convert a list to an array, use > http://eclipseclp.org/doc/bips/kernel/termmanip/array_list-2.html > > In your program, you know the list length in advance, so you could > also avoid the list completely, create an array in advance (dim/2) > and then fill in the elements. > > >> ... and I get into infinite loops when I ask: >> listeDesMatches(Liste,7), X is Liste[2]. > > The infinite loops happen when you backtrack into listeDesMatches/2. > They are caused by your predicates with the pattern > > p(N,N). > p(I,N) :- I1 is I+1, p(I1,N). > > You can either add the missing logical condition I<N, i.e. > > p(N,N). > p(I,N) :- I<N, I1 is I+1, p(I1,N). > > or, more efficiently, use > > p(I,N) :- > ( I<N -> > I1 is I+1, p(I1,N) > ; > true > ). > > >> What should I do ? > > Here is a different way to make the kind of list you want: > > listeDesMatches(Rows, N) :- > findall(Row, ( > dim(Row,[N]), > Row #:: 0..1, > sum(Row[1..N]) #= 2, > labeling(Row) > ), Rows). > > > -- Joachim > > ------------------------------------------------------------------------------ > Attend Shape: An AT&T Tech Expo July 15-16. Meet us at AT&T Park in San > Francisco, CA to explore cutting-edge tech and listen to tech luminaries > present their vision of the future. This family event has something for > everyone, including kids. Get more information and register today. > http://sdm.link/attshape > _______________________________________________ > ECLiPSe-CLP-Users mailing list > ECLiPSe-CLP-Users_at_lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/eclipse-clp-usersReceived on Tue Jun 28 2016 - 14:04:22 CEST
This archive was generated by hypermail 2.2.0 : Wed Jun 29 2016 - 06:13:36 CEST