Page 1 of 1

obtaining information from incidence matrices

Posted: 31 Jan 2012, 18:27
by ren
Hello, I am a little bit stuck in understanding your implementation of incidence matrices.
Correct me if I am wrong, but it seems to me that an incidence matrix, say {0,1} {0,2}, is internally stored as something alike a 2x3 matrix of the form
1 1 0
1 0 1
where each row corresponds to a set, each columns corresponds to a column, and boolean entries say whether a set contains an element of not.
Say the incidence matrix is called m, then I can get the number of colums and rows through m.cols() and m.rows(). But how can I get the boolean entries?
(Of course I tried the trivial method bool b = m[j] or b = m(i)(j). I hope the answer isn't written at some obvious place in the library, where I missed it.)

best regards and thanks in advance, Yue.

Re: obtaining information from incidence matrices

Posted: 31 Jan 2012, 19:14
by joswig
I hope the following example explains a little how to use incidence matrices.

Code: Select all

polytope > $M=new IncidenceMatrix([[0,1,2],[0,2,3],[0,1,19]]); polytope > print $M; {0 1 2} {0 2 3} {0 1 19} polytope > print $M->rows(); 3 polytope > print $M->cols(); 20
Now, the following gives an error.

Code: Select all

polytope > print $M->[1][2]; polymake: ERROR: No random access at input line 1.
The reason is that the incidence matrices are sparse and do not sport random access (as the error says). Instead you can do the following.

Code: Select all

polytope > print $M->row(1)->contains(2); 1
Think of each row/column as a set.

Re: obtaining information from incidence matrices

Posted: 01 Feb 2012, 10:31
by gawrilow
There is also a more compact form of this query:

Code: Select all

print $M->(1,2);
It has the same performance as the expression above, but saves some typing and also works as lvalue, that is, if the matrix $M is not write-protected, you can assign to it any boolean expression:

Code: Select all

$M->(1,2) = 0; $M->(2,1) = $a && $b;

Re: obtaining information from incidence matrices

Posted: 01 Feb 2012, 17:41
by ren
thanks, words like a charm!