An optimal control method for real-time irrigation scheduling