|
| 1 | + |
| 2 | +#include "AuctionAlgorithm/Auction.h" |
| 3 | +#include "AuctionAlgorithm/AuctionMT.h" |
| 4 | +#include "Matrix/SparseMatrix.h" |
| 5 | +#include <boost/random/mersenne_twister.hpp> |
| 6 | +#include <boost/random/uniform_int_distribution.hpp> |
| 7 | +#include <boost/random/uniform_real_distribution.hpp> |
| 8 | +using namespace LSAP; |
| 9 | + |
| 10 | +typedef double Scalar; |
| 11 | + |
| 12 | +typedef Eigen::Matrix<Scalar, -1, -1> WeightMatrix; |
| 13 | + |
| 14 | +int main(int argc, char **argv) |
| 15 | +{ |
| 16 | + const size_t rows = 2000, cols = 5000; |
| 17 | + |
| 18 | + // assert that rows <= cols and coefficients are between 0 and 1! |
| 19 | + Eigen::MatrixXd m = Eigen::MatrixXd::Random(rows, cols); |
| 20 | + |
| 21 | + // shift coefficients to get positive values |
| 22 | + for ( size_t i = 0; i < rows; ++i) |
| 23 | + for ( size_t j = 0; j < cols; ++j ) |
| 24 | + m(i, j) += 1.; |
| 25 | + |
| 26 | + m /= m.maxCoeff(); // normalize to 0..1 |
| 27 | + |
| 28 | + // create sparse matrix from dense |
| 29 | + // this could take some time! |
| 30 | + // currently there's an own sparse class, might be changed to eigen sparse type |
| 31 | + // this matrix type stores the matrix in rowMajor AND colMajor format, so it uses |
| 32 | + // a lot of space! (this was due to testing purposes) |
| 33 | + SparseMatrix<double> s(m); |
| 34 | + |
| 35 | + // result type |
| 36 | + Edges solution; |
| 37 | + |
| 38 | + // single threaded computation and some time measurement |
| 39 | + MEASURE_DURATION_SINGLE((solution = Auction<double>::solve(m))); |
| 40 | + MEASURE_DURATION_SINGLE((solution = Auction<double, SparseMatrix<double> >::solve(s))); |
| 41 | + |
| 42 | + // multi threaded computation (2 threads) and time measurement |
| 43 | + MEASURE_DURATION_SINGLE((solution = AuctionMT<double>::solve(m, 2))); |
| 44 | + MEASURE_DURATION_SINGLE((solution = AuctionMT<double, SparseMatrix<double> >::solve(s, 2))); |
| 45 | + |
| 46 | +} |
0 commit comments