You could also characterize the maximum braking ability of the train in front of you and the minimum braking ability of your own train and determine the needed distance for any given speed based on that. This would of course be more complicated and probably be solved by only including broad categories of trains (i.e. only two sets of values for either passenger trains or freight trains).