The ships are out there and start from one harbour and sail to the destination harbour.
When your U-boat gets to within 30km of those ships, they are then drawn in the 3d game.
So yes the game is keeping track of all traffic and then spawns within a 30km radius
Open a campaign with ME2 and press play - you can see this happening