Foundations and Mathematical Methods of Dynamic Optimization