[eclipse-clp-users] List to arrays

From: Annick Fron <list_at_...407...>
Date: Wed, 22 Jun 2016 12:19:12 +0200
Hi,

	I have a small program like this (see below). I want to generate a permutation of all matches, and put a sequence constraints on the columns, but I am not able to transform the generated list into an array, and I get into infinite loops when I ask: 
listeDesMatches(Liste,7), X is Liste[2].
What should I do ?

Annick Fron

listeDesMatches(Liste,N):-
	(for(I,1,N) , fromto([],In,Out,Liste),param(N) do
		listeDesMatches(I,SousListe,N),
		
		append(SousListe,In,Out)
	).


listeDesMatches(N,[],N). 	
listeDesMatches(I,Liste,N):-
	Iplus1 is I +1,
	listeDesMatches(I,Liste,N,Iplus1). 

listeDesMatches(I,[Match],N,N):- match(I,N,Match,N). 
listeDesMatches(I,[Match|Liste],N,Index):-
	match(I,Index,Match,N),
	Indexplus1 is Index +1,
	listeDesMatches(I,Liste,N,Indexplus1). 


match(I,J,Match,N):-
dim(Match,[N]),
Match :: 0..1,
(for(K,1,N),param(Match,I,J) do
	X is Match[K] ,
	X is (or((K#=I),(K#=J)))).
Received on Wed Jun 22 2016 - 10:37:29 CEST

This archive was generated by hypermail 2.2.0 : Mon Jul 09 2018 - 02:05:30 CEST