// example: invert a random matrix (or find out that it's singular) #include #include #include #include #include #include #include // choose exact integral type #ifdef CGAL_USE_GMP #include typedef CGAL::Gmpz ET; #else #include typedef CGAL::MP_Float ET; #endif int n = 4; // dimension of matrix int s = 10; // coordinates are in {-s, -s+1,...,0,...,s-1,s} CGAL::Random rd; // random number generator // program and solution types typedef CGAL::Quadratic_program Program; typedef CGAL::Quadratic_program_solution Solution; int main() { std::vector > > inv_a; // stored columnwise // we need a free LP (no variable bounds) with Ax = b Program lp (CGAL::EQUAL, false, 0, false, 0); // constraint matrix A: the random matrix to be inverted for (int j=0; j >()); std::copy (s.variable_values_begin(), s.variable_values_end(), std::back_inserter (inv_a[j])); } lp.set_b (j, 0); // reset for next round } // output both matrices, and check that they are indeed inverse to each // other std::cout << "Random matrix A...:" << std::endl; Program::A_iterator a = lp.get_a(); for (int i=0; i val; for (int k=0; k