Search code examples
c++exponentcgalquadratic

CGAL Quadratic Programming Solver, how to enter "x^4" in objective function? and in the constraints?


I am trying to minimize a function like the following:

a*x^4+b*y

and constraints like:

x^2 <= a

in CGAL::Quadratic_program.

To input "x^2" in the objective function I can do the following:

qp.set_d(X, X, 2);

but what about "x^4" ?

To add a constraint like "x<=a":

hp.set_a(X, 0, 1);
hp.set_b(0, a);

but what about "x^2 <= a" ?


Solution

  • The solution to solve this

    enter image description here

    kind of problems is to modify the objective function and constraints, in this case by setting z^2 = z.

            //>=
            Program hp(CGAL::LARGER, false, 0, false, 0);
            //x+y >= -4
            hp.set_a(X, 0, 1); hp.set_a(Y, 0, 1);
            hp.set_b(0, -4);
            //4x+2y+z^2 >= -a*b
            //z^2 = z
            hp.set_a(X, 1, 4); hp.set_a(Y, 1, 2); hp.set_a(Z, 1, 1);
            hp.set_b(1, -a * b);
            //-x + y >= −1
            hp.set_a(X, 2, -1); hp.set_a(Y, 2, 1);
            hp.set_b(2, -1);
            //x <= 0
            hp.set_a(X,3,1);
            hp.set_b(3,0);
            hp.set_r(3,CGAL::SMALLER);
            //y <= 0
            hp.set_a(Y,4,1);
            hp.set_b(4,0);
            hp.set_r(4,CGAL::SMALLER);
            //objective function
            //min a*x^2 + b*y + z^4
            //z^2 = z
            //min a*x^2 + b*y + z^2
            hp.set_d(X, X, 2 * a); //2D
            hp.set_c(Y, b);
            hp.set_d(Z, Z, 2); //2D
    
            // solve the program
            Solution s = CGAL::solve_quadratic_program(hp, ET());
            assert(s.solves_quadratic_program(hp));