Resource counting with combinators

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.
golfmiketango
Filter Inserter
Filter Inserter
Posts: 549
Joined: Fri Jan 29, 2016 2:48 am
Contact:

Re: Resource counting with combinators

Post by golfmiketango »

JasonC wrote:
golfmiketango wrote:Anyone got an idea for how to output a single tick of output when a signal goes from 0->1, and stay quiet until we go back to zero and then back to one, again, with a single combinator?
You can do this with one combinator if you don't mind having to use both red and green for the output with the implicit summing. It's combinator A from the OP. Consider the following crappy ASCII art:

Code: Select all

     /-------------------------\
     |                         |
     |  +-------------------+  |
IN---o->R                   |  \----->R
        | each * -1 => each |
        |                   G-------->G
        +-------------------+
The sum of R+G on the right will always be the change in the input in the last tick. So for your case, when IN goes from 0->1, the R+G will momentarily be 1. When IN goes from 1->0, R+G will momentarily be -1. So if you can make your circuit work with this logic, you can use it as an edge detector. For example, if you attach both red and green to a lamp, and set the lamp to anything > 0, then the lamp will flash for 1 tick when IN increases (i.e. 0->1) but not when it stays the same or decreases:

Code: Select all

     /-------------------------\
     |                         |
     |  +-------------------+  |      +--------------------+
IN---o->R                   |  \----->R                    |
        | each * -1 => each |         |   lamp, any > 0    |
        |                   G-------->G                    |
        +-------------------+         +--------------------+
If you set the lamp to any < 0, it'll flash on the falling edge instead. (Unfortunately you can't really get both edges at once with this circuit since there's no not-equal operator in circuit conditions).

Note that this combinator doesn't behave exactly as you describe, since it outputs a value on both 0->1 and 1->0, but by using >0 on the next element in the series, you filter out the 1->0 case and effectively achieve what you're going for. Still, it's not quite perfect, if you're running the output to e.g. a counter you might not get what you want. But it's the closest you can get with just one combinator as long as your receiver can filter with a condition (otherwise you have no choice but to run it through a >0 decider, thus using two combinators).

In general, though, just remember that since the game implicitly sums red + green on inputs, you basically get a free combinator-less addition that can sometimes help you.

Hope that helps.
I guess it doesn't help to count a resource flowing through with a single combinator per chest. But, what you've shown is perfect when what you want to do, instead, or in addition, is to keep a running total of the quantity buffered inside the chests. Also, it's potentially quite convenient that if we chain them like:

[ first order derivative combinator ] -> [ high-pass filter combinator ]

(in other words, exactly as pictured in combinators "A" and "B" of your OP), I can accomplish both by wire-summing signals from the middle of the chain into a "buffered storage count accumulator" and wire-summing signals from the filtered end into an "in-flow count accumulator" (like combinator "C" in OP). If I were buffering meaningful quantities rather than working with just one item at a time, (i.e.: a similar device that pulled from chests rather than belts and thus expected an unpredictable number of items to wind up in the chests), I could then calculate exact cumulative throughput by taking the difference, which is pretty sexy. However for purposes of my "belt counter" thingy, it's probably acceptable to ignore buffering.
golfmiketango
Filter Inserter
Filter Inserter
Posts: 549
Joined: Fri Jan 29, 2016 2:48 am
Contact:

Re: Resource counting with combinators

Post by golfmiketango »

golfmiketango wrote:
JasonC wrote:
You can do this with one combinator if you don't mind having to use both red and green for the output with the implicit summing. It's combinator A from the OP. Consider the following crappy ASCII art:

Code: Select all

     /-------------------------\
     |                         |
     |  +-------------------+  |
IN---o->R                   |  \----->R
        | each * -1 => each |
        |                   G-------->G
        +-------------------+
