> random factor of passenger loading and unloading and changing gaps between trains as they accelerate and decelerate between stations.
Solution: Never arrive early, never depart late, and keep the stopping durations fixed, at the longest time possible (which is one quarter the time between the two closest neighbouring stations).
That's not actually a solution. What do you do when someone holds the door open? Unless you have someone next to each door ready to boot such people out of the train, you simply can't stop yourself departing late.