int main() { const int d = 10; // change this in order to experiment const int n = 100000; // change this in order to experiment // generate n random d-dimensional points in [0,1]^d CGAL::Random rd; std::vector<Point_d> points; for (int j =0; j<n; ++j) { std::vector<double> coords; for (int i=0; i<d; ++i) coords.push_back(rd.get_double()); points.push_back (Point_d (d, coords.begin(), coords.end())); } // benchmark all pricing strategies in turn CGAL::Quadratic_program_pricing_strategy strategy[] = { CGAL::QP_CHOOSE_DEFAULT, // QP_PARTIAL_FILTERED_DANTZIG CGAL::QP_DANTZIG, // Dantzig's pivot rule... CGAL::QP_PARTIAL_DANTZIG, // ... with partial pricing CGAL::QP_BLAND, // Bland's pivot rule CGAL::QP_FILTERED_DANTZIG, // Dantzig's filtered pivot rule... CGAL::QP_PARTIAL_FILTERED_DANTZIG // ... with partial pricing }; CGAL::Timer t; for (int i=0; i<6; ++i) { // test strategy i CGAL::Quadratic_program_options options; options.set_pricing_strategy (strategy[i]); t.reset(); t.start(); // is origin in convex hull of the points? (most likely, not) solve_convex_hull_containment_lp (Point_d (d, CGAL::ORIGIN), points.begin(), points.end(), ET(0), options); t.stop(); std::cout << "Time (s) = " << t.time() << std::endl; } return 0; }
void testcase() { int h, t; cin >> h >> t; vector<vector<vector<ET> > > powers; for (int j=0; j < h+t; j++) { vector<vector<ET> > var; for (int i=0; i < 3; i++) { vector<ET> row(31, -1); var.push_back(row); } powers.push_back(var); } for (int i=0; i < h; i++) { int x, y, z; cin >> x >> y >> z; powers[i][0][1] = x; powers[i][1][1] = y; powers[i][2][1] = z; } for (int i=0; i < t; i++) { int x, y, z; cin >> x >> y >> z; powers[h+i][0][1] = x; powers[h+i][1][1] = y; powers[h+i][2][1] = z; } if (t == 0 || h == 0) { cout << "0\n"; return; } int d; for (d=0; d <= 30; d += 5) { //cout << "try " << d << endl; Program qp (CGAL::LARGER, false, 0, false, 0); int var_ind = 0; for (int i=0; i < h; i++) { add_polynom(qp, d, i, powers); qp.set_b( i, -1); qp.set_r( i, CGAL::SMALLER); } for (int i=0; i < t; i++) { add_polynom(qp, d, h+i, powers); qp.set_b( h+i, 1); qp.set_r( h+i, CGAL::LARGER); } CGAL::Quadratic_program_options options; options.set_pricing_strategy(CGAL::QP_BLAND); Solution s = CGAL::solve_linear_program(qp, ET(), options); // Solution s = CGAL::solve_quadratic_program(qp, ET()); assert (s.solves_linear_program(qp)); if (s.status() != CGAL::QP_INFEASIBLE) { break; } } if (d <= 30) { for (; d >= 0; d--) { Program qp (CGAL::LARGER, false, 0, false, 0); int var_ind = 0; for (int i=0; i < h; i++) { add_polynom(qp, d, i, powers); qp.set_b( i, -1); qp.set_r( i, CGAL::SMALLER); } for (int i=0; i < t; i++) { add_polynom(qp, d, h+i, powers); qp.set_b( h+i, 1); qp.set_r( h+i, CGAL::LARGER); } CGAL::Quadratic_program_options options; options.set_pricing_strategy(CGAL::QP_BLAND); Solution s = CGAL::solve_linear_program(qp, ET(), options); // Solution s = CGAL::solve_quadratic_program(qp, ET()); assert (s.solves_linear_program(qp)); if (s.status() == CGAL::QP_INFEASIBLE) { cout << d+1 << endl; return; } } } cout << "Impossible!\n"; }
void algo() { int h,t; cin >> h >> t; vector<Cell> cells; cells.reserve(h + t); for (int i = 0; i < h + t; ++i) { int x,y,z; cin >> x >> y >> z; cells.PB(Cell(x,y,z)); } const int gamma = 0; bool sol = false; int var = gamma + 1; Program lp (CGAL::SMALLER, false, 0, false, 0); lp.set_u(gamma, true, 1); lp.set_c(gamma, -1); for(int i = 0; i < h + t; ++i) { lp.set_a(gamma, i, 1); } int degree = -1; while(degree < 9 && !sol) { ++degree; int varI = var; for(int he = 0; he < max(h,t); ++he) { var = varI; for(int i = 0; i <= degree; ++i) { for(int j = 0; j <= degree - i; ++j) { int l = degree - i - j; assert(l + i + j == degree); if(he < h) { double result = pow(cells[he].x, i) * pow(cells[he].y, j)* pow(cells[he].z, l); lp.set_a(var, he, result); } if(he < t) { double result = pow(cells[he + h].x, i) * pow(cells[he + h].y, j)* pow(cells[he + h].z, l); lp.set_a(var, he + h, -result); } ++var; } } } varI = var; CGAL::Quadratic_program_options options; options.set_pricing_strategy(CGAL::QP_BLAND); Solution s = CGAL::solve_linear_program(lp, ET(), options); assert (s.solves_linear_program(lp)); if(s.is_optimal() && s.objective_value() < 0) { sol = true; } } if(!sol) { int min_degree = degree = 10; int max_degree = 30; while(min_degree <= max_degree) { int d = (min_degree + max_degree) / 2; Program lp (CGAL::SMALLER, false, 0, false, 0); lp.set_u(gamma, true, 1); lp.set_c(gamma, -1); for(int i = 0; i < h + t; ++i) { lp.set_a(gamma, i, 1); } int varI = var; for(int he = 0; he < max(h,t); ++he) { var = 1; for(int k = 0; k <= d; ++k) { for(int i = 0; i <= k; ++i) { for(int j = 0; j <= k - i; ++j) { int l = k - i - j; assert(l + i + j == k); if(he < h) { double result = pow(cells[he].x, i) * pow(cells[he].y, j)* pow(cells[he].z, l); lp.set_a(var, he, result); } if(he < t) { double result = pow(cells[he + h].x, i) * pow(cells[he + h].y, j)* pow(cells[he + h].z, l); lp.set_a(var, he + h, -result); } ++var; } } } } // varI = var; CGAL::Quadratic_program_options options; options.set_pricing_strategy(CGAL::QP_BLAND); Solution s = CGAL::solve_linear_program(lp, ET(), options); assert (s.solves_linear_program(lp)); // cout << "Min degree " << min_degree << endl ; // cout << "Current degree " << d << " Min degree " << min_degree << endl; if(s.is_optimal() && s.objective_value() < 0) { sol = true; max_degree = d - 1; degree = d; } else { min_degree = d + 1; } } } if(!sol) { cout << "Impossible!\n"; } else { cout << degree << "\n"; } }