Foundations of Generic Optimization