Dynamic Sushi Controller

This board is to show, discuss and archive useful combinator- and logic-creations.
Smart triggering, counters and sensors, useful circuitry, switching as an art :), computers.
Please provide if possible always a blueprint of your creation.
Post Reply
farcast
Long Handed Inserter
Long Handed Inserter
Posts: 86
Joined: Fri Jul 06, 2018 8:25 am
Contact:

Dynamic Sushi Controller

Post by farcast »

For any sushi belt loop, items need to be added in specific proportions to maximize the use of the limited throughput. These proportions are determined by the recipes of any machines that pull items from the sushi belt. You can calculate these proportions manually if there's only one final product, or if multiple final products are always taken in fixed proportions, but if the demand can change like in a mall, then adding items in fixed proportions will often waste space on the sushi belt for items that aren't needed. Since the ideal proportions are basically the active recipes, and the recipes are just what the machines will take from the sushi belt, a way to adapt to changing demand is to periodically count what gets taken from the sushi belt and use that as the proportions to follow when adding more items. This circuit does exactly that, as well as handle some of the complications that arise from trying to do exactly that.

The circuit is technically capable of handling any number of belts in parallel, but there are a couple of requirements that make it cumbersome to build a sushi bus with more than two belts. Firstly, lane balancers (belt balancers that also balance the left & right lanes of each belt) are actually required to use all available throughput. Secondly, if a sub factory only pulls from one belt of a two belt sushi bus, then you effectively only have a one belt sushi bus for the item that the sub factory produces, as well as for any recipe or recipe chain that uses that item, so all assemblers or sub factories need to be able to pull items from all belts of a sushi bus.

For those reasons, I made a set of blueprints for setting up a factory with a two belt sushi bus. If more throughput is required, you can build multiple two belt sushi factories.

Example Mall
Example Sushi Mall v1_8.jpg
Example Sushi Mall v1_8.jpg (767.91 KiB) Viewed 5348 times
This is a fully functional early game mall made from the other blueprints, meant to be an example of a correctly setup sushi factory.

Quick Start
DSC Quick Start v1_10.jpg
DSC Quick Start v1_10.jpg (336.55 KiB) Viewed 5065 times
This blueprint is the start and end of the sushi bus, and includes external item inputs, a warehouse, all the lane balancing necessary for a two belt sushi factory, as well as the circuit itself. There are three pairs of belts on one side that are supposed to connect to the factory. The middle pair of belts is where all intermediates produced by the factory that need to go on the sushi bus should be placed. The outer pairs need to connect to each other, and items should never be added to these belts, only taken away. I chose to separate supply from demand since it avoids the need to build multiple lane balancers all along the sushi bus.

Factory Segment
DSC Factory Segment v1_10.jpg
DSC Factory Segment v1_10.jpg (231.01 KiB) Viewed 5065 times
A tile-able blueprint with a simple way of setting up assembly machines along the sushi bus. It can be placed next to the quick start with one overlapping electric pole to automatically connect it to the circuit. Each assembly machine has an output chest. The ones on the inside also have a green wired output inserter with the correct settings for being controlled by the circuit, all you need to do is put the item produced by the assembly machine in the left side of the enable condition. This isn't the only way to set up the factory, nor is it the best, so this blueprint is meant to be a customizable base, but it's entirely functional on its own.

The factory is connected to the circuit with two wires. Only what moves items to/from the sushi bus should be connected. The red wire is for counting the items taken from the sushi bus, anything connected to this wire just needs to be set to pulse read. The green wire is for controlling what items get added to the bus, a positive number for an item signal means that there are enough of that item in the warehouse to meet the current demand, while a negative number indicates a demand for more of that item. Inserters connected to the green wire should be set to Enable if ITEM <= 0, pulse read. When controlling belts with the green wire like with the external inputs, use two belt tiles. The first tile should have the enable condition, and the immediate next tile should pulse read.

Warehouse
DSC Warehouse v1_10.jpg
DSC Warehouse v1_10.jpg (162.79 KiB) Viewed 5065 times
Items that travel all the way through the sushi bus without being used end up here. Both versions tile with each other if you upgrade the electric poles to mediums. A mirrored version won't tile with the original. No fiddling with circuit network stuff beyond checking if it's connected to the circuit is necessary when expanding the warehouse, just place the blueprint and done. The warehouse has throughput issues until you get the first non-stack inserter capacity bonus. Using normal inserters for the first warehouse section will help until then.

The warehouse is necessary to actively clean out the sushi bus of items that aren't being used. New items will not be requested if there are enough in the warehouse. The reason why the sushi bus isn't a real loop is because it made the logic much simpler if all unused items just get dumped in the warehouse.

Input Expansion
DSC External Input Expansion v1_10.jpg
DSC External Input Expansion v1_10.jpg (119.13 KiB) Viewed 5065 times
A tile-able blueprint for adding more external item inputs. Like for the factory segment, the wired belts already have the correct settings, just set the item on the left side of the enable condition. Be sure to check if the wire is connected.

Circuit
Dynamic Sushi Controller v1_10.jpg
Dynamic Sushi Controller v1_10.jpg (278.87 KiB) Viewed 5065 times
The circuit has a throughput meter, cycle progress bar, and labels for the settings and what connects to where.

"C" is the cycle time in ticks. I recommend at least 1200 ticks (20 seconds). This constant combinator is also the on/off switch for the circuit.

There needs to be at least one of every item on the bus for the circuit to detect if those items get taken, so the circuit will periodically request one of every item from the warehouse as a sample. The "or equal to zero" part of the item source enable condition is how samples of items that aren't in the warehouse are added. The cycle time is the time between each request for more samples, as well as the time between updating the proportions to use, progressing the moving average of what was taken, and clearing a few memory cells.

If factory intermediates don't have buffer chests, then the circuit seems to forget about the demand needed to make those intermediates unless a cycle is at least as long as it takes for an item to travel all the way around a bus, including the middle section. Using a bigger value for "S" might also work, as it kind of has the effect of multiplying cycle time.

"I" is the total number of items to be requested per cycle. It can at most be the items per second of the bus * cycle time in seconds ("C" / 60 converts from ticks to seconds). For a two belt sushi bus where "C" = 1200, "I" can at most be 600 for normal belts, 1200 for fast belts, and 1800 for express belts.

Instead of controlling the amount of space on the bus used for each item, the circuit controls the amount of throughput used for each item. The total throughput is set as items per cycle, and the circuit scales the average number of items taken (plus the defaults) so that the total equals "I". This result is then gradually revealed 1/128th at a time as the cycle progresses to avoid flooding the bus. The circuit requests one of each item at the start of every cycle, so this setting also limits how precise the proportions can be. For example: if "I" = 100, and there are two different items to control, then the proportion can at most be ~99:1.

Control over supply isn't precise, so the total items added to the bus often exceeds "I". The total excess is subtracted from "I" for the next cycle to avoid the bus getting backed up. Or rather, the next next cycle, since timing restrictions mean it can't take effect immediately. The error correction repeatedly falls behind, then catches up over six cycles due to the way it's set up. This is interesting to watch as the bus looks like it's backing up, but then clears out, then backs up again, almost like the factory is breathing (or maybe I've spent way too much time thinking about this thing).

"S" is the smoothing factor for the moving average. Must be negative. It's not really necessary to change this from the default (-3). Setting to -1 will disable the moving average without breaking the circuit.

The moving average circuit is based on vanatteveldt's design, but modified to progress once every cycle. Instead of directly using the items taken during the last cycle as the proportions of the next, a moving average of items taken is used so changes in supply are less drastic. This is beneficial when supply points are far apart as the bus can temporarily back up if the proportions change too quickly, though I think this is more of an aesthetic issue.

There is a constant combinator where you can set what the proportions should default to when the factory is idle. It's not at all necessary to set these, it's just a way to offset the latency problem this design has. It's basically artificial demand. Only use positive numbers.

Want a bit of everything in equal amounts? Set a 1 for every item. Want twice as much iron as copper? Make the iron value twice as big as the copper value. The values for each item can be whatever you want, but the greater the total is, the less it can deviate from these proportions. This doesn't work perfectly if you set default proportions for factory intermediates as it'll bounce between producing those intermediates and being idle until there are enough items to fill the bus.

Integer overflow is a thing, so here is a formula for figuring out if your chosen settings are safe to use:

Code: Select all

|S * I * 128| + (Sum of defaults) < 2,147,483,648
Example of the core idea
Change log
Last edited by farcast on Fri Jan 15, 2021 4:29 am, edited 4 times in total.
Efficient inefficient design.

farcast
Long Handed Inserter
Long Handed Inserter
Posts: 86
Joined: Fri Jul 06, 2018 8:25 am
Contact:

Re: Dynamic Sushi Controller

Post by farcast »

I finally completed the No Spoon achievement, and I used a sushi factory to do it!
No Spoon Sushi.jpg
No Spoon Sushi.jpg (161.59 KiB) Viewed 6161 times
More Pictures
I did some calculations to figure out if it was even possible before I started.
Thanks to Kirk McDonald for providing a wonderful calculator.

Starting conditions:

Two red belt sushi bus, no modules except four production 3 modules in the rocket silo.
furnace products, green circuits, gears, sulfur, and rocket fuel produced outside the sushi factory.
copper wire produced and used on site, pulling copper plates from the bus.
fluids transported with pipes.
Everything else that uses items pulls those items from the bus.

Results:

red, green, & blue science
130 Science Per Minute

+ purple or yellow science
39 SPM

+ purple and yellow science
23 SPM

minimum time to build a rocket after the silo is built
23 minutes

I knew from testing that SPM can get within 5% of predicted values... given enough time, and as long as demand doesn't change too much. I thought it should still be possible despite this, and I was right!
Efficient inefficient design.

Post Reply

Return to “Combinator Creations”