I am sure there is a formula. But when NS tries a new innovation, to run a hotshot intermodal with 125 cars with only 2 locos on the head end, the train must get a running start up the 11 mile mountain grade, in order not to stall. Usually experience, guestimation, and on the job training, helps dispatchers maintain that enough power is available for steep gradients.
Usually a intermodal has 3 locos head end with no helpers, and merchandise freights and coal drags have upwards of 4 head end with 2 more shoving on the rear. Also the 2 rear end helpers assit in dynamic braking, helping slowing the rear end of the train down the other side of the mountain grade. The Pittsburgh line does not use mid train DPU.
Since they know that the Altoona to Johnstown gradient is @ 1.25% they usually add more power over the mountain, and sometimes remove un-needed power at the base of the grade, on the less steep trackage: Johnstown to Pittsburgh, and Altoona to Harrisburg, which generally has a gradient of much less than 1%.
Usually a 6 loco train is arrainged: <--//<--//<--//-->_______train________<--//--> so reverse moves can be easily facilitated. Usually a engine shop hostler arrainges locos in sets of 2, with locos facing, opposing one another: <--//--> And added power is hooked on when needed. Sometimes a lashup of particular units stays together for months at a time, until a breakdown occurs, or power is pulled off a consist, and is swapped.