[It's perfect for] wire-summing signals ... into a "buffered storage count accumulator"
Well maybe not perfect since we can't chain together the red wires feeding into a bunch of these without mixing them up. What we could do, however, is, i.e., run green wires to the chests, and chain them together with all the green wires coming out of the ascii-art accumulators.
kann_
Inserter
Inserter
Posts: 44
Joined: Fri Apr 15, 2016 4:36 pm
Contact:

Re: Resource counting with combinators

Post by kann_ »

golfmiketango wrote:I am sure we can't sum the chests. Items are flowing into and out of those chests, one-at-a-time, due to conditions I placed on the smart inserters. The smart inserters putting items into the chest act only if the chest is empty. The smart inserters taking items out act only if the chest contains one or more items.
You didn't read my guide correctly. I never said to sum up all the chests. I suggested to count each chest on a different resource and use one combinator to store all of those signals. If you post the last edition of you problem as blueprint string I can show you what I mean.

Actually there are even more ways... best is probably to activate all input inserters if all chests are empty and activate all output inserters when all chests are full. Than you can actually just sum up all chests.

wire all chests with input of arithmetic combinator sum/#chests=iron, this will be 1 if all chests have one iron otherwise 0.
wire (same color) combinator output to every input and output inserter.
wire (different color) every chest with every input and output inserter.
input inserter rule: iron=0
output inserter rule: iron=2 *might not work due to inserter timing, in that case it will get a little more difficoult

To count you just wire the combiantor output to one of those incrementor memory cells and multiply by chest number. Probably also works by just wiring the chest directly to the incrementor memory cell without multiplying
golfmiketango
Filter Inserter
Filter Inserter
Posts: 549
Joined: Fri Jan 29, 2016 2:48 am
Contact:

Re: Resource counting with combinators

Post by golfmiketango »

kann_ wrote:
golfmiketango wrote:I am sure we can't sum the chests. Items are flowing into and out of those chests, one-at-a-time, due to conditions I placed on the smart inserters. The smart inserters putting items into the chest act only if the chest is empty. The smart inserters taking items out act only if the chest contains one or more items.
You didn't read my guide correctly. I never said to sum up all the chests. I suggested to count each chest on a different resource and use one combinator to store all of those signals. If you post the last edition of you problem as blueprint string I can show you what I mean.
Yeah, I had a feeling I might not have understood you entirely. But I don't see much utility separating the resources when we can capture them all at once with "each"... maybe I still don't understand you. A blueprint will be coming eventually, but for now, I have some real-life stuff I gotta do first -- I'm sure this goes without saying, but feel free to just ignore me and post your own design.
kann_ wrote: Actually there are even more ways... best is probably to activate all input inserters if all chests are empty and activate all output inserters when all chests are full. Than you can actually just sum up all chests.
I would like a counter to introduce minimal side-effects when only a very few resources are flowing in, all the way down to just a single item, so I don't think that'd work for my purposes. If anything, I'd like the production version of the device to separate and preserve belt-sides. In fact, ideally, it would even have all the distances from the input to the smart inserters to the output be exactly equal, such that items emerge, as nearly as possible, in the exact configuration they arrive in, although I am not sure what kind of fidelity is practically possible in that regard and fear I'll wind up futzing around with it forever if I get too picky about it.
golfmiketango
Filter Inserter
Filter Inserter
Posts: 549
Joined: Fri Jan 29, 2016 2:48 am
Contact:

Re: Resource counting with combinators

Post by golfmiketango »

FFF #138 is must-read material for anyone interested in this counting biz!
User avatar
siggboy
Filter Inserter
Filter Inserter
Posts: 988
Joined: Tue Mar 29, 2016 11:47 am
Contact:

Re: Resource counting with combinators

Post by siggboy »

golfmiketango wrote:Anyone got an idea for how to output a single tick of output when a signal goes from 0->1, and stay quiet until we go back to zero and then back to one, again, with a single combinator? Then I can eliminate a whole row of combinators. But, otherwise, I plan just use OP's two-combinator design and de-specialize the whole apparatus to not depend on item-type.
I'm sure this is impossible, for the following reason:

What you want is an edge detector for a rising signal. So there's the temporal component (signal changing from one tick to the next), which you can only isolate by delaying the signal. This requires 1 combinator.
Then you need to compare this delayed signal (from 1 tick in the past) to the present signal (to detect the change and, optionally, to distinguish rising from falling edges). This requires another combinator. It can never be the combinator that you used to delay the signal, because you can't delay a signal with an operation and use the same operation to compare the past version to the present version, because the delay has not happened yet.

If we did have an "oracle" combinator that can view 1 tick into the future it might be possible, however :). Or we'd need a combinator that can do more than one operation during the same tick.

Regarding your counter contraption:

1. You do not need smart inserters on both ends. It's enough if you have smart inserters removing the items (each connected to the chest in front of it), and configure it to only act when the chest is not empty (otherwise the loading inserter might skip the chest and hand the item directly over to the unloading inserter, and then the item won't be counted).
2. You do not need that many chests/inserters to count a blue belt. 20 inserters/chests is already more than enough.
3. Your layout can be more compact.

Here's my version (I've tested it, it's count-perfect). There are 22 chests in this version, so you can remove one column, 20 inserters/chests is enough for one blue belt -- well 20 FAST inserters is enough, the smart inserters are a bit slower, so probably 22 chests is the correct number or otherwise some backlog might be building up in the chest, albeit very slowly.

Oh, and by the way, this will be entirely moot in 0.13 because we'll be able to count belt contents directly :).
counter.PNG
counter.PNG (1.87 MiB) Viewed 28297 times
Here's the blueprint:

Code: Select all

