[gecode-users] Sum over matrix slice

Christian Schulte cschulte at kth.se
Thu May 15 13:39:11 CEST 2014


Hi Tomas,

 

According to the documentation slice(i1,i2,j1,j2) extracts the elements with
coordinates in [i1,i2) and [j1,j2).

 

So, in your example, slice(i,i+1,i,i+1) extracts the elements with
coordinates [i,i+1) and [i,i+1) which is the single element with coordinates
i,i. That means you have to write slice(i,i+2,i,i+2).

 

Cheers

Christian

 

--

Christian Schulte, Professor of Computer Science, KTH,
www.ict.kth.se/~cschulte/

 

From: users-bounces at gecode.org [mailto:users-bounces at gecode.org] On Behalf
Of Tomas Lidén
Sent: Thursday, May 15, 2014 1:17 PM
To: users at gecode.org
Subject: [gecode-users] Sum over matrix slice

 

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/f4e05830/attachment.html>


More information about the users mailing list