[gecode-users] Sum over matrix slice

Tomas Lidén tomas.liden at liu.se
Thu May 15 13:16:52 CEST 2014


Hi!

While working on a course assignment I realized (after some struggling) 
that summing over a matrix slice does not perform as expected:

=== snippet ==
BoolVarArray x(home, n*n, 0, 1);
Matrix<BoolVarArray> m(x, n, n);

rel(home, sum(m.slice(i, i+1, i, i+1)) > 0); // forces m(i,i) > 0 !!
BoolVarArgs s;
s << m(i,i) << m(i+1,i) << m(i,i+1) << m(i+1,i+1);
rel(home, sum(s) > 0); // forces the sum over the 4 variables > 0 (as I 
wanted)

== end of snippet ==

The sum(m.slice(...)) only seems to sum the first element in the slice?!
Quite surprising and unnatural to me. Am I doing something wrong here?
(I get no compiler warnings or errors..)

The following post discusses a similar subject concerning IntVar's..
http://www.gecode.org/pipermail/users/2013-August/004086.html

All the best,
Tomas

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.gecode.org/pipermail/users/attachments/20140515/4b7f92ab/attachment.html>


More information about the users mailing list