On Optimal Designs for Nonlinear Models: A General and Efficient Algorithm