Trajectory optimization with gradient descent for a variable-volume float