Let f, g1,..., gs be polynomials in R[X1,..., Xn]. Based on topological properties of generalized critical values, the authors propose a method to compute the global infimum f* of f over an arbitrary given real algebraic set V = {x ∈ Rn | g1(x) = 0,..., gs(x) = 0}, where V is not required to be compact or smooth. The authors also generalize this method to solve the problem of optimizing f over a basic closed semi-algebraic set S = {x ∈ Rn | g1(x) ≥ 0,..., gs(x) ≥ 0}.