H4sIAAAAAAAA/+Vd247bNhD9lcCPrR3wphsK90eCYuHYSiLAlg1ZLrJY7L/XkhatRUqjM2QKe7Vv2ZijGZ65kBwOyd3x0/643ew/Pa1f8rIu6iI/r19eys0h
Xy92+bbY5dVqezx8LcpNfawWy9PxfG10LNcvP9erZPm8XqWfo9fl9liW+bb54Ur+ZSEXf61fqnx3/VT71eenYrdWarktqu2lqJu/5Ovr8nuV5yXRRr1eG31Z
qMGv2Q1bIXbFmwxvsq9fvhXVuX46F9/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
u1Kkv1KQM1r9RrRSDKUU5zszVkqATpDja1mG6yShdOJ8Z8Y6Eb46gU7hWY1onUSUTpyRacY68R7loTN9ViNaJx/JFbzHcegMp9WIhj2mXMGZD7xDnbwui20r
7UtR7vJmaCDzPlcEunZqSSUXr9/9o8rrS1V+evojL3f/AN6EzvL8lQAA
Is your railroad worrying you? Doctor T-Junction recommends: Smart, dynamic train deliveries with combinator Magick
User avatar
siggboy
Filter Inserter
Filter Inserter
Posts: 988
Joined: Tue Mar 29, 2016 11:47 am
Contact:

Re: Resource counting with combinators

Post by siggboy »

kann_ wrote: wire all chests with input of arithmetic combinator sum/#chests=iron, this will be 1 if all chests have one iron otherwise 0.
wire (same color) combinator output to every input and output inserter.
wire (different color) every chest with every input and output inserter.
input inserter rule: iron=0
output inserter rule: iron=2 *might not work due to inserter timing, in that case it will get a little more difficoult
I don't see this working at all, for several reasons (I've tried something similar briefly).

If both inserters are active at the same time, the item won't even land in the chest. One inserter will simply hand the item right into the next, as if the chest wasn't even there.

Also, how do you ensure that ALL inserters put an item into ALL of the chests at the same time? The item flow in on a belt, they don't get dropped with a helicopter onto all inserters simultaneously. The chests will not fill evenly -- but that needs to be the case, otherwise your counting algorithm will be completely wrong (you divide by chest count).

If I understand you correctly, what you're trying to do is activate all inserters along the belt at the same time, but only if all chests are empty, so you can pretend there's always the same amount of items in all chests, and that way you can just divide the sum by the number of chests and get a count per chest. The problem is that you pretend that there's a full belt of items in front of all inserters, so they can all grab an item, and then the belt will fill up again for the next round.

So this already requires that you fill the belt before you start the contraption, and even then it will stop working right at the moment when the input belt is not 100% compressed -- because your inserters need to remove items EXACTLY as fast as the belt brings them (if they're too slow the belt will clog up, if they're too fast you won't be filling the chests evenly any longer).

Now, if everything is perfectly synchronized, then you don't need a counter at all, because I can tell you that 22 smart inserters are required and the item count will be exactly 2400 items per minute :).
Is your railroad worrying you? Doctor T-Junction recommends: Smart, dynamic train deliveries with combinator Magick
User avatar
siggboy
Filter Inserter
Filter Inserter
Posts: 988
Joined: Tue Mar 29, 2016 11:47 am
Contact:

Re: Resource counting with combinators

Post by siggboy »

golfmiketango wrote: keep a running total of the quantity buffered inside the chests.
What do you mean by "running total"? You get the total count of items in all chests by summing up the chests... ie. connect all of them with wire. No combinator required.
Also, it's potentially quite convenient that if we chain them like:

[ first order derivative combinator ] -> [ high-pass filter combinator ]

(in other words, exactly as pictured in combinators "A" and "B" of your OP), I can accomplish both by wire-summing signals from the middle of the chain into a "buffered storage count accumulator"
The "buffered storage count accumulator" will contain the total number of items in all chests. Which is what you get by simply connecting all chests with wire (see above).
and wire-summing signals from the filtered end into an "in-flow count accumulator" (like combinator "C" in OP). If I were buffering meaningful quantities rather than working with just one item at a time, (i.e.: a similar device that pulled from chests rather than belts and thus expected an unpredictable number of items to wind up in the chests), I could then calculate exact cumulative throughput by taking the difference, which is pretty sexy. However for purposes of my "belt counter" thingy, it's probably acceptable to ignore buffering.
"Throughput" is a velocity, it only makes sense if you measure it "per time unit" (e.g. per second/minute/...). What do you mean by "cumulative throughput"? The throughput across all chests?

I think you got carried away a little and now you don't see the forest anymore for all the trees.
Is your railroad worrying you? Doctor T-Junction recommends: Smart, dynamic train deliveries with combinator Magick
User avatar
siggboy
Filter Inserter
Filter Inserter
Posts: 988
Joined: Tue Mar 29, 2016 11:47 am
Contact:

Re: Resource counting with combinators

Post by siggboy »

JasonC wrote:
golfmiketango wrote:Anyone got an idea for how to output a single tick of output when a signal goes from 0->1, and stay quiet until we go back to zero and then back to one, again, with a single combinator?
You can do this with one combinator if you don't mind having to use both red and green for the output with the implicit summing. It's combinator A from the OP. Consider the following crappy
I love the simple edge detector (your version), but "implicit summing" by putting R+G together is cheating :). In order to take the implicit sum you need another combinator, making it a two-combinator solution.

