From: Joachim Schimpf <jschimpf_at_coninfer.com>

Date: Wed, 29 Jun 2016 02:54:32 +0100

Date: Wed, 29 Jun 2016 02:54:32 +0100

On 28/06/16 15:04, Annick Fron wrote: > 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. alldifferent_matrix/1 takes a matrix (2-dimensional array) and places alldifferent/1 constraints on its rows AND columns. So "alldifferent_matrix on the columns" does not make sense. I would anyway recommend that you use individual alldifferent/1 constraints instead of alldifferent_matrix/1 (it is a prototype that currently works only for special cases like square matrices). Some further recommendations: Do not use lib(matrix_util), it is an old library from the times before ECLiPSe supported arrays properly. It represents matrices as lists of lists, which is hardly ever convenient. Use dim/2 to create matrices (arrays of arrays). It is seldom necessary to convert between lists and arrays. Most constraints, and predicates like labeling/1, accept both. This would be a more compact version of your code: essai(N,Span,M) :- Nb is N*(N-1)//2, dim(M, [Nb,N]), M #:: 0..1, ( for(J,1,N), param(M,Nb,Span) do sequence(0,1,Span,M[1..Nb,J]) ), ( for(I,1,Nb), param(M,N) do sum(M[I,1..N]) #= 2 ), array_flat(1, M, Vars), labeling(Vars). Cheers, Joachim > :-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)) > .Received on Wed Jun 29 2016 - 01:54:44 CEST

*
This archive was generated by hypermail 2.2.0
: Thu Jun 30 2016 - 18:13:13 CEST
*