28 template <
typename MatroidType,
typename MatrixType,
typename NestedMinorSequenceType,
typename RowThreeConnectivity,
29 typename ColumnThreeConnectivity>
31 RowThreeConnectivity& row_three_connectivity, ColumnThreeConnectivity& column_three_connectivity)
33 for (
size_t row = nested_minors.height(); row <
matroid.
size1(); ++row)
35 if (row_three_connectivity.is_other(row))
38 row_three_connectivity.swap_vectors(nested_minors.height(), row);
40 row_three_connectivity.enlarge_base();
41 column_three_connectivity.enlarge_dimension();
64 template <
typename MatroidType,
typename MatrixType,
typename NestedMinorSequenceType,
typename RowThreeConnectivity,
65 typename ColumnThreeConnectivity>
67 RowThreeConnectivity& row_three_connectivity, ColumnThreeConnectivity& column_three_connectivity,
size_t& index)
71 bool found_column =
false;
72 for (
size_t row = nested_minors.height(); row <
matroid.
size1(); ++row)
74 if (row_three_connectivity.is_parallel(row))
76 index = row_three_connectivity.get_referred(row);
79 else if (row_three_connectivity.is_unit(row))
81 index = row_three_connectivity.get_referred(row);
86 for (
size_t column = nested_minors.width(); column <
matroid.
size2(); ++column)
88 if (column_three_connectivity.is_unit(column))
90 index = column_three_connectivity.get_referred(column);
93 else if (column_three_connectivity.is_parallel(column))
95 index = column_three_connectivity.get_referred(column);
99 return found_column ?
'c' : 0;
128 row_types_(row_types), column_types_(column_types)
144 switch (5 * row_types_[i] + column_types_[j])
170 const std::vector <index_type>& row_types_;
171 const std::vector <index_type>& column_types_;
188 template <
typename MatroidType,
typename MatrixType,
typename NestedMinorSequenceType,
typename RowThreeConnectivity,
189 typename ColumnThreeConnectivity>
191 RowThreeConnectivity& row_three_connectivity, ColumnThreeConnectivity& column_three_connectivity,
size_t index,
196 std::vector <size_t> start_nodes, end_nodes;
201 std::vector <elaborate_extension_matrix_modifier::index_type> row_types(
matroid.
size1());
204 if (row < nested_minors.height())
206 else if (row_three_connectivity.is_parallel(row) && row_three_connectivity.get_referred(row) == index)
211 else if (row_three_connectivity.is_zero(row))
221 std::vector <elaborate_extension_matrix_modifier::index_type> column_types(
matroid.
size2());
222 for (
size_t column = 0; column <
matroid.
size2(); ++column)
224 if (column < nested_minors.width())
226 else if (column_three_connectivity.is_unit(column) && column_three_connectivity.get_referred(column) == index)
231 else if (column_three_connectivity.is_zero(column))
235 column_types[column] = matrix(index, column) == 1
246 std::vector <bipartite_graph_bfs_node> bfs_result;
247 bool found_path =
bipartite_graph_bfs(modified_matrix, dim, start_nodes, end_nodes,
false, bfs_result);
252 size_t nearest_end = 0;
253 for (std::vector <bipartite_graph_dimensions::index_type>::const_iterator iter = end_nodes.begin(); iter != end_nodes.end(); ++iter)
255 if (bfs_result[*iter].is_reachable())
258 assert (bfs_result[nearest_end].is_reachable());
260 size_t nearest_distance = bfs_result[nearest_end].distance;
261 size_t connecting_start = 0;
262 size_t first_connected = 0;
263 size_t last_index = nearest_end;
264 size_t current_index = bfs_result[nearest_end].predecessor;
268 while (last_index != current_index)
280 nearest_distance -= 2;
285 if (bfs_result[current_index].distance == 0)
287 first_connected = last_index;
288 connecting_start = current_index;
291 last_index = current_index;
292 current_index = bfs_result[current_index].predecessor;
296 if (nearest_distance == 1)
299 std::swap(nearest_end, connecting_start);
301 assert (dim.
is_row(nearest_end));
302 assert (dim.
is_column(connecting_start));
309 else if (nearest_distance == 2)
312 if (connecting_start > nearest_end)
313 std::swap(connecting_start, nearest_end);
315 if (dim.
is_row(nearest_end))
317 assert (dim.
is_row(connecting_start));
327 assert (dim.
is_column(connecting_start));
343 std::pair <size_t, size_t> split(0, 0);
345 std::vector <int> reachable(matrix.size1());
346 for (
size_t row = 0; row < matrix.size1(); ++row)
349 int value = row < nested_minors.height() ? row - nested_minors.height() : (node.
is_reachable() ? 2 : 1);
350 reachable[row] = value;
360 reachable.resize(matrix.size2());
361 for (
size_t column = 0; column < matrix.size2(); ++column)
364 int value = column < nested_minors.width() ? column - nested_minors.width() : (node.
is_reachable() ? 2 : 1);
365 reachable[column] = value;
370 p.
reset(matrix.size2());
376 std::pair <size_t, size_t> witness(split.first, 0);
377 while (matrix(witness.first, witness.second) == 0)
379 assert (witness.second < nested_minors.width());
402 template <
typename Matro
idType,
typename MatrixType>
406 size_t cut = log.
size();
423 log.
line() <<
" + " << nested_minors.
size() <<
" EXT";
427 assert (nested_minors.
height() == row_three_connectivity.
base());
428 assert (nested_minors.
height() == column_three_connectivity.
dimension());
429 assert (nested_minors.
width() == row_three_connectivity.
dimension());
430 assert (nested_minors.
width() == column_three_connectivity.
base());
439 if (
find_simple_row_extension(transposed_matroid, transposed_matrix, transposed_nested_minors, column_three_connectivity,
440 row_three_connectivity))
445 size_t the_index = 0;
451 else if (type ==
'r')
461 else if (type ==
'c')
465 row_three_connectivity, the_index, extra_elements);
471 throw std::runtime_error(
"tu::find_minor_sequence: Invalid parallel/unit-vector type.");
474 row_three_connectivity.
reset(nested_minors.
width(), nested_minors.
height());
475 column_three_connectivity.
reset(nested_minors.
height(), nested_minors.
width());
481 log.
line() <<
" + " << nested_minors.
size() <<
" EXT";
Definition: logger.hpp:19
bool is_progressive() const
Definition: logger.hpp:67
std::stringstream & line()
Definition: logger.hpp:131
size_t size() const
Definition: logger.hpp:108
void erase(size_t position)
Definition: logger.hpp:119
Definition: matrix_modified.hpp:14
Definition: matrix_transposed.hpp:47
Definition: matroid_transposed.hpp:14
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
Definition: nested_minor_sequence.hpp:154
Definition: nested_minor_sequence.hpp:16
size_t width() const
Definition: nested_minor_sequence.hpp:121
@ 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_ROW_TWO_COLUMNS
Definition: nested_minor_sequence.hpp:27
size_t size() const
Definition: nested_minor_sequence.hpp:130
size_t height() const
Definition: nested_minor_sequence.hpp:112
Definition: permutations.hpp:44
void reset(size_t new_size)
Definition: permutations.hpp:111
Definition: separation.hpp:18
separation transposed()
Definition: separation.cpp:161
bool is_valid() const
Definition: separation.hpp:125
void set_special_swap(char type, size_t index)
Definition: separation.hpp:149
Definition: vector_three_connectivity.hpp:10
void reset(size_t dimension, size_t base)
Definition: vector_three_connectivity.hpp:34
size_t base() const
Definition: vector_three_connectivity.hpp:78
size_t dimension() const
Definition: vector_three_connectivity.hpp:83
#define CMR_UNUSED(x)
Definition: env.h:24
Definition: algorithm.hpp:14
void sort(permutation &permutation, size_t first, size_t beyond, Less &less)
Definition: permutations.hpp:583
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
separation find_minor_sequence(MatroidType &matroid, MatrixType &matrix, nested_minor_sequence &nested_minors, matroid_element_set &extra_elements, logger &log)
Definition: find_minor_sequence.hpp:403
bool find_simple_row_extension(MatroidType &matroid, MatrixType &matrix, NestedMinorSequenceType &nested_minors, RowThreeConnectivity &row_three_connectivity, ColumnThreeConnectivity &column_three_connectivity)
Definition: find_minor_sequence.hpp:30
separation find_elaborate_extension(MatroidType &matroid, MatrixType &matrix, NestedMinorSequenceType &nested_minors, RowThreeConnectivity &row_three_connectivity, ColumnThreeConnectivity &column_three_connectivity, size_t index, matroid_element_set &extra_elements)
Definition: find_minor_sequence.hpp:190
void matroid_apply_row_permutation(MatroidType &matroid, MatrixType &matrix, const permutation &perm)
Definition: matroid_reorder.hpp:18
void matroid_permute1(matroid< NameType > &matroid, size_t index1, size_t index2)
Definition: matroid.hpp:162
void matroid_apply_column_permutation(MatroidType &matroid, MatrixType &matrix, const permutation &perm)
Definition: matroid_reorder.hpp:40
void matroid_permute2(matroid< NameType > &matroid, size_t index1, size_t index2)
Definition: matroid.hpp:192
void matroid_binary_pivot(matroid< NameType > &matroid, size_t i, size_t j)
Definition: matroid.hpp:222
char find_parallel_or_unit_vector(MatroidType &matroid, MatrixType &matrix, NestedMinorSequenceType &nested_minors, RowThreeConnectivity &row_three_connectivity, ColumnThreeConnectivity &column_three_connectivity, size_t &index)
Definition: find_minor_sequence.hpp:66
std::set< int > matroid_element_set
Definition: matroid_decomposition.hpp:19
Definition: bipartite_graph_bfs.hpp:15
bool is_reachable() const
Definition: bipartite_graph_bfs.hpp:26
Definition: bipartite_graph_bfs.hpp:39
bool is_row(index_type index) const
Definition: bipartite_graph_bfs.hpp:88
std::pair< size_t, size_t > indexes_to_coordinates(index_type first, index_type second) const
Definition: bipartite_graph_bfs.hpp:155
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: find_minor_sequence.hpp:109
@ ZERO
Definition: find_minor_sequence.hpp:114
@ END0
Definition: find_minor_sequence.hpp:116
int operator()(size_t i, size_t j, int value)
Definition: find_minor_sequence.hpp:142
@ BLOCK
Definition: find_minor_sequence.hpp:113
unsigned char index_type
Definition: find_minor_sequence.hpp:111
@ START
Definition: find_minor_sequence.hpp:115
int value_type
Definition: find_minor_sequence.hpp:110
@ END1
Definition: find_minor_sequence.hpp:117
elaborate_extension_matrix_modifier(const std::vector< index_type > &row_types, const std::vector< index_type > &column_types)
Definition: find_minor_sequence.hpp:127
Definition: comparators.hpp:108