(I'm sure that you know this as you were alluding to it in your post.)

Sadly, it's often not possible to put R+G together and use the wire-sum technique, because you need the edge signal on a single wire, or you need to have it already filtered (only rising or falling edge). But some day I'll find a way to use this nice edge detector and I'll be able to save one combinator, yay :).
Is your railroad worrying you? Doctor T-Junction recommends: Smart, dynamic train deliveries with combinator Magick
User avatar
siggboy
Filter Inserter
Filter Inserter
Posts: 988
Joined: Tue Mar 29, 2016 11:47 am
Contact:

Re: Resource counting with combinators

Post by siggboy »

Alright, I'm taking another stab at this, before moving on :). It's fun after all.

So I've made another circuit that actually calculates the Throughput through the buffer chests (instead of simply integrating over what gets added, which is kind of useless without any point of reference).
accumulator.PNG
accumulator.PNG (203.09 KiB) Viewed 28275 times
The combinators do the following (going from the lower left to the upper left):

1 - (lower left) A clock/counter that increments a value every tick
2 and 3 - Clock divider; We multiply by 2^25 and then check for negativity - the result is a signal that oscillates between 0 and 1 with a period of exactly 128 ticks (about 2 seconds)
4 - This is an accumulator (integrator) that is active while the clock signal is 0; so it will integrate over the amount of items added to the chests for exactly 64 ticks, then reset to 0 for another 64 ticks, then starts integrating again etc.

Technically we already have our result (throughput per 64 ticks), the other circuits are just to hold this value so you can look at it (or update a nixie tube or something).

The middle column pulses out the result from the integrator just before it resets (after the full cycle of 64 ticks), the right combinator is a register that holds the value for the other 64 ticks (while the integrator is accumulating data).

As a result you get the throughput of the belt over the last 64 ticks, held for another 64 ticks, then it updates again.

Done.

(64 ticks = 1,07 seconds).

I get around 41-43 items/1.07 seconds on a compressed belt. When I disconnect half of the input the value drops to around 20.

Pretty much what is expected from a compressed blue belt (40 items/second).

One last remark: Of course it would be TRIVIAL to calculate the throughput per TICK (it's what the array of buffer chests pulses out every tick). Unfortunately this value is less than 1 on average, so what's displayed would not make much sense (1 tick is not long enough, the signal is smeared by aliasing effects).

Blueprint:

Code: Select all

H4sIAAAAAAAA/8WWYY6bMBCFrxL5Z2uqAElaaeuTrFbItSfJSGAjY3YXody9E0hbyEIgKNX+C2HmYb7neUbbVWqVTFeJqMF49AiFqGsjMxBMg0INLlA2+4VG
eusYz21BRdaI+l0E8bctr0QQnbhGB6r5P+LKGtNekNQzC9mLqB1okm2eUCWoRcgVOlWiP19Qf+fWj9OJHxyA6TVs+g1U88yiSeVwUCu6KqEiWrPGy5Ivry3q
PbrCJwUejExF7aucmLyi86VMGW8RtTeDCtLUvrFGp/DSeLGmn1ku3ZmaYIJxW/q8nKcGr+Aqf0RzaBTzKlG2ND7ZO5slaEhGMO9KYOeVX7ySDv0xA49q3K71
Yruu6Q9ADecaFN+m/+9FFhlQwFnsqgc9ZH8a0FkTWEfwuM2B/DlTYF9GDBru7HCfmpFoMfNofETiaTt2D7JjwTDQEz5zEuamVjhtyUes27lYrzNmamLCnsG7
h5siTYfjoDM/73Kmk3iDruxlWtwdUK0z664xu1mz8n3MlomD5FHxA1Idu2TjeLvdbOJoTsTcUlwW8It29ugB+7H0/yb4X4hhl15wF70mghZtvhnsZm++m4X9
gd9+AtKviwa+QzUDjWUWQEqEHKHNbQp9qOuW6N1fhA0BehCqpqVGo+GdSm65SctqyyI+ehCQ5pMDXzqzSp7A6N+hxFAr/woAAA==
Is your railroad worrying you? Doctor T-Junction recommends: Smart, dynamic train deliveries with combinator Magick
XKnight
Filter Inserter
Filter Inserter
Posts: 329
Joined: Thu May 28, 2015 10:40 pm
Contact:

Re: Resource counting with combinators

Post by XKnight »

kann_ wrote:One combinator per chest should be enough. Each combinators should have a different output "resource". Then you can store all chest values on one storage cell instead of one per chest. Then you can use Each>0 = Resource(input count) to sum all the different signals.
kann_ wrote: Actually there are even more ways... best is probably to activate all input inserters if all chests are empty and activate all output inserters when all chests are full. Than you can actually just sum up all chests.
Perhaps no one actually understand these messages, so I am going to show them on the real case:

Different item types per chest (1 combinator per chest + 2)
1.png
1.png (331.71 KiB) Viewed 8917 times
Blueprint
Chests summarizing (0 combinator per chest + 4). This is actually useful for counting inexpensive items like plates, green circuits, etc.
Because this build transfers 9 items simultaneously and 8 items will have to wait for the ninth.
2.png
2.png (345.1 KiB) Viewed 8917 times
Blueprint
kann_ wrote: wire all chests with input of arithmetic combinator sum/#chests=iron, this will be 1 if all chests have one iron otherwise 0.
wire (same color) combinator output to every input and output inserter.
wire (different color) every chest with every input and output inserter.
input inserter rule: iron=0
output inserter rule: iron=2 *might not work due to inserter timing, in that case it will get a little more difficoult
Rule "iron = 2" will work only if all output inserters transfer items simultanesouly which is not possible at all.
Breaking example
P.S. These builds were successfully tested with jammed output belts.
User avatar
siggboy
Filter Inserter
Filter Inserter
Posts: 988
Joined: Tue Mar 29, 2016 11:47 am
Contact:

Re: Resource counting with combinators

Post by siggboy »

XKnight wrote:Perhaps no one actually understand these messages, so I am going to show them on the real case:
It helped.
Different item types per chest (1 combinator per chest + 2)
This is not going to work anymore (in 0.13):
obsolete.PNG
obsolete.PNG (126.27 KiB) Viewed 8909 times
The decider combinator will get changed and it won't be possible anymore to add up different input signals in this fashion. Actually it is probably not going to be possible anymore, at all (unless you do it manually with lots of dummy combinators for recoloring).

A good change, if you ask me, the current behaviour makes no sense (it's useful in this case, though). Actually I was wondering where you could abuse the current behaviour of the decider, this is actually a good example.

Maybe something important should be mentioned about the first implementation: the smart inserters don't look into the chests themselves, they take the input from the combinator that does the counting. That way, the information (count) from the chest is delayed by 1 tick, and this avoids the problem that the input inserter will drop the item right into the hand of the output inserter, instead of into the chest.

This little quirk is actually what makes the setup work at all.

But I like the second implementation a lot better anyway (chest counting in batches of 9 items).

It's a little slow, though. In my tests even 22 inserters could not manage to empty a compressed blue belt. It's probably not so great for counting very high volume belts.
Chests summarizing (0 combinator per chest + 4). This is actually useful for counting inexpensive items like plates, green circuits, etc.
Because this build transfers 9 items simultaneously and 8 items will have to wait for the ninth.
You can also be hard to understand, sometimes :).

I really like this way. I did not understand how kann_ was supposed to synchronize the inserters.

The various combinators delaying the signal several times, very nice. Very difficult to understand. Almost sad it will be quite useless with version 0.13.

I have to give it to you, XKnight. Every time you post something about combinators, it's really clever, and useful.
Is your railroad worrying you? Doctor T-Junction recommends: Smart, dynamic train deliveries with combinator Magick
XKnight
Filter Inserter
Filter Inserter
Posts: 329
Joined: Thu May 28, 2015 10:40 pm
Contact:

Re: Resource counting with combinators

Post by XKnight »

siggboy wrote: This is not going to work anymore (in 0.13):
Image
Indeed, it is announced that this behaviour will be changed in 0.13, but this doesn't mean new behaviour will be inapplicable...
Personally, I will talk about combinators in 0.13 only after playing with them directly.

Anyway, is is still possible to solve this task with 1.5 combinators per chest using "stable features" + "different item per chest" with arithmetic combinators:
"signal 0 + signal 1 => plate", "signal 2 + signal 3 => plate" ...
User avatar
siggboy
Filter Inserter
Filter Inserter
Posts: 988
Joined: Tue Mar 29, 2016 11:47 am
Contact:

Re: Resource counting with combinators

Post by siggboy »

XKnight wrote:Anyway, is is still possible to solve this task with 1.5 combinators per chest using "stable features" + "different item per chest" with arithmetic combinators:
"signal 0 + signal 1 => plate", "signal 2 + signal 3 => plate" ...
Yeah, sure but it's not nearly as elegant as having 1 combinator add all of them. Setting all the different virtual signals is so tedious, one for each combinator. It's not elegant. It works well but I don't find it aesthetically pleasing. (Same with binary decoder that uses a combinator full of constants. It works, but it's ugly.)

The other solution, where the 9 inserters are synchronized, that's actually amazing, and then only 4 combinators for the entire counting, it's really good. You make a lot of good combinator designs. Please look at my train scheduler and tell me what you think or what you might improve (it's here: viewtopic.php?f=8&t=25311).
Is your railroad worrying you? Doctor T-Junction recommends: Smart, dynamic train deliveries with combinator Magick
golfmiketango
Filter Inserter
Filter Inserter
Posts: 549
Joined: Fri Jan 29, 2016 2:48 am
Contact:

Re: Resource counting with combinators

Post by golfmiketango »

XKnight wrote:
siggboy wrote: This is not going to work anymore (in 0.13):
Image
Indeed, it is announced that this behaviour will be changed in 0.13, but this doesn't mean new behaviour will be inapplicable...
Personally, I will talk about combinators in 0.13 only after playing with them directly.

Anyway, is is still possible to solve this task with 1.5 combinators per chest using "stable features" + "different item per chest" with arithmetic combinators:
"signal 0 + signal 1 => plate", "signal 2 + signal 3 => plate" ...
Yeah, I'm not sure, myself, that I get what they are saying is going to happen... but I've only skimmed through the thread where it's proposed; it seems like the full intent is spelled out pretty clearly there but I'd probably need to sit and scratch my head longer than I have to fully grasp it. Wish I could link to it but I can't find the damn thread anymore... was just reading it yesterday... bah... *throws up hands in frustration*
golfmiketango
Filter Inserter
Filter Inserter
Posts: 549
Joined: Fri Jan 29, 2016 2:48 am
Contact:

Re: Resource counting with combinators

Post by golfmiketango »

siggboy wrote:
golfmiketango wrote:Anyone got an idea for how to output a single tick of output when a signal goes from 0->1, and stay quiet until we go back to zero and then back to one, again, with a single combinator? Then I can eliminate a whole row of combinators. But, otherwise, I plan just use OP's two-combinator design and de-specialize the whole apparatus to not depend on item-type.
I'm sure this is impossible, for the following reason:

What you want is an edge detector for a rising signal. So there's the temporal component (signal changing from one tick to the next), which you can only isolate by delaying the signal. This requires 1 combinator.
Then you need to compare this delayed signal (from 1 tick in the past) to the present signal (to detect the change and, optionally, to distinguish rising from falling edges). This requires another combinator. It can never be the combinator that you used to delay the signal, because you can't delay a signal with an operation and use the same operation to compare the past version to the present version, because the delay has not happened yet.

If we did have an "oracle" combinator that can view 1 tick into the future it might be possible, however :). Or we'd need a combinator that can do more than one operation during the same tick.
Yes, I'm inclined to agree. It's much harder to rigorously prove something can't be done than that it can, but your analysis sounds correct to me.
siggboy wrote: Regarding your counter contraption:

1. You do not need smart inserters on both ends. It's enough if you have smart inserters removing the items (each connected to the chest in front of it), and configure it to only act when the chest is not empty (otherwise the loading inserter might skip the chest and hand the item directly over to the unloading inserter, and then the item won't be counted).
This, and there is the possibility of items going into and out of the chest simultaneously going undetected. It seemed to me that limiting the inserters to act one-at-a-time was by far the most rational starting point. From there, I suppose it might be possible to implement something like you describe but I would be concerned about the inserter-to-inserter handoff situation and other potential complications, like simultaneous addition and subtraction to and from the chest -- the only way to rule those out, imo, would be extensive testing, and not only with saturated belts.

