constrain list length in CLP (Prolog)

Viewed 49

I have an optimisation problem, where I want to minimse the length of a list which I have yet to construct. Language here is Prolog, using swipl's clpfd library.

Something along the lines of pred(L), length(L,N), labeling([min(N)],[....]).

Problem is: length/2 already sets the length, even if L is a variable, so this ain't CLP optimisation after that. So, can I somehow constrain the length of L to be N without instantiating N? Perhaps using reification if I know an upper bound for N (which I do) - but that does sound awfully complicated? TBH I have similar issues stopping with my pred/1 thing to commit to a particular list length, but I was just primarily curious about that length thing.

0 Answers
Related