Units that can't find room would need to be pushed back a row I imagine?
The first line would need to be resolved first. You start with all units with the front settings and assign them randomly to the first line until it's full,
Instead of randomly, I would assign the largest unit, then the next, until it's almost full--and when the next group won't fit, keep trying until you find a group that fits. That way you fill the line as full as you can, the way you would if you were really trying to stop the enemy from entering the pass. Reinforcements would probably consist of one or two units at a time, again trying to optimize the space.
The attacking enemy would do the same thing--as many men as possible would move forward each time.
Example (defender only), with line width of 100:
L1: 45, 35, 15 (total of 95)
L2: 30, 25, 21 (total of 76)
If the first line took >24 casualties, then the 30 man unit moves up. If <16 casualties, then nobody moves up. You can figure out the values for the other two units, it'll be between 24 and 16.