I expected fully, by the way, that this limitation of both inserters would slow down the per-inserter efficiency of the device. In my mind, it should add the duration, whatever it may be in combinator ticks, of one-half-smart-inserter-rotation to the time cost of measuring each object on the belt, hence it's not surprising that...
siggboy wrote: 2. You do not need that many chests/inserters to count a blue belt. 20 inserters/chests is already more than enough.
...I did need that many in my contraption as implemented.
siggboy wrote: 3. Your layout can be more compact.
No doubt. Compactness was not a design objective I gave much thought to.
siggboy wrote:
Here's my version (I've tested it, it's count-perfect). There are 22 chests in this version, so you can remove one column, 20 inserters/chests is enough for one blue belt -- well 20 FAST inserters is enough, the smart inserters are a bit slower, so probably 22 chests is the correct number or otherwise some backlog might be building up in the chest, albeit very slowly.

Oh, and by the way, this will be entirely moot in 0.13 because we'll be able to count belt contents directly :).
Interesting use of a splitter-bus. What inspired you to do it that way? Personally I've made it a habit never to drop items directly into or pull items directly out from splitters as I pretty quickly came to the conclusion that I didn't know what the rules were, but the crap I expected to happen wasn't happening -- but that's just a fancy way of saying I've been too lazy to learn some stuff.
User avatar
siggboy
Filter Inserter
Filter Inserter
Posts: 988
Joined: Tue Mar 29, 2016 11:47 am
Contact:

