Well, I cheered too soon. Here are some screenshots: https://imgur.com/a/KIQDAh0 (shortly after placing the build order, a detail view of the problem and the finished result)
I tried to route 8 lanes of copper in one swoop by shift right clicking the starting belts and then the ending belts at the splitter. Your algorithm doesn't seem to respect already existing entity ghosts. Notice the brighter-than-normal ghosts. I suspect the algorithm just places two ghosts on top of each other.
I'll have to test it further. I suspect that if I let one lane be built and then do the next one it would yield better results.
Apart from that, the algorithm totally stalls the server. Do you try to do the pathfinding in one tick? Because it seems the game is waiting until the path finder is done. Could you make the pathfinder asynchronous? So the game continues to run while the path finder chuggs along until it reaches a result or a timeout?
Great work though!
Edit: I'm not very well versed in the Factorio API, but in Lua you can have Coroutines (https://www.lua.org/pil/9.1.html), which seem like the pathfinder needs to be wrapped in.
Edit2: Damn! coroutine isn't accessible in Factorio API (https://lua-api.factorio.com/latest/Libraries.html)
Edit3: https://forums.factorio.com/viewtopic.php?t=51186 Apparently you'd have to break up your loop(s) to be executed over several ticks. Is this possible?
Edit4: Here's a very interesting read how to spread the load over multiple ticks: https://forums.factorio.com/viewtopic.php?t=53405
Edit5:
Regarding the issue with the invalid placement of ghosts:
I think you need to add
build_check_type = defines.build_check_type.ghost_place
after the "position" table entry here https://github.com/Seancheey/FactorioBeltRouter/blob/dd13c4e8de36ab7cc9c0b7595a5650be8261b9f7/control.lua#L102