#include <iostream>
#include <vector>
#include <algorithm>
#include <CGAL/basic.h>
#include <CGAL/Random.h>
#include <CGAL/QP_models.h>
#include <CGAL/QP_functions.h>
#ifdef CGAL_USE_GMP
#else
#endif
int n = 4;
int s = 10;
CGAL::Random rd;
int main() {
std::vector<std::vector<CGAL::Quotient<ET> > >
inv_a;
for (int j=0; j<n; ++j)
for (int i=0; i<n; ++i)
lp.set_a (j, i, rd.get_int (-s, s));
for (int j=0; j<n; ++j) {
lp.set_b (j, 1);
if (s.is_infeasible()) {
std::cout << "matrix is singular" << std::endl;
return 0;
} else {
std::copy (s.variable_values_begin(), s.variable_values_end(),
std::back_inserter (inv_a[j]));
}
lp.set_b (j, 0);
}
std::cout << "Random matrix A...:" << std::endl;
Program::A_iterator a = lp.get_a();
for (int i=0; i<n; ++i) {
for (int j=0; j<n; ++j)
std::cout << (*(a+j))[i] << " ";
std::cout << std::endl;
}
std::cout << std::endl << "...and its inverse: " << std::endl;
for (int i=0; i<n; ++i) {
for (int j=0; j<n; ++j)
std::cout << inv_a[j][i] << " ";
std::cout << std::endl;
}
for (int i=0; i<n; ++i)
for (int j=0; j<n; ++j) {
for (int k=0; k<n; ++k) val += (*(a+k))[i] * inv_a[j][k];
assert (val == (i == j ? 1 : 0));
}
return 0;
}