obtaining information from incidence matrices

Questions and problems about using polymake go here.
ren
Posts: 38
Joined: 03 May 2011, 15:21

obtaining information from incidence matrices

Postby ren » 31 Jan 2012, 18:27

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.

User avatar
joswig
Main Author
Posts: 282
Joined: 24 Dec 2010, 11:10

Re: obtaining information from incidence matrices

Postby joswig » 31 Jan 2012, 19:14

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.

User avatar
gawrilow
Main Author
Posts: 423
Joined: 25 Dec 2010, 17:40

Re: obtaining information from incidence matrices

Postby gawrilow » 01 Feb 2012, 10:31

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;

ren
Posts: 38
Joined: 03 May 2011, 15:21

Re: obtaining information from incidence matrices

Postby ren » 01 Feb 2012, 17:41

thanks, words like a charm!


Return to “Helpdesk”