typedef std::vector<index_type> column_type;
typedef D derived;
+ protected:
/** Create a matrix with 'width' columns, initalized with zero entries. */
boolean_colmatrix_base(size_t width) :
cols(width) {
}
+ public:
/** Get height resp. width of the matrix. */
size_t width() const {
return cols.size();
get_derived()->_set(r, c, value);
}
+ /** For each of the 'count'-many (row-index, column-pair) pair in 'indices', set the specific value. */
+ void set_all(index_type indices[][2], size_t count, bool value) {
+ for (unsigned i=0; i < count; ++i)
+ set(indices[i][0], indices[i][1], value);
+ }
+
/** Get the c-th column. */
const column_type& get_column(index_type c) const {
assert(c < width());
return !(*this == m);
}
+ /** Print index pairs of the 1s as { {r, c}, {r, c}, {r, c} } */
+ void print_indexpairs(std::ostream &os) const {
+ bool first=true;
+
+ os << "{";
+ for (unsigned c=0; c < width(); ++c) {
+ const column_type &col = get_column(c);
+ for (typename column_type::const_iterator it = col.begin(); it != col.end(); ++it) {
+ if (first)
+ first = false;
+ else
+ os << ",";
+ os << " {" << *it << ", " << c << "}";
+ }
+ }
+ os << " }";
+ }
+
protected:
/** Set the matrix entry at row 'r' and column 'c'. */
void _set(index_type r, index_type c, bool value) {
typedef std::vector<index_type> row_type;
typedef D derived;
+ protected:
/** Create a matrix with 'height' rows, initalized with zero entries.
* */
boolean_rowmatrix_base(size_t height) :
rows(height) {
}
+ public:
/** Get height resp. width of the matrix. */
size_t height() const {
return rows.size();
get_derived()->_set(r, c, value);
}
+ /** For each of the 'count'-many (row-index, column-pair) pair in 'indices', set the specific value. */
+ void set_all(index_type indices[][2], size_t count, bool value) {
+ for (unsigned i=0; i < count; ++i)
+ set(indices[i][0], indices[i][1], value);
+ }
+
/** Get the r-th row. */
const row_type& get_row(index_type r) const {
assert(r < height());
colbase::set(r, c, value);
}
+ /** For each of the 'count'-many (row-index, column-pair) pair in 'indices', set the specific value. */
+ void set_all(index_type indices[][2], size_t count, bool value) {
+ colbase::set_all(indices, count, value);
+ }
+
/** Get the matrix entry at row 'r' and column 'c'. */
bool get(index_type r, index_type c) const {
assert(colbase::get(r, c) == rowbase::get(r, c));
/** Multiply with matrix b from the right */
template<class D>
- boolean_colrowmatrix<IT> operator*(const boolean_colmatrix_base<IT, D> &b) {
+ boolean_colrowmatrix<IT> operator*(const boolean_colmatrix_base<IT, D> &b) const {
boolean_colrowmatrix<IT> c(size());
multiply_matrix(c, *this, b);
return c;
}
/** Multiply a*b and save the product in 'result'. It is assumed that 'result' is intially empty and has appropriate size. */
-template<class IT, class D, class RT>
-void multiply_matrix(RT &result, const boolean_rowmatrix_base<IT, D> &a, const boolean_colmatrix_base<IT, D> &b) {
+template<class IT, class D1, class D2, class RT>
+void multiply_matrix(RT &result, const boolean_rowmatrix_base<IT, D1> &a, const boolean_colmatrix_base<IT, D2> &b) {
assert(a.height() == b.width());
for (unsigned r=0; r < a.height(); ++r) {
- const typename boolean_rowmatrix_base<IT, D>::row_type &row = a.get_row(r);
+ const typename boolean_rowmatrix_base<IT, D1>::row_type &row = a.get_row(r);
for (unsigned c=0; c < b.width(); ++c) {
- const typename boolean_colmatrix_base<IT, D>::column_type &col = b.get_column(c);
+ const typename boolean_colmatrix_base<IT, D2>::column_type &col = b.get_column(c);
if (count_set_intersection(row.begin(), row.end(), col.begin(), col.end()) % 2 == 1)
result.set(r, c, true);
}
template<class IT>
std::ostream& operator<<(std::ostream &os, const boolean_colrowmatrix<IT> &mat) {
+
+ os << " ";
+ for (unsigned c=0; c < mat.size(); ++c) {
+ const unsigned d = (c % 10);
+ if (d > 0)
+ os << d;
+ else
+ os << " ";
+ }
+ os << std::endl;
+
for (unsigned r=0; r < mat.size(); ++r) {
+ const unsigned d = (r % 10);
+ if (d > 0)
+ os << d;
+ else
+ os << " ";
+
for (unsigned c=0; c < mat.size(); ++c)
os << (mat.get(r,c) ? "X" : ".");