Combining reinforcement learning and optimal control for the control of nonlinear dynamical systems