![Very Happy :D](./images/smilies/icon_e_biggrin.gif)
I've been a little frustrated at times at how trains always favor the same bay to arrive at, if a station has two or more arrival bays. I started to tinker a little with the Combinators and here's what's happened:
![Image](https://forums.factorio.com/images/ext/10b451a55b9d6eb4fac61729b806a5a1.png)
And with the symbols on:
![Image](https://forums.factorio.com/images/ext/44a7e6b6e6b976468a78e3a266861e5f.png)
The way this works in a nutshell: The cargo amount from both bays is compared, and if both tracks are empty, the one with the biggest amount of cargo still waiting is closed (this can be reversed if you want the bay with the biggest amount instead). A bay closed in this fashion gets a Blue signal in this example.
Detailed explanation:
![Image](https://forums.factorio.com/images/ext/69254a9aacb037ae818350a41df7c1aa.png)
The system consists of 2x5 Combinators in a row, flanked by substations. Squished together tight enough that they'll fit in between the train tracks. Using the Substations also ensures that there's power for all the adjacent inserters. For better visibility I expanded one in the example above.
The expected input signal is the sum of the cargo type (simply create a circuit of all the storage of each bay)
The first row of combinators: Converts the cargo value for both sides into variables A and B. This has to be done because the same cargo type cannot be compared directly between different circuits.
The second row of combinators: Top one compares the values A and B, and returns value C (1 or 0). The bottom combinator is a logical NOT operator ("Everything = 0", returns D as 1 or 0).
The third row of combinators: Logical OR operators, these determine wether or not the track becomes active. These combine the signal for the preferred track with the Red signal from the opposite track to determine if the track should be greenlit.
The fourth row of combinators: Logical NOT operators that output the Blue signal with value 1. The output of these will be sent out to the track signalling and the status lamps.
The fifth row of combinators tests for a Red signal, and sends the output back to the third row (OR), but the opposite side.
The track switches finally should be set to both Close Signal and Read Signal, with closed condition "Blue = 1"
Result: When no trains are present, the most full (or empty, depending on the direction of the comparison) bay is closed with a Blue signal. When one train is present, the other bay is opened with a Green signal.
Limitations of this design:
- Meant for one cargo type. Mainly useful for bulk cargo such as ores or smelted metals. Also useful for grabbing the biggest partial cargo if using an inactivity timeout.
- Limited to 2 tracks in this design. Could be expanded, but would add significant complexity.
- Can be used in monodirectional or bidirectional stations - only the arrival signal is connected.