Dual track station switching system

Smart setups of railway stations, intelligent routing, solutions to complex train-routing problems.
Please provide - only if it makes sense of course - a blueprint of your creation.
Post Reply
Aeternus
Filter Inserter
Filter Inserter
Posts: 835
Joined: Wed Mar 29, 2017 2:10 am
Contact:

Dual track station switching system

Post by Aeternus »

New player here but absolutely loving this game. Builders heaven... this reminds me a little of the old Transport Tycoon games I wasted half my youth on :D
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
And with the symbols on:
Image
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
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.

MrDrummer
Fast Inserter
Fast Inserter
Posts: 131
Joined: Sat Nov 22, 2014 2:51 pm
Contact:

Re: Dual track station switching system

Post by MrDrummer »

I tried this back when multiple stations with the same name wasn't overhauled to be useful, so attempted an 8 station design with Smart Trains.

The train arriving with the ore would go to a "decider" station, and compare all 8 deposits to determine the station with the least ore, which would be where the train would go to. (station to go to is determined by any 1 signals' value)

I had a hard time finding out the least value... But then that was with completely stock.

How would you approach more than two stations being compared without a "find minimum value mod" like https://mods.factorio.com/mods/Cobaltur/MathCoProcessor?

Even though i would certainly use this mod, I'm interested as to how complex it would have been, and how far off I was from getting it to work.

I'm currently doing a far more complex logic system where all ore trains are on the same schedule, and the it will "dispatch" an outpost at random, where the outposts "broadcast" their fill status using custom signals.

I'll probably make a post on it once I have it working.

EDIT: Please post a blueprint string viewtopic.php?f=8&t=29493? :)

Aeternus
Filter Inserter
Filter Inserter
Posts: 835
Joined: Wed Mar 29, 2017 2:10 am
Contact:

Re: Dual track station switching system

Post by Aeternus »

Thus far I've not had a need for more then 2 tracks for loading/unloading any one good type. Trains seem fast and have such a huge cargo capacity, that I've not had traffic issues... yet. But to your question - finding the least cargo from a number of arriving signals is easy:
Multiply each cargo value by 1 with an Arithmatic Combinator, and assign it to virtual channels 1 through 8 respectively. Neccesary step since comparing the same cargo type across two inputs doesn't work.
Then compare channels 1 and 2 with a Decider, and have it return the Value to another virtual channel... say, A. Then compare 3 with A, return least into A... and so on, until you have compared all 8. This should take 7 Deciders. You now have the lowest cargo value, but don't know which track yet.
Last stap is finding that out. 8 more Decider Combinators in the Equal setting, with the final "A" signal (containing the least cargo value), compared to the virtual channel 1, 2, 3 etc - which contain the actual cargo values. When the two values are Equal, you know you've got the right track, and you can set the signal green.
This would require at least 3 combinators per connected track, with no limit to the amount it would support. I say at least, because you probably want to make sure that any tracks already occupied are ignored in the comparison (if track signal red, set cargo amount on the virtual channel to 99999, should work, one more combinator per track).


I've been tinkering with a design without mods, to call a train to the station only when there is a full cargo available (and basically I don't care if it's the station with the biggest cargo - a full load available is sufficient). Basically, I set each station (resource outpost) to the same name, then use the circuit network to force the entrance signal for the station red if there's no full cargo available. This works, but only until there's no open station when a train tries to find one, then the train tries to go to whichever station is closest, even if it is blocked.
I suppose it's time to break out that wide-area signalling circuit I've been meaning to build. Haven't decided if I want to try multiplexing (real time signalling but encoding/decoding a non-binary value would be a pain) or a serial bus that cycles through the nodes (less of a hassle, but there's latency in the signalling). Probably easier to have a dummy version of the station that can buffer trains if they have nowhere to go.
The setup is just so damn convenient that I want to get this to work... Whenever you hook up a station to your rail net, set it to the generic resource type name, and all the ore haulers will automatically include it in their "schedule".

Aeternus
Filter Inserter
Filter Inserter
Posts: 835
Joined: Wed Mar 29, 2017 2:10 am
Contact:

Re: Dual track station switching system

Post by Aeternus »

More experimentation.
I've come to the conclusion that this system will only work well (IE work without jams) if you don't let more trains onto the network, then there are receiving stations open to handle them. This could be done with wide area signalling, carrying a single circuit network across the entire rail net (using big power poles inbetween the rails, with both the red and green circuit wires - these can link your outposts to main factory easily).

Trains would have to go into a hold before being released onto the network, just past the receiving station. Trick would be to keep the amount of trains enroute to loading equal or less then the amount of stations open for loading.
Trains would have the following states:
Waiting past unload / Hold
Moving to Loading point (+1)
Loading at Loading point (-1)
Moving to Unloading point
Unloading at Unloading point
Moving to Hold

The switching logic could get a bit tricky when expanding this to an arbitrary amount of tracks at the hold point (and incidentally, equal amount of trains). It should be possible though.

Post Reply

Return to “Railway Setups”