I've been wondering what's the most optimal way to utilize circuits to automate train transportation on a city-block level. The basic principle is to load on output stations and unloading on inputs stations, through an array of general-purpose trains.
Currently my main method is built around on creating recipe signals using multiplexers, these recipe signals are sent by input stations when their stocks run dry and once in a 256 tick cycle. The recipe signals are compared to all idle trains per cycle, if any trains has the compatible content compared to the recipe code, it will register the station's order and train ID, converting these signals into enable signals for both entities.
I want to know if there's a better way to handle these operations, because they are very hard and complex to deal with and I've already spent 80 hours developing them and yet I still have to fix unexpected issues (mostly with synchronization caused by combinator's delay).