Optimization of polynomials on compact semialgebraic sets