3 #include <boost/numeric/ublas/matrix_proxy.hpp>
27 std::copy(leaf->
elements().begin(), leaf->
elements().end(), std::inserter(result, result.end()));
28 if (collect_extra_elements)
38 if (first_elements.empty())
39 return second_elements;
40 else if (second_elements.empty())
41 return first_elements;
43 return (first_elements.size() < second_elements.size()) ? first_elements : second_elements;
47 template <
typename InputIterator,
typename OutputIterator1,
typename OutputIterator2>
48 std::pair <OutputIterator1, OutputIterator2>
split_elements(InputIterator first, InputIterator beyond, OutputIterator1 rows,
49 OutputIterator2 columns)
51 for (; first != beyond; ++first)
58 return std::make_pair(rows, columns);
61 template <
typename MatrixType>
67 sub_matroid.
resize(row_elements.size(), column_elements.size());
71 size_t index = row_elements.size() - 1;
72 for (matroid_element_set::const_iterator iter = row_elements.begin(); iter != row_elements.end(); ++iter)
74 sub_matroid.
name1(index) = *iter;
75 row_vector[index] = -1 - *iter;
80 for (matroid_element_set::const_iterator iter = column_elements.begin(); iter != column_elements.end(); ++iter)
82 sub_matroid.
name2(index) = *iter;
83 column_vector[index] = -1 + *iter;
103 std::cout <<
"\nMatrix is NOT totally unimodular. Searching the violating submatrix...\n" << std::endl;
128 typedef boost::numeric::ublas::matrix_indirect <const integer_matrix, submatrix_indices::indirect_array_type> indirect_matrix_t;
138 std::cout <<
"submatrix is t.u., but should not:" << std::endl;
139 matrix_print(sub_matrix);
151 typedef boost::numeric::ublas::matrix_indirect <const integer_matrix, submatrix_indices::indirect_array_type> indirect_matrix_t;
176 std::cout <<
"Submatrix did not pass the signing test. It is NOT totally unimodular.\n" << std::endl;
178 shrink(row_elements, column_elements);
193 std::cout <<
"\nSubmatrix is totally unimodular.\n" << std::endl;
195 delete decomposition;
203 delete decomposition;
216 std::cout <<
"\nThe " << row_elements.size() <<
" x " << column_elements.size() <<
" submatrix is NOT totally unimodular.\n" << std::endl;
223 shrink(row_elements, column_elements);
234 if (forbidden_elements.find(*iter) == forbidden_elements.end())
241 if (forbidden_elements.find(*iter) == forbidden_elements.end())
243 columns.insert(*iter);
247 return test(rows, columns);
278 std::vector <int> all_elements;
282 for (std::vector <int>::const_iterator iter = all_elements.begin(); iter != all_elements.end(); ++iter)
290 columns.erase(*iter);
324 for (std::vector <matroid_element_set>::const_iterator bundle_iter = bundles.begin(); bundle_iter != bundles.end(); ++bundle_iter)
336 for (
float rate = 0.8f; rate > 0.02f; rate *= 0.5f)
338 size_t row_amount, column_amount;
343 if (row_amount == 0 || column_amount == 0)
357 std::cout <<
"\nGreedy loop starting, forbidden sets will have size " << row_amount <<
" and " << column_amount << std::endl;
359 typedef std::vector <matroid_element_set::value_type> matroid_element_vector;
360 matroid_element_vector shuffled_rows, shuffled_columns;
364 std::random_shuffle(shuffled_rows.begin(), shuffled_rows.end());
365 std::random_shuffle(shuffled_columns.begin(), shuffled_columns.end());
367 std::vector <matroid_element_set> bundles;
369 for (matroid_element_vector::const_iterator iter = shuffled_rows.begin(); iter + row_amount <= shuffled_rows.end(); iter += row_amount)
372 std::copy(iter, iter + row_amount, std::inserter(bundles.back(), bundles.back().end()));
375 for (matroid_element_vector::const_iterator iter = shuffled_columns.begin(); iter + column_amount <= shuffled_columns.end(); iter
379 std::copy(iter, iter + column_amount, std::inserter(bundles.back(), bundles.back().end()));
Definition: matroid_decomposition.hpp:83
virtual bool is_regular() const
Definition: matroid_decomposition.hpp:163
Definition: matroid_decomposition.hpp:179
decomposed_matroid * first() const
Definition: matroid_decomposition.hpp:219
decomposed_matroid * second() const
Definition: matroid_decomposition.hpp:228
Definition: matroid_decomposition.hpp:26
virtual bool is_leaf() const =0
const matroid_element_set & extra_elements() const
Definition: matroid_decomposition.hpp:68
const matroid_element_set & elements() const
Definition: matroid_decomposition.hpp:59
Definition: violator_search.hpp:297
bool test_bundles(const std::vector< matroid_element_set > &bundles)
Definition: violator_search.hpp:322
virtual ~greedy_violator_strategy()
Definition: violator_search.hpp:310
virtual void search()
Definition: violator_search.hpp:334
greedy_violator_strategy(const integer_matrix &input_matrix, const matroid_element_set &row_elements, const matroid_element_set &column_elements, logger &log)
Definition: violator_search.hpp:299
Definition: violator_search.hpp:258
single_violator_strategy(const integer_matrix &input_matrix, const matroid_element_set &row_elements, const matroid_element_set &column_elements, logger &log)
Definition: violator_search.hpp:260
virtual void search()
Definition: violator_search.hpp:276
virtual ~single_violator_strategy()
Definition: violator_search.hpp:271
Definition: violator_search.hpp:93
virtual void shrink(const matroid_element_set &row_elements, const matroid_element_set &column_elements)
Definition: violator_search.hpp:126
bool test(const matroid_element_set &row_elements, const matroid_element_set &column_elements)
Definition: violator_search.hpp:149
matroid_element_set _row_elements
Definition: violator_search.hpp:252
virtual ~violator_strategy()
Definition: violator_search.hpp:111
void create_matrix(submatrix_indices &indices) const
Definition: violator_search.hpp:118
logger & _log
Definition: violator_search.hpp:254
violator_strategy(const integer_matrix &input_matrix, const matroid_element_set &row_elements, const matroid_element_set &column_elements, logger &log)
Definition: violator_search.hpp:95
bool test_forbidden(const matroid_element_set &forbidden_elements)
Definition: violator_search.hpp:228
const integer_matrix & _input_matrix
Definition: violator_search.hpp:251
matroid_element_set _column_elements
Definition: violator_search.hpp:253
Definition: logger.hpp:19
bool is_progressive() const
Definition: logger.hpp:67
bool is_verbose() const
Definition: logger.hpp:58
Definition: matroid.hpp:22
void resize(size_t size1, size_t size2)
Definition: matroid.hpp:63
name_type & name2(size_t index)
Definition: matroid.hpp:116
name_type & name1(size_t index)
Definition: matroid.hpp:96
#define CMR_UNUSED(x)
Definition: env.h:24
matroid_element_set find_smallest_irregular_minor(const decomposed_matroid *decomposition, bool collect_extra_elements=true)
Definition: violator_search.hpp:17
std::pair< OutputIterator1, OutputIterator2 > split_elements(InputIterator first, InputIterator beyond, OutputIterator1 rows, OutputIterator2 columns)
Definition: violator_search.hpp:48
void create_indirect_matroid(const MatrixType &input_matrix, const matroid_element_set &row_elements, const matroid_element_set &column_elements, integer_matroid &sub_matroid, submatrix_indices &sub_indices)
Definition: violator_search.hpp:62
Definition: algorithm.hpp:14
bool is_signed_matrix(const integer_matrix &matrix)
Definition: total_unimodularity.cpp:397
void support_matrix(integer_matrix &matrix)
Definition: total_unimodularity.cpp:462
boost::numeric::ublas::matrix< long long > integer_matrix
Definition: common.hpp:27
std::pair< bool, decomposed_matroid * > decompose_binary_matroid(MatroidType &matroid, MatrixType &matrix, matroid_element_set extra_elements, bool construct_decomposition, logger &log)
Forward declaration.
Definition: algorithm.hpp:484
std::set< int > matroid_element_set
Definition: matroid_decomposition.hpp:19
bool is_totally_unimodular(const integer_matrix &matrix, log_level level)
Definition: total_unimodularity.cpp:47
Definition: common.hpp:15
indirect_array_type columns
Definition: common.hpp:20
boost::numeric::ublas::vector< size_t > vector_type
Definition: common.hpp:16
boost::numeric::ublas::indirect_array< vector_type > indirect_array_type
Definition: common.hpp:17
indirect_array_type rows
Definition: common.hpp:19