SMS dit: Deterministic and stochastic optimal control