Re: Resource counting with combinators

Post by siggboy »

golfmiketango wrote:Yeah, I'm not sure, myself, that I get what they are saying is going to happen... but I've only skimmed through the thread where it's proposed; it seems like the full intent is spelled out pretty clearly there but I'd probably need to sit and scratch my head longer than I have to fully grasp it. Wish I could link to it but I can't find the damn thread anymore... was just reading it yesterday... bah... *throws up hands in frustration*
You're talking about this thread: 13706

The two main reasons for the change are:

1. The current user interface is ambiguous, because it doesn't tell you what is meant by "input count". Is it the count of the input to the predicate function? Or is it the count of the signal that you actually want to output? It's also downright confusing, because it will take the count of the output from a different signal than the output itself.

2. While the current behavior allows for obscure solutions like summing a bunch of different signals in a single combinator (as demonstrated by XKnight above), it does not allow a much more common (and arguably more useful) scenario, namely to use the decider as a tri-gate (think of a triggerable "valve"). In version 0.13 this will be very easy: apply "Blue = x" and "Red" to a decider; let ONLY "Blue = x" pass through if and only if "Red = 1"; currently not possible because you can't pass the count from Blue, unless you pass "Everything (input count)", which is what most people do but it's often quite ugly.

Just try to solve the following problem in 0.12: you have a wire with many signals on it (e.g. "A", "B", "C", "D", ...). Extract a single one of these signals from the wire (e.g. "B"), but only if signal "Red" is equal to "0" (i.e. not on the wire). Or in other words: make a filter extracting "B" which can be disabled with "Red = 1".

