Deterministic and Stochastic Optimal Control and Inverse Problems