CMR  1.3.0
gen_generic.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <boost/random.hpp>
4 #include <tu/total_unimodularity.hpp>
5 #include "matrix_transposed.hpp"
6 #include "matrix_reorder.hpp"
7 #include "permutations.hpp"
9 
11 {
12 protected:
13  size_t _height;
14  size_t _width;
16  boost::mt19937 _rng;
18  const char* _name;
19 
20 public:
21  matrix_generator(const char* name, size_t height, size_t width, tu::log_level level) :
22  _height(height), _width(width), _matrix(height, width), _rng(time(NULL)), _level(level), _name(name)
23  {
24  }
25 
27  {
28 
29  }
30 
31  virtual void generate() = 0;
32 
34  {
35  if (_level != tu::LOG_QUIET)
36  std::cerr << "Generating " << _height << " x " << _width << " " << _name << " matrix..." << std::flush;
37  }
38 
40  {
41  if (_level != tu::LOG_QUIET)
42  std::cerr << " done." << std::endl;
43  }
44 
45  virtual bool do_pivot(size_t row, size_t column)
46  {
47  return true;
48  }
49 
50  template <typename MatrixType>
51  void permute_rows(MatrixType& matrix)
52  {
53  tu::permutation perm(matrix.size1(), _rng);
55  }
56 
57  void permute_rows()
58  {
60  }
61 
63  {
65  permute_rows(transposed);
66  }
67 
68  virtual void randomize()
69  {
70  permute_rows();
72  }
73 
74  virtual void sign()
75  {
77  }
78 
79  virtual void print()
80  {
81  std::cout << _height << " " << _width << "\n\n";
82  for (size_t row = 0; row < _height; ++row)
83  {
84  for (size_t column = 0; column < _width; ++column)
85  {
86  std::cout << std::setw(3) << _matrix(row, column);
87  }
88  std::cout << "\n";
89  }
90  std::cout << std::flush;
91  }
92 };
Definition: gen_generic.hpp:11
matrix_generator(const char *name, size_t height, size_t width, tu::log_level level)
Definition: gen_generic.hpp:21
void permute_rows()
Definition: gen_generic.hpp:57
void log_generate_end()
Definition: gen_generic.hpp:39
void permute_rows(MatrixType &matrix)
Definition: gen_generic.hpp:51
const char * _name
Definition: gen_generic.hpp:18
virtual void randomize()
Definition: gen_generic.hpp:68
virtual bool do_pivot(size_t row, size_t column)
Definition: gen_generic.hpp:45
boost::mt19937 _rng
Definition: gen_generic.hpp:16
virtual void print()
Definition: gen_generic.hpp:79
tu::log_level _level
Definition: gen_generic.hpp:17
virtual ~matrix_generator()
Definition: gen_generic.hpp:26
virtual void generate()=0
virtual void sign()
Definition: gen_generic.hpp:74
void log_generate_start()
Definition: gen_generic.hpp:33
tu::integer_matrix _matrix
Definition: gen_generic.hpp:15
size_t _height
Definition: gen_generic.hpp:13
size_t _width
Definition: gen_generic.hpp:14
void permute_columns()
Definition: gen_generic.hpp:62
Definition: matrix_transposed.hpp:47
Definition: permutations.hpp:44
log_level
Definition: common.hpp:36
@ LOG_QUIET
Definition: common.hpp:37
boost::numeric::ublas::matrix< long long > integer_matrix
Definition: common.hpp:27
bool sign_matrix(M &matrix, submatrix_indices *violator)
Definition: signing.hpp:138
void matrix_apply_row_permutation(MatrixType &matrix, const permutation &perm)
Definition: matrix_reorder.hpp:19