atmost/3

From: Tom Kelsey <tom_at_dcs.st-and.ac.uk>
Date: Tue 12 Nov 2002 03:02:25 PM GMT
Message-ID: <3DD11801.C7E634D2@dcs.st-and.ac.uk>
Hi,

I'm trying to constrain how often a variable can be set to
a value within a list of lists. The following code fragment returns

[1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, ...]
[1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, ...]

whereas I want 

[1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, ....]
[1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3,  ...]

Any ideas?

:- lib(ic).
:- lib(ic_global).
:- lib(matrix_util).
:- lib(lists).

test :-
	matrix(2,20,Rows,Cols),
	(
	    foreach(Row,Rows)
	do
	    Row :: 1..5,
	    atmost(4,Row,1),
	    atmost(4,Row,2)
	),
	concat(Rows,Vars),
	labeling(Vars),
	(
	    foreach(Row,Rows)
	do
	    writeln(Row)
	).


-- 
============================================================
Tom Kelsey                     Email:  tom@dcs.st-and.ac.uk
School of Computer Science     direct:   +44 (0)1334 463260
University of St Andrews       office:   +44 (0)1334 463253
North Haugh KY16 9SS           Fax:      +44 (0)1334 463278
          http://www-theory.dcs.st-and.ac.uk/~tom
============================================================
Received on Tue Nov 12 15:56:41 2002

This archive was generated by hypermail 2.1.8 : Wed 16 Nov 2005 06:07:18 PM GMT GMT