1818
1919#include " matrix.h"
2020
21- #include < QDataStream>
22- #include < QtCompilerDetection>
23- #include < qassert.h>
24-
2521#include < Eigen/Core>
2622#include < Eigen/SparseCore>
2723
24+ #include < cassert>
2825#include < vector>
2926
3027
31- using Eigen::Index;
32- using VectorXidx = Eigen::Vector<Index,Eigen::Dynamic>;
33-
34-
3528namespace Graph {
3629
30+ using Eigen::Index;
31+
3732
3833// ! check if coeff(r,c)==1
3934bool IncidenceMatrix::isSet ( const Index r, const Index c) const
4035{
41- Q_ASSERT_X ( r>=0 && r<rows (), Q_FUNC_INFO, " row index out of range" );
42- Q_ASSERT_X ( c>=0 && c<cols (), Q_FUNC_INFO, " column index out of range" );
43- Q_ASSERT ( coeff (r,c)<2 );
36+ assert ( coeff (r,c)<2 );
4437 return coeff (r,c)==1 ;
4538}
4639
@@ -57,8 +50,7 @@ bool IncidenceMatrix::isSet( const last_t /*unused*/, const Index c) const
5750}
5851
5952
60-
61- // ! Biadjacency matrix A = [O, B; B',O]
53+ // ! Biadjacency matrix B = [O, A; A',O]
6254SparseMatrix<int > IncidenceMatrix::biadjacency () const
6355{
6456 const Index C = cols ();
@@ -84,62 +76,67 @@ SparseMatrix<int> IncidenceMatrix::biadjacency() const
8476
8577
8678// ! remove column c
87- void IncidenceMatrix::remove_column ( const Index c) {
88-
89- // qDebug() << Q_FUNC_INFO;
90-
91- Q_ASSERT ( c>=0 && c<cols () );
79+ void IncidenceMatrix::remove_column ( const Index c)
80+ {
81+ assert ( c>=0 && c<cols () );
9282
9383 const Index C = cols ()-1 ;
9484
95- SparseMatrix<int > TT (C+1 ,C);
85+ SparseMatrix<int > RR (C+1 ,C);
9686 for (Index i=0 ; i<c; i++) {
97- TT .insert (i,i) = 1 ;
87+ RR .insert (i,i) = 1 ;
9888 }
9989 for (Index i=c; i<C; i++) {
100- TT .insert (i+1 ,i) = 1 ;
90+ RR .insert (i+1 ,i) = 1 ;
10191 }
102- *this = (*this )*TT ;
92+ *this = (*this )*RR ;
10393}
10494
10595
10696// ! remove row r
10797void IncidenceMatrix::remove_row ( const Index r)
10898{
109- // qDebug() << QString("remove row #%1").arg(r);
110-
111- Q_ASSERT ( r>=0 && r<rows () );
99+ assert ( r>=0 && r<rows () );
112100
113101 const Index R = rows ()-1 ;
114102
115- SparseMatrix<int > SS (R,R+1 );
103+ SparseMatrix<int > LL (R,R+1 );
116104 for (Index i=0 ; i<r; i++) {
117- SS .insert (i,i) = 1 ; // i.e., true
105+ LL .insert (i,i) = 1 ;
118106 }
119107 for (Index i=r; i<R; i++) {
120- SS .insert (i,i+1 ) = 1 ;
108+ LL .insert (i,i+1 ) = 1 ;
121109 }
122110
123- *this = SS *(*this );
111+ *this = LL *(*this );
124112}
125113
126114
127- // ! remove i -th column and i -th row
128- void IncidenceMatrix::reduce ( const Index i )
115+ // ! remove r -th column and c -th row
116+ void IncidenceMatrix::reduce ( const Index r, const Index c )
129117{
130- Q_ASSERT ( i>=0 && i<rows () && i<cols () );
131- // qDebug() << QString("reduce %1").arg(i);
118+ assert ( r>=0 && r<rows () );
119+ assert ( c>=0 && c<cols () );
120+
121+ // selection matrix LL (left, rows)
122+ SparseMatrix<int > LL ( rows ()-1 ,rows ());
123+ for ( Index i=0 ; i<r; i++) {
124+ LL.insert (i,i) = 1 ;
125+ }
126+ for ( Index i=r; i<LL.rows (); i++) {
127+ LL.insert (i,i+1 ) = 1 ;
128+ }
132129
133- // selection matrix S
134- SparseMatrix<int > SS ( rows ()- 1 , rows () );
135- for ( Index j =0 ; j<i; j ++) {
136- SS .insert (j,j ) = 1 ;
130+ // selection matrix RR (right, cols)
131+ SparseMatrix<int > RR ( cols (), cols ()- 1 );
132+ for ( Index i =0 ; i<c; i ++) {
133+ RR .insert (i,i ) = 1 ;
137134 }
138- for ( Index j=i; j<SS. rows (); j ++) {
139- SS .insert (j,j+ 1 ) = 1 ;
135+ for ( Index i=c; i<RR. cols (); i ++) {
136+ RR .insert (i+ 1 ,i ) = 1 ;
140137 }
141138
142- *this = SS *(*this )*SS. transpose () ;
139+ *this = LL *(*this )*RR ;
143140}
144141
145142} // namespace Graph
0 commit comments