Not exactly an exotic problem (it comes up all the time when you have a shared message bus), and if you look at the Decider Combinator your first impression will be that it's straightforward, but it's not.

So that was a lengthy explanation of the change, I hope it helps.

It's a good change, but some people are violently against it because it can break some setups.
golfmiketango wrote:It's much harder to rigorously prove something can't be done than that it can
That's not true. Negative proofs are not inherently more difficult than positive ones, it's just a matter of applying the correct proof technique and reasoning.

We don't have the formalism for making actually rigorous proofs about combinators. Your delay problem doesn't really require that, though: you can't compare A to B before B even exists, q.e.d. :)

Negative proofs can never be constructive, i.e. they can never give an example for something that is proven to not exist -- which is probably what makes you think they're more difficult, because you like to think in examples.

But in mathematics, computer science and logic, proofs are usually not made by way of listing examples, so it's really not important if you're trying to prove a positive or negative statement.

Negative proofs are often done as "proof by contradiction": if you want to prove that "S is false", you assume instead that "S" is true, and then show that this leads to a contradiction.
Interesting use of a splitter-bus. What inspired you to do it that way? Personally I've made it a habit never to drop items directly into or pull items directly out from splitters as I pretty quickly came to the conclusion that I didn't know what the rules were, but the crap I expected to happen wasn't happening -- but that's just a fancy way of saying I've been too lazy to learn some stuff.
I got that idea from here: http://imgur.com/a/WytKJ I just love it and always use it when I have to unload from a row of chests onto a belt.

If you insert into the splitters, then your inserters can't clog eachother up, they will always work at maximum speed as long as the belt is not backing up. This is because every splitter is like a mini-buffer for 1 item that drops the item onto the belt (at the exit). If you drop directly onto the belt, there might be an item in the way and your inserter would be delayed for a moment.

The splitter bus is also a lot more compact than the usual way of merging several lanes hierarchically. Which is why I love it for train unloading and I've also started to use it at the exit of a smelting setup (from the buffer chests onto the belt).

I'm not sure if we'll still need that construction with the new rapid inserter that is coming with 0.13. It might be awesome in combination, or not needed anymore at all. We'll see.
Is your railroad worrying you? Doctor T-Junction recommends: Smart, dynamic train deliveries with combinator Magick
JasonC
Filter Inserter
Filter Inserter
Posts: 449
Joined: Tue Mar 22, 2016 3:05 am
Contact:

Re: Resource counting with combinators

Post by JasonC »

@siggboy FYI, not sure if it's useful for you, but if you want more precision with rate calculations one trick I like to do is e.g. multiply the resource count by 1000 (or whatever) before dividing by time, then your output is in thousandths of an item per time (i.e. deal with fractions by doing fixed-point math, since combinators only work with integers). E.g. the rate tests at viewtopic.php?f=18&t=23409#p146781.
Took a break from 0.12.29 to 0.17.79, and then to ... oh god now it's 1.something. I never know what's happening.
JasonC
Filter Inserter
Filter Inserter
Posts: 449
Joined: Tue Mar 22, 2016 3:05 am
Contact:

Re: Resource counting with combinators

Post by JasonC »

golfmiketango wrote:Personally I've made it a habit never to drop items directly into or pull items directly out from splitters as I pretty quickly came to the conclusion that I didn't know what the rules were, but the crap I expected to happen wasn't happening
Prior to 0.12.31 there was a bug when inserting onto splitters which you may have been running into. Since then it makes a lot more sense. See my images here for the way it used to work and the way it works now.

Btw, in a setup like that it is usually overkill to use one splitter per inserter. Often you can get away with small groups of inserters going onto their own belt then using a splitter to merge it into the real belt.

Also, fyi, another good use for inserting onto splitters is to get long inserter distance with fast inserter speed (both to and from the belt), e.g. here.
Took a break from 0.12.29 to 0.17.79, and then to ... oh god now it's 1.something. I never know what's happening.
golfmiketango
Filter Inserter
Filter Inserter
Posts: 549
Joined: Fri Jan 29, 2016 2:48 am
Contact:

Re: Resource counting with combinators

Post by golfmiketango »

siggboy wrote:
golfmiketango wrote:Yeah, I'm not sure, myself, that I get what they are saying is going to happen... but I've only skimmed through the thread where it's proposed; it seems like the full intent is spelled out pretty clearly there but I'd probably need to sit and scratch my head longer than I have to fully grasp it. Wish I could link to it but I can't find the damn thread anymore... was just reading it yesterday... bah... *throws up hands in frustration*
You're talking about this thread: 13706
Ahh, thank you, that was driving me nuts.
siggboy wrote: The two main reasons for the change are:

1. The current user interface is ambiguous, because it doesn't tell you what is meant by "input count". Is it the count of the input to the predicate function? Or is it the count of the signal that you actually want to output? It's also downright confusing, because it will take the count of the output from a different signal than the output itself.

2. While the current behavior allows for obscure solutions like summing a bunch of different signals in a single combinator (as demonstrated by XKnight above), it does not allow a much more common (and arguably more useful) scenario, namely to use the decider as a tri-gate (think of a triggerable "valve"). In version 0.13 this will be very easy: apply "Blue = x" and "Red" to a decider; let ONLY "Blue = x" pass through if and only if "Red = 1"; currently not possible because you can't pass the count from Blue, unless you pass "Everything (input count)", which is what most people do but it's often quite ugly.

Just try to solve the following problem in 0.12: you have a wire with many signals on it (e.g. "A", "B", "C", "D", ...). Extract a single one of these signals from the wire (e.g. "B"), but only if signal "Red" is equal to "0" (i.e. not on the wire). Or in other words: make a filter extracting "B" which can be disabled with "Red = 1".

Not exactly an exotic problem (it comes up all the time when you have a shared message bus), and if you look at the Decider Combinator your first impression will be that it's straightforward, but it's not.

So that was a lengthy explanation of the change, I hope it helps.
Well it definitely helps me understand why the change is made. Not sure I have grokked exactly what is being changed but I think I am probably just being mentally lazy, I get the gist.
siggboy wrote: It's a good change, but some people are violently against it because it can break some setups.
Any change is bound to have a few impassioned detractors. Of course, if their complaint could be fixed by a mod, it's worth considering that those detractors are apparently even more passionate about not implementing a mod, than they are about their original complaint :) I have enough faith in the factorio developers not to do anything hopelessly silly on purpose, to be confident that, once I see it in-game, the old brain-indicator-light will fully illuminate.
siggboy wrote:
golfmiketango wrote:It's much harder to rigorously prove something can't be done than that it can
That's not true. Negative proofs are not inherently more difficult than positive ones, it's just a matter of applying the correct proof technique and reasoning.

[snip!]

Negative proofs can never be constructive, i.e. they can never give an example for something that is proven to not exist -- which is probably what makes you think they're more difficult, because you like to think in examples.

But in mathematics, computer science and logic, proofs are usually not made by way of listing examples, so it's really not important if you're trying to prove a positive or negative statement.

Negative proofs are often done as "proof by contradiction": if you want to prove that "S is false", you assume instead that "S" is true, and then show that this leads to a contradiction.
I think there must be more to it than that. For example, consider the statement "This statement is false", which, if it is false, leads to a contradiction, and therefore, must, by your proposed mechanism, be true. Even if we try to fix the mechanism by saying that, since this statement led to contradiction both ways, it must fall into a third truth category we'll call "nonsensical", we can still construct predicate-logical statements such as "If pigs can fly, then 2+2=4" which don't have this problem, but will cause any quick-and-dirty formulation of proof by contradiction to confirm some extremely counter-intuitive hypotheses.

But, I'll leave it there, as we seem to have stumbled into the very interesting but also very off-topic and confusing areas of scientific methodology and the metaphysics of epistemology, which, most likely, we needn't figure out, entirely, just to play factorio :twisted:
siggboy wrote:
Interesting use of a splitter-bus. What inspired you to do it that way? Personally I've made it a habit never to drop items directly into or pull items directly out from splitters as I pretty quickly came to the conclusion that I didn't know what the rules were, but the crap I expected to happen wasn't happening -- but that's just a fancy way of saying I've been too lazy to learn some stuff.
I got that idea from here: http://imgur.com/a/WytKJ I just love it and always use it when I have to unload from a row of chests onto a belt.

If you insert into the splitters, then your inserters can't clog eachother up, they will always work at maximum speed as long as the belt is not backing up. This is because every splitter is like a mini-buffer for 1 item that drops the item onto the belt (at the exit). If you drop directly onto the belt, there might be an item in the way and your inserter would be delayed for a moment.

The splitter bus is also a lot more compact than the usual way of merging several lanes hierarchically. Which is why I love it for train unloading and I've also started to use it at the exit of a smelting setup (from the buffer chests onto the belt).

I'm not sure if we'll still need that construction with the new rapid inserter that is coming with 0.13. It might be awesome in combination, or not needed anymore at all. We'll see.
Love it. I'm sold. A similar idea I had watching antielitz latest-and-greatest was to use underground belts to try to enable inline inserters to more fully compress a belt. This makes me wonder: how close to fully compressing a belt-side with a single row of inline smart-inserters might one be able to get by cleverly combining both ideas? Actually, re-reading what you've written, it sounds like maybe the splitter-bus alone is enough to do it. I guess there's only one way to find out....
Post Reply

Return to “Combinator Creations”