Algorithms to Run the Trains on Time