Basic trend analysis

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.
Gauraus
Manual Inserter
Manual Inserter
Posts: 1
Joined: Sun Nov 26, 2017 8:01 am
Contact:

Basic trend analysis

Post by Gauraus »

This is a small experiment I came up with to help me learn more about using combinators, if you guys can provide some critique, suggestions to make it better, or let me know if this has already been done better that would be awesome.

The goal was to use basic trend analysis to detect when a resource is depleting by more than X percent over a given time frame and take action until that reserves of that resource are growing by more than X percent again over the same time frame.

Example: coal being buffered on the way to the steam boilers. I want 2 chests to act as a main buffer (intermediaries between the supply and demand lines with no flow control) and another two to act as backup buffers (they will pull from the supply line, but only contribute to the demand line when needed). So 2 chests act as a backup if my coal supply runs low - they will contribute to the demand line output when the main buffer contents drops by more than 10% over a 10 second time frame. They will continue to contribute to the demand line until the main buffer builds up by more than 10% over the given time frame. This way, when the supply starts to drop, the backup buffers kick in to compensate, and keep doing so until the supply is able to fill the main buffer enough to be self-sufficient again.
Example Scenario
image
This follows the common smart loading standard - the combinators and wires are mostly for that, except the red wire going from the left of the screen to the top two fast inserters (which are part of this build). The top two chests are the backup buffers, the botton two chests are main buffers - they will always supply the output line while then can. When the total coal in the main buffer drops by more than 10% in 10 seconds, I want the backup buffers to kick in and start supplying the demand line, and continue to do so until the total coal in the main buffer increases by more than 10% in 10 seconds.

I'll break this out into stages..
Stage 1
image
The constant combinator provides the initial tick for the counter. The first decider combinator turns that into a 10 second counter and passes it on.

At this point it's important to clarify what the B and C signals represent.
  • B = baseline
    C = current
This is what happens every 10 second cycle. The top set of combinators do the same thing as the bottom set - the top set are for the C signal and the bottom set are for the B signal.

1 tick before the 10 second counter finishes (T = 599):
  • 1. B = 0 (to prevent the new value of C being added to B)
    2. B += C
When the 10 second counter cycles (T = 0):
  • 1. C = 0 to prevent the new value of C being added to C)
    2. C += current count of coal ore
This results in C being given current amount of ore every 10 seconds and B being given the previous value of C (baseline) every 10 seconds. It is then simple to compare the current value to the baseline value to see whether the amount of ore increased, stayed the same, or decreased. The light will glow green if it increased, blue if it stayed the same, or red if it decreased.

Increase:
image
Decrease:
image
Blueprint:
blueprint
To test this stage:
  • 1. The light will start off blue, as there are no B or C values stored
    2. Set coal to 100 on the constant combinator
    3. The C-C combinator will show a C=100 signal and the light will turn green (as this an increase)
    4. After another 10 second cycle, the B-B combinator will show 100 - now the baseline and current are the same, to the light will turn blue
    5. Decrease the coal to 99 on the constant combinator - the C-C combinator will show C=99 and the B-B combinator will still show B=100 (for another cycle) - the light will turn red
    6. Increase the coal to 100 on the constant combinator - the C-C combinator will show C=100 and the B-B combinator will still show B=99 for another cycle) - the light will turn green
    7. Do nothing - the C-C combinator will show C=100 and the B-B combinator will update to the value of the previous cycle (B=100) - the light will turn blue
Stage 2
image
Turning this into percentage increase/decrease is not difficult, just a few more combinators. The arithmetic combinators calculate the difference between B and C and turn the difference into a percentage, and the decider checks whether that percentage is more than 10% - outputting a red/green signal if so.

We have two additional lights - the top light will glow green if the increase was more than 10%, the middle light behaves the same as in stage 1, the bottom light will glow red if the decrease was more than 10%.

>10% Increase:
image
>10% Decrease:
image
Blueprint:
blueprint
To test this stage (from where we left off from stage 1):
  • 1. Increase the coal to 110 on the constant combinator - the C-C combinator will show C=110 and the B-B combinator will still show B=100 (for another cycle) and the middle light will turn green (to signify an increase) but the top the bottom lights will stay off (as the increase/decrease was not by more than 10%)
    2. Decrease the coal to 100 again on the constant combinator - the C-C combinator will show C=100 and the B-B combinator will still show B=110 (for another cycle) and the middle light will turn red (to signify a decrease) but the top the bottom lights will stay off (as the increase/decrease was not by more than 10%)
    3. Increase the coal to 111 on the constant combinator - the C-C combinator will show C=111 and the B-B combinator will still show B=100 (for another cycle), the middle light will turn green (to signify an increase), and the top light will turn green to signify that the increase was by more than 10%
    4. Decrease the coal to 100 again on the constant combinator - the C-C combinator will show C=100 and the B-B combinator will still show B=111 (for another cycle) and the middle light will turn red (to signify a decrease), and the bottom light will turn turn red to signify that the decrease was by more than 10%
Stage 3
All that's left really is to use the percentage increase/decrease signals implemented in stage 2 to control the fast inserters that take from the hard buffer chests and output to the demand line. Once the red signal that represents a 10% decrease in the soft buffers triggers, the fast inserters will drain the hard buffer until the green signal that represents a 10% increase in the soft buffers triggers. This compensates for the period between when supply starts to suffer significantly to the point where it has recovered enough to (hopefully) remain self-sufficient.

Example scenario:
image
>10% decrease in soft buffers:
image
>10% increase in soft buffers:
image
A simple latch off of the red/green signals does the job - it will set (start the backup buffer inserters) when the >10% decrease red signal fires, and reset (stop the backup buffer inserters) when the >10% green signal fires. Note that this only affects the fast inserters that empty the backup buffers to the demand line. All buffers will continue to fill from the supply line regardless. It is important (at least in this example) to use stack inserters to fill the buffer chests from the supply line, so that they can outpace the fast inserters that output to the demand line to allow the buffers to fill. Otherwise the rate of increase/decrease may fluctuate continuously. As long as the inserters filling the buffer chests can outpace those taking items from it, once supply comes back up the backup buffer chests will fill up faster than the main buffer chests (as the demand line inserters will stop pulling from them), so they should be ready to buy us some time when we forget to send enough coal down the supply line again.

Blueprint:
blueprint
To test this stage (from where we left off from stage 2):
  • 1. Repeat the same steps and note that the fast inserters that output from the backup buffers to the demand line kick in when the main buffers decrease by more than 10% in a 10 second cycle, and stop when the main buffers increase by more than 10% in a 10 second cycle.
Disclaimer: This was purely a creative mode contraption - who knows how useful it actually is in game.

Cheerio!
Post Reply

Return to “Combinator Creations”