51 if (i < _split.first || j >= _split.second)
72 template <
typename Matro
idType,
typename MatrixType>
77 std::vector <size_t> type(split.second);
79 typedef std::set <size_t> column_set_t;
80 column_set_t types[4];
87 for (
size_t column = 0; column < split.second; ++column)
91 size_t type = vector_space.
find(vector);
97 size_t reached_column = 0;
98 size_t starting_column = 0;
99 size_t connecting_row = 0;
103 std::vector <bipartite_graph_bfs_node> nodes;
104 column_set_t start_nodes = types[1];
105 column_set_t end_nodes = types[2];
106 std::copy(types[3].begin(), types[3].end(), std::inserter(end_nodes, end_nodes.end()));
108 if (
bipartite_graph_bfs(modified_matrix, dimensions, start_nodes, end_nodes,
false, nodes))
112 for (column_set_t::const_iterator iter = end_nodes.begin(); iter != end_nodes.end(); ++iter)
114 if (nodes[*iter].is_reachable())
116 reached_node = *iter;
121 else if (
bipartite_graph_bfs(modified_matrix, dimensions, types[2], types[3],
false, nodes))
125 for (column_set_t::const_iterator iter = types[3].begin(); iter != types[3].end(); ++iter)
127 if (nodes[*iter].is_reachable())
129 reached_node = *iter;
136 throw std::runtime_error(
"tu::find_column_witnesses failed to find paths between columns of different type.");
141 for (
size_t current_node = nodes[reached_node].predecessor; nodes[current_node].distance > 0; current_node = nodes[current_node].predecessor)
143 size_t next_node = nodes[current_node].predecessor;
144 if (nodes[current_node].distance > 1 && dimensions.
is_row(current_node))
146 assert (dimensions.
is_column(next_node));
152 else if (nodes[current_node].distance == 1)
161 if (starting_column > reached_column)
162 std::swap(starting_column, reached_column);
177 template <
typename Matro
idType,
typename MatrixType>
182 std::vector <size_t> type(
matroid.
size1() - split.first);
184 typedef std::set <size_t> row_set_t;
192 for (
size_t row = split.first; row < matrix.size1(); ++row)
196 size_t type = vector_space.
find(vector);
202 size_t reached_row = 0;
203 size_t starting_row = 0;
204 size_t connecting_column = 0;
207 std::vector <bipartite_graph_bfs_node> nodes;
208 row_set_t start_nodes = types[1];
209 row_set_t end_nodes = types[2];
210 std::copy(types[3].begin(), types[3].end(), std::inserter(end_nodes, end_nodes.end()));
212 if (
bipartite_graph_bfs(modified_matrix, dimensions, start_nodes, end_nodes,
false, nodes))
216 for (row_set_t::const_iterator iter = end_nodes.begin(); iter != end_nodes.end(); ++iter)
218 if (nodes[*iter].is_reachable())
220 reached_node = *iter;
225 else if (
bipartite_graph_bfs(modified_matrix, dimensions, types[2], types[3],
false, nodes))
229 for (row_set_t::const_iterator iter = types[3].begin(); iter != types[3].end(); ++iter)
231 if (nodes[*iter].is_reachable())
233 reached_node = *iter;
240 throw std::runtime_error(
"tu::find_row_witnesses failed to find paths between rows of different type.");
245 for (
size_t current_node = nodes[reached_node].predecessor; nodes[current_node].distance > 0; current_node = nodes[current_node].predecessor)
247 size_t next_node = nodes[current_node].predecessor;
248 if (nodes[current_node].distance > 1 && dimensions.
is_column(current_node))
250 assert (dimensions.
is_row(next_node));
256 else if (nodes[current_node].distance == 1)
264 if (starting_row < reached_row)
265 std::swap(starting_row, reached_row);
280 template <
typename Matro
idType,
typename MatrixType>
286 if (matrix(split.first, split.second - 2) == 0 || matrix(split.first + 1, split.second - 1) == 0)
300 template <
typename Matro
idType,
typename MatrixType>
303 for (
size_t row = 0; row < split.first; ++row)
305 for (
size_t column = split.second; column < matrix.size2(); ++column)
307 if (matrix(row, column) != 0)
330 template <
typename Matro
idType,
typename MatrixType>
333 for (
size_t row = split.first; row < matrix.size1(); ++row)
335 for (
size_t column = 0; column < split.second; ++column)
337 if (matrix(row, column) != 0)
362 template <
typename Matro
idType,
typename MatrixType>
376 for (
size_t column = 0; column <
matroid.
size2() / 2; ++column)
398 template <
typename Matro
idType,
typename MatrixType>
403 partition(worker_matrix, top_left_size.first, top_left_size.second, bottom_right_size.first, bottom_right_size.second);
407 if (top_left_size.first + top_left_size.second < 4 || bottom_right_size.first + bottom_right_size.second < 4)
423 assert (matrix_equals(matrix, worker_matrix));
443 template <
typename MappingValue>
457 return std::make_pair(negative, positive);
468 template <
typename NestedMinorSequence>
471 size_t current_height = 3;
472 size_t current_width = 3;
473 for (
size_t i = 0; i < nested_minors.size(); ++i)
475 if (current_height + current_width >= 8)
477 minor_size = std::make_pair(current_height, current_width);
480 current_height += nested_minors.get_extension_height(i);
481 current_width += nested_minors.get_extension_width(i);
484 assert (current_height + current_width >= 8);
486 minor_size = std::make_pair(current_height, current_width);
487 return nested_minors.size();
515 template <
typename Matro
idType,
typename MatrixType,
typename MappingValue>
517 MappingValue>& row_mapping, std::vector <MappingValue>& column_mapping,
size_pair_t minor_size,
size_t ext_height,
size_t ext_width,
519 unsigned long long max_enumerations,
unsigned int& next_percent,
logger& log,
size_t cut)
521 const size_t minor_length = minor_size.first + minor_size.second;
522 const size_t ext_length = ext_height + ext_width;
524 for (
size_t minor_enum_iter = 0; minor_enum_iter <= minor_length; ++minor_enum_iter)
527 bool minor_enum_is_row = minor_enum_iter < minor_size.first;
528 bool minor_enum_is_column = !minor_enum_is_row && minor_enum_iter != minor_length;
529 size_t minor_enum_index = minor_enum_is_column ? minor_enum_iter - minor_size.first : minor_enum_iter;
531 for (
size_t bits = 1; bits < (size_t) (1 << ext_length); ++bits)
534 std::fill(row_mapping.begin(), row_mapping.begin() + minor_size.first + ext_height, 1);
535 std::fill(row_mapping.begin() + minor_size.first + ext_height, row_mapping.end(), 0);
536 std::fill(column_mapping.begin(), column_mapping.begin() + minor_size.second + ext_width, 1);
537 std::fill(column_mapping.begin() + minor_size.second + ext_width, column_mapping.end(), 0);
540 size_t num_enumerated = 1;
541 if (minor_enum_is_row)
542 row_mapping[minor_enum_index] = -1;
543 else if (minor_enum_is_column)
544 column_mapping[minor_enum_index] = -1;
549 for (
size_t ext_enum_iter = 0; ext_enum_iter < ext_length; ++ext_enum_iter)
551 if (((bits >> ext_enum_iter) & 1) == 1)
554 if (ext_enum_iter < ext_height)
555 row_mapping[minor_size.first + ext_enum_iter] = -1;
557 column_mapping[minor_size.second + ext_enum_iter - ext_height] = -1;
561 if (num_enumerated < 2)
573 log.
line() << next_percent <<
"%";
576 next_enumeration = (max_enumerations * next_percent) / 100;
603 template <
typename Matro
idType,
typename MatrixType,
typename NestedMinorSequence>
607 typedef signed char mapping_value_t;
610 if (matrix.size1() + matrix.size2() < 12)
614 log.
line() <<
", TOO SMALL --> IRREGULAR";
615 std::cout << log << std::endl;
620 std::cout <<
"Matroid is too small to contain a (3|4)-separation and must be irregular." << std::endl;
629 assert(minor_size.first + minor_size.second >= 8);
630 assert(minor_size.first + minor_size.second <= 10);
636 std::vector <mapping_value_t> row_mapping(worker_matrix_base.size1(), 0);
637 std::vector <mapping_value_t> column_mapping(worker_matrix_base.size2(), 0);
640 unsigned long long enumeration = 0;
643 size_t cut = 0, full_cut = 0;
644 unsigned long long max_enumerations = 0;
648 max_enumerations = 1L << (minor_size.first + minor_size.second);
649 size_t h = minor_size.first;
650 size_t w = minor_size.second;
651 for (
size_t i = minor_index; i < nested_minors.size(); ++i)
653 switch (nested_minors.get_extension(i))
657 max_enumerations += h + w;
660 max_enumerations += 3 * (h + w) + 1;
664 max_enumerations += 7 * (h + w) + 4;
669 h += nested_minors.get_extension_height(i);
670 w += nested_minors.get_extension_width(i);
675 full_cut = log.
size();
676 log.
line() <<
", ENUMERATING " << max_enumerations <<
" PARTITIONS: ";
683 std::cout <<
"Enumerating " << max_enumerations <<
" partitions along the sequence." << std::endl;
687 unsigned long long next_enumeration = max_enumerations / 100;
688 unsigned int next_percent = 1;
691 size_t limit = (1 << (minor_size.first + minor_size.second));
692 for (
size_t bits = 0; bits < limit; ++bits)
696 for (
size_t row = 0; row < minor_size.first; ++row)
698 row_mapping[row] = ((bits >> row) & 0x1) ? 1 : -1;
700 for (
size_t column = 0; column < minor_size.second; ++column)
702 column_mapping[column] = ((bits >> (minor_size.first + column)) & 0x1) ? 1 : -1;
710 widths.second), result, extra_elements))
718 log.
line() << next_percent <<
'%';
721 next_enumeration = (max_enumerations * next_percent) / 100;
727 std::cout <<
"Complete enumeration of " << (minor_index + 1) <<
" minors done." << std::endl;
731 for (
size_t i = minor_index; i < nested_minors.size(); ++i)
733 size_t extension_height = nested_minors.get_extension_height(i);
734 size_t extension_width = nested_minors.get_extension_width(i);
736 result, extra_elements, enumeration, next_enumeration, max_enumerations, next_percent, log, cut))
740 minor_size.first += extension_height;
741 minor_size.second += extension_width;
745 std::cout <<
"Clever enumeration done for nested minor " << (i + 2) <<
"." << std::endl;
752 log.
line() <<
", ENUMERATED " << enumeration <<
" PARTITIONS --> IRREGULAR";
753 std::cout << log << std::endl;
759 std::cout <<
"Matroid does not contain a (3|4)-separation and must be irregular." << std::endl;
Definition: binary_linear_space.hpp:16
std::vector< bool > vector_type
Definition: binary_linear_space.hpp:19
bool insert_checked(const vector_type &vector)
Definition: binary_linear_space.hpp:96
int find(const vector_type &vector) const
Definition: binary_linear_space.hpp:133
Definition: logger.hpp:19
void clear()
Definition: logger.hpp:98
bool is_progressive() const
Definition: logger.hpp:67
std::stringstream & line()
Definition: logger.hpp:131
bool is_verbose() const
Definition: logger.hpp:58
size_t size() const
Definition: logger.hpp:108
void erase(size_t position)
Definition: logger.hpp:119
Definition: matrix_modified.hpp:14
size_type size1() const
Definition: matrix_modified.hpp:52
size_type size2() const
Definition: matrix_modified.hpp:61
Definition: matrix_permuted.hpp:17
const permutation_type & perm2() const
Definition: matrix_permuted.hpp:92
const permutation_type & perm1() const
Definition: matrix_permuted.hpp:74
Definition: matroid.hpp:22
size_t size1() const
Definition: matroid.hpp:77
size_t size2() const
Definition: matroid.hpp:86
name_type & name2(size_t index)
Definition: matroid.hpp:116
name_type & name1(size_t index)
Definition: matroid.hpp:96
@ ONE_ROW_ONE_COLUMN
Definition: nested_minor_sequence.hpp:28
@ ONE_ROW
Definition: nested_minor_sequence.hpp:26
@ TWO_ROWS_ONE_COLUMN
Definition: nested_minor_sequence.hpp:29
@ ONE_COLUMN
Definition: nested_minor_sequence.hpp:30
@ ONE_ROW_TWO_COLUMNS
Definition: nested_minor_sequence.hpp:27
Definition: permutations.hpp:44
size_type size() const
Definition: permutations.hpp:150
Definition: separation.hpp:18
std::pair< std::size_t, std::size_t > witness_type
Definition: separation.hpp:21
separation find_witnesses(MatroidType &matroid, MatrixType &matrix, size_pair_t split, matroid_element_set &extra_elements)
Definition: enumeration.hpp:281
void copy_partial_column(const MatrixType &matrix, VectorType &vector, size_t column, size_t first_row, size_t beyond_row)
Definition: partition.hpp:48
void find_row_witnesses(MatroidType &matroid, MatrixType &matrix, size_pair_t split, matroid_element_set &extra_elements)
Definition: enumeration.hpp:178
void find_column_witnesses(MatroidType &matroid, MatrixType &matrix, size_pair_t split, matroid_element_set &extra_elements)
Definition: enumeration.hpp:73
bool extend_to_3_4_separation(MatroidType &matroid, MatrixType &matrix, matrix_permuted< const integer_matrix > &worker_matrix, size_pair_t top_left_size, size_pair_t bottom_right_size, separation &separation, matroid_element_set &extra_elements)
Definition: enumeration.hpp:399
void pivot_top_right(MatroidType &matroid, MatrixType &matrix, size_pair_t &split, matroid_element_set &extra_elements)
Definition: enumeration.hpp:301
void copy_partial_row(const MatrixType &matrix, VectorType &vector, size_t row, size_t first_column, size_t beyond_column)
Definition: partition.hpp:28
void normalize_3_4_separation(MatroidType &matroid, MatrixType &matrix, size_pair_t &split, rank_distribution ranks, matroid_element_set &extra_elements)
Definition: enumeration.hpp:363
void pivot_bottom_left(MatroidType &matroid, MatrixType &matrix, size_pair_t &split, matroid_element_set &extra_elements)
Definition: enumeration.hpp:331
size_t find_first_7_element_minor(const NestedMinorSequence &nested_minors, size_pair_t &minor_size)
Definition: enumeration.hpp:469
bool enumerate_extension(MatroidType &matroid, MatrixType &matrix, matrix_permuted< const integer_matrix > &worker_matrix, std::vector< MappingValue > &row_mapping, std::vector< MappingValue > &column_mapping, size_pair_t minor_size, size_t ext_height, size_t ext_width, separation &separation, matroid_element_set &extra_elements, unsigned long long &enumeration, unsigned long long &next_enumeration, unsigned long long max_enumerations, unsigned int &next_percent, logger &log, size_t cut)
Definition: enumeration.hpp:516
size_pair_t apply_mapping(permutation &permutation, std::vector< MappingValue > &mapping)
Definition: enumeration.hpp:444
Definition: algorithm.hpp:14
permutation matrix_get_perm2(matrix_permuted< MatrixType > &matrix)
Definition: matrix_permuted.hpp:236
void sort(permutation &permutation, size_t first, size_t beyond, Less &less)
Definition: permutations.hpp:583
std::pair< size_t, size_t > size_pair_t
Definition: partition.hpp:12
bool bipartite_graph_bfs(const MatrixType &matrix, const bipartite_graph_dimensions &dimensions, const StartNodesContainerType &start_nodes, const EndNodesContainerType &end_nodes, bool reach_all, std::vector< bipartite_graph_bfs_node > &result)
Definition: bipartite_graph_bfs.hpp:182
rank_distribution
Definition: partition.hpp:59
@ RANK_TOO_HIGH
Definition: partition.hpp:60
@ RANK_BL_2_TR_0
Definition: partition.hpp:60
@ RANK_BL_0_TR_2
Definition: partition.hpp:60
permutation matrix_get_perm1(matrix_permuted< MatrixType > &matrix)
Definition: matrix_permuted.hpp:230
void matroid_permute1(matroid< NameType > &matroid, size_t index1, size_t index2)
Definition: matroid.hpp:162
void matrix_set_perm1(matrix_permuted< MatrixType > &matrix, const permutation &permutation)
Definition: matrix_permuted.hpp:254
void matroid_permute2(matroid< NameType > &matroid, size_t index1, size_t index2)
Definition: matroid.hpp:192
rank_distribution partition(matrix_permuted< const MatrixType > &matrix, size_t &top_left_height, size_t &top_left_width, size_t &bottom_right_height, size_t &bottom_right_width)
Definition: partition.hpp:76
boost::numeric::ublas::matrix< long long > integer_matrix
Definition: common.hpp:27
void matrix_set_perm2(matrix_permuted< MatrixType > &matrix, const permutation &permutation)
Definition: matrix_permuted.hpp:260
void matroid_set_perm1(matroid_permuted< MatroidType > &matroid, const permutation &permutation)
Definition: matroid_permuted.hpp:190
separation enumerate_separations(MatroidType &matroid, MatrixType &matrix, const NestedMinorSequence &nested_minors, matroid_element_set &extra_elements, logger &log)
Definition: enumeration.hpp:604
void matroid_binary_pivot(matroid< NameType > &matroid, size_t i, size_t j)
Definition: matroid.hpp:222
void matroid_set_perm2(matroid_permuted< MatroidType > &matroid, const permutation &permutation)
Definition: matroid_permuted.hpp:196
std::set< int > matroid_element_set
Definition: matroid_decomposition.hpp:19
Definition: bipartite_graph_bfs.hpp:39
bool is_row(index_type index) const
Definition: bipartite_graph_bfs.hpp:88
size_t index_to_column(index_type index) const
Definition: bipartite_graph_bfs.hpp:119
index_type column_to_index(size_t column) const
Definition: bipartite_graph_bfs.hpp:140
index_type row_to_index(size_t row) const
Definition: bipartite_graph_bfs.hpp:130
size_t index_to_row(index_type index) const
Definition: bipartite_graph_bfs.hpp:108
bool is_column(index_type index) const
Definition: bipartite_graph_bfs.hpp:98
Definition: enumeration.hpp:25
empty_bottom_left_modifier(size_pair_t split)
Definition: enumeration.hpp:34
value_type operator()(size_t i, size_t j, value_type value)
Definition: enumeration.hpp:49
int value_type
Definition: enumeration.hpp:26
Definition: comparators.hpp:108