  Consider a polynomial optimization problem. Adding polynomial equations
generated by the Fritz John conditions to the constraint set does not change
the optimal value. As proved in [arXiv:2205.04254 (2022)], the objective
polynomial has finitely many values on the new constraint set under some
genericity assumption. Based on this, we provide an algorithm that allows us to
compute exactly this optimal value. Our method depends on the computations of
real radical generators and Gr\"obner basis. Finally, we apply our method to
solve some instances of mathematical program with complementarity constraints.
