Pick-A-Signal combinator?

Don't know how to use a machine? Looking for efficient setups? Stuck in a mission?
Honktown
Smart Inserter
Smart Inserter
Posts: 1041
Joined: Thu Oct 03, 2019 7:10 am
Contact:

Re: Pick-A-Signal combinator?

Post by Honktown »

Unless I missed something, filtering positive and negative can be done with a single combinator (this might not've been present years ago):
filter_only_positive.png
filter_only_positive.png (983.25 KiB) Viewed 6835 times

I was messing with the combinators, and I came to a horrible conclusion: it's impossible to filter only one signal with only combinators. Combinators can only act on the quantities of signals present with the generic filters, and therefore if two signals have the same quantity, they will never be separable (and make some circuits like least, greatest, etc return sets).

Using stack filter inserters in a square, with containers, you can get one signal (the first signal in the signal list, the greatest quantity and probably least ID number), but there's some very edge cases where it will fail to do things on an exact tick schedule. This still takes putting items in the containers that match what you have on the network, because you can't read filters, only hand contents.

I did find some algebraic terms that were interesting: the sum of all signals on the input (as one output signal), the sum of all other signals that aren't that signal (sum - signal). Combine sum - signal + signal and you have all signals present, and the value of each is the sum of all values on the network.

Edit: rephrasing for clarity, a single circuit that is fixed-time, fixed-space, can never output exactly one signal that could be any signal, only sets.

And I did misinterpret things. Sue me : P
I have mods! I guess!
Link
mrvn
Smart Inserter
Smart Inserter
Posts: 5853
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Re: Pick-A-Signal combinator?

Post by mrvn »

Honktown wrote: ↑Fri Dec 27, 2019 4:59 am Unless I missed something, filtering positive and negative can be done with a single combinator (this might not've been present years ago):
filter_only_positive.png


I was messing with the combinators, and I came to a horrible conclusion: it's impossible to filter only one signal with only combinators. Combinators can only act on the quantities of signals present with the generic filters, and therefore if two signals have the same quantity, they will never be separable (and make some circuits like least, greatest, etc return sets).

Using stack filter inserters in a square, with containers, you can get one signal (the first signal in the signal list, the greatest quantity and probably least ID number), but there's some very edge cases where it will fail to do things on an exact tick schedule. This still takes putting items in the containers that match what you have on the network, because you can't read filters, only hand contents.

I did find some algebraic terms that were interesting: the sum of all signals on the input (as one output signal), the sum of all other signals that aren't that signal (sum - signal). Combine sum - signal + signal and you have all signals present, and the value of each is the sum of all values on the network.

Edit: rephrasing for clarity, a single circuit that is fixed-time, fixed-space, can never output exactly one signal that could be any signal, only sets.

And I did misinterpret things. Sue me : P
you can easily pick a signal by ordering them some way and then checking each in turn. You end up with at least two decider combinator per item checking for = 0 and =! 0. Its just that placing 800 combinators in a modded game to pick a signal is insane.
Honktown
Smart Inserter
Smart Inserter
Posts: 1041
Joined: Thu Oct 03, 2019 7:10 am
Contact:

Re: Pick-A-Signal combinator?

Post by Honktown »

mrvn wrote: ↑Mon Jan 13, 2020 11:30 am you can easily pick a signal by ordering them some way and then checking each in turn. You end up with at least two decider combinator per item checking for = 0 and =! 0. Its just that placing 800 combinators in a modded game to pick a signal is insane.
It's one thing to whittle down the signals to binary outputs, in space or in time. I unfortunately have a background in engineering and some math, and it actually bugs me that technically, two signals with the same value are indistinguishable. You can either sort signals down to that set of equal values, or none, depending on the circuit. I want an actual generic selector circuit damnit. It'd be easy enough to do in lua, just pick the first signal and call it a day, but ugh. There has to be a better way.
I have mods! I guess!
Link
mrvn
Smart Inserter
Smart Inserter
Posts: 5853
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Re: Pick-A-Signal combinator?

Post by mrvn »

Honktown wrote: ↑Mon Jan 13, 2020 4:11 pm
mrvn wrote: ↑Mon Jan 13, 2020 11:30 am you can easily pick a signal by ordering them some way and then checking each in turn. You end up with at least two decider combinator per item checking for = 0 and =! 0. Its just that placing 800 combinators in a modded game to pick a signal is insane.
It's one thing to whittle down the signals to binary outputs, in space or in time. I unfortunately have a background in engineering and some math, and it actually bugs me that technically, two signals with the same value are indistinguishable. You can either sort signals down to that set of equal values, or none, depending on the circuit. I want an actual generic selector circuit damnit. It'd be easy enough to do in lua, just pick the first signal and call it a day, but ugh. There has to be a better way.
Maybe my description was too brief. As said, per signal you need 2 combinators and you chain them together like this:

Code: Select all

coal != 0 => coal -------------------------------
coal == 0 => each -- iron != 0 >= iron ------/
                  \- iron == 0 >= each -----/
In the each branch you check the next signal chaining them all together. Each signal will only be output if all the signals before it where 0, in whatever order you decide to check them. But the number of combinators and maybe more important the signal runtime is insane as the setup takes as many ticks as you have items.

If you want one signal that has the highest count that makes it even more complex. I would probably make a max finder first and then the above signal separator.

But yeah, there has to be a better way. The combinator solution is just unusable and the inserter thing is annoying with many items.
User avatar
Optera
Smart Inserter
Smart Inserter
Posts: 2920
Joined: Sat Jun 11, 2016 6:41 am
Contact:

Re: Pick-A-Signal combinator?

Post by Optera »

Could you explain how my filter posted here: viewtopic.php?p=447487#p447487 doesn't work for you.
Any signal set to 1 on the cc between the poles will pass through anything else will blocked.
Honktown
Smart Inserter
Smart Inserter
Posts: 1041
Joined: Thu Oct 03, 2019 7:10 am
Contact:

Re: Pick-A-Signal combinator?

Post by Honktown »

@optera

I'm just bitching about not having something absolutely perfect and generic i.e. no settings. disentius used your circuit I think. dunno about mrvn
I have mods! I guess!
Link
mrvn
Smart Inserter
Smart Inserter
Posts: 5853
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Re: Pick-A-Signal combinator?

Post by mrvn »

I'm still waiting or a pick-a-signal combinator. ONE signal.

Other ideas for a red/green aware combinator would be "each / each" and partitioning. I think "/" is self explanatory but partitioning not so. What I mean there is a combinator that has some input and splits the signals into two or more sets. For each set you could then choose the output. For example the combinator could be set to "each > 0". That then produces two sets, things > 0 and things <= 0. The outut could be set to "each green" and "each red" respectively.

Sounds like simply 2 decider combinators? Well, yes, for "each > 0" it is. But it could have a "pick-one" mode where one signal is separated from the rest. Or more general "pick-N" that separates N signals (second argument) and the rest. This would allow you to program a series of filter inserters with 5 different items each.

Other operations could be "max", "min", "average (above and below average)", "split (50/50 split)". I bet there are more.
Honktown
Smart Inserter
Smart Inserter
Posts: 1041
Joined: Thu Oct 03, 2019 7:10 am
Contact:

Re: Pick-A-Signal combinator?

Post by Honktown »

mrvn wrote: ↑Wed Jan 15, 2020 1:36 pm ...
Above/below average is doable already: output an input count signal for each input on one combinator (sum). Output one for each input count as different signal (n). Arithmetic combinator sum / n = third signal (average), and then two more combinators, if original signals >= average, and original signals < average. I don't know what you'd want it for (deciding which trains should get more ore by trying to balance inputs?)

Edit: as for pick a signal, a new combinator could be added which just grabs the first signal on each tick... easy to do in lua.

Also, if anyone was good with guis, a single combinator could have radio buttons: first signal, last signal, max, min. It could be simple and for max/min do if next >/< current_max/min then replace. Would output the first signal it ran into that was max/min, and not the set of maxes/mins.
I have mods! I guess!
Link
mrvn
Smart Inserter
Smart Inserter
Posts: 5853
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Re: Pick-A-Signal combinator?

Post by mrvn »

Honktown wrote: ↑Wed Jan 15, 2020 11:50 pm
mrvn wrote: ↑Wed Jan 15, 2020 1:36 pm ...
Above/below average is doable already: output an input count signal for each input on one combinator (sum). Output one for each input count as different signal (n). Arithmetic combinator sum / n = third signal (average), and then two more combinators, if original signals >= average, and original signals < average. I don't know what you'd want it for (deciding which trains should get more ore by trying to balance inputs?)

Edit: as for pick a signal, a new combinator could be added which just grabs the first signal on each tick... easy to do in lua.

Also, if anyone was good with guis, a single combinator could have radio buttons: first signal, last signal, max, min. It could be simple and for max/min do if next >/< current_max/min then replace. Would output the first signal it ran into that was max/min, and not the set of maxes/mins.
I know average can be done. Provided your sum doesn't overflow. So not reliable but usually good enough. It's just an example what could be added in the new combinator besides just pick-a-signal.

As for "easy to do in lua": It's easy but also horribly slow. Having just a bunch of those lua combinators will kill your UPS. That's the whole reason for the request.
fgcapo
Burner Inserter
Burner Inserter
Posts: 5
Joined: Fri Jun 21, 2019 2:13 am
Contact:

Re: Pick-A-Signal combinator?

Post by fgcapo »

Optera wrote: ↑Fri Aug 02, 2019 6:37 am I know I'm a bit late to the party. Here's the whitelist filter for positive signals I've been using for a year.
It uses integer overflow to filter signals.
Hi Optera, your whitelist filter is awesome! I'm definitely going to use it to index my memory cells. Could you explain what the multiply is for? I think I got it working without it.

whitelist_filter.png
whitelist_filter.png (866.24 KiB) Viewed 6358 times
User avatar
Optera
Smart Inserter
Smart Inserter
Posts: 2920
Joined: Sat Jun 11, 2016 6:41 am
Contact:

Re: Pick-A-Signal combinator?

Post by Optera »

fgcapo wrote: ↑Thu May 14, 2020 1:10 am Hi Optera, your whitelist filter is awesome! I'm definitely going to use it to index my memory cells. Could you explain what the multiply is for? I think I got it working without it.
My design for positive numbers only needs it to subtract the +1 from filters from the end result.
As far as I see you managed to optimize that combinator away. A quick test showed no over or underflow glitches with your design.
Now I feel blind for not seeing this much simpler design.
If the filter is static, your design you could easily remove the 2nd arithmetic combinator doing left shift 31 as well.

How would your design look for filtering positive and negative signals?
fgcapo
Burner Inserter
Burner Inserter
Posts: 5
Joined: Fri Jun 21, 2019 2:13 am
Contact:

Re: Pick-A-Signal combinator?

Post by fgcapo »

Optera wrote: ↑Thu May 14, 2020 4:55 am How would your design look for filtering positive and negative signals?
Whew, it took me a couple days to understand it well enough, but it is possible to do in fewer combinators!

doublefilter.png
doublefilter.png (692.97 KiB) Viewed 6315 times
This design doesn't require overflow--just a number that is larger in magnitude than any potential input, to selectively flip the sign of inputs without needing EACH * EACH. The number I'm using is 2^31 - 1, which is the largest positive integer in Factorio for anyone unfamiliar.

As you said, you could remove the arithmetic combinators if you are willing to store the positive and negative constants in constant combinators. I have no need to preserve negative numbers at the moment, as I only wanted a way to select an index--what do you use it for?

Also thanks again, because I can't imagine I would have come with this method without seeing your design.

User avatar
Optera
Smart Inserter
Smart Inserter
Posts: 2920
Joined: Sat Jun 11, 2016 6:41 am
Contact:

Re: Pick-A-Signal combinator?

Post by Optera »

Nice, that looks so deceptively simple.
I normally use only the positive whitelist filter as well. Filtering positive and negative signals was a challenge posed by this thread.

Did you notice both our designs have overflow errors in the negative filter path?
stone input of -2147483648 only outputs -2147483647, easy test is to hook a cc with -1 to the output pole, stone should overflow to +2147483647
fgcapo
Burner Inserter
Burner Inserter
Posts: 5
Joined: Fri Jun 21, 2019 2:13 am
Contact:

Re: Pick-A-Signal combinator?

Post by fgcapo »

Optera wrote: ↑Sun May 17, 2020 5:29 am Did you notice both our designs have overflow errors in the negative filter path?
stone input of -2147483648 only outputs -2147483647, easy test is to hook a cc with -1 to the output pole, stone should overflow to +2147483647
Heh, my approach cannot handle -2147483648, because there is no positive 32-bit integer you can add to it to make it non-negative. I suspect you could handle it specially through a separate signal path, but I would caution everyone against trying to do arithmetic on numbers over 2^30 anyway because of the chance of overflow.
RedshiftOTF
Manual Inserter
Manual Inserter
Posts: 3
Joined: Mon May 07, 2018 6:57 pm
Contact:

Re: Pick-A-Signal combinator?

Post by RedshiftOTF »

Unless I'm missing a trick here, and if you are happy with only positive outputs, you can do this with 2 combinators and an electric pole.
Factorio_filter01.jpg
Factorio_filter01.jpg (188.14 KiB) Viewed 6180 times
The left combinator contains item inputs with amounts. The right combinator contains item(s) you want filter with the amount set to a large negative number, (I used -1,000,000 but you could use any number). Both combinators go into a power pole and then to a decider combinator set to Each < 0 output Each (item count). The output of this goes into an arithmetic combinator set to Each + 1,000,000 output Each, (which just adds back the negative number your filter was set at) and the output will be your filter item with the correct amount.

Edit: I just realised you don't need the electric pole XD. Just connect both outputs of the combinators into the input of the first combinator.
User avatar
Optera
Smart Inserter
Smart Inserter
Posts: 2920
Joined: Sat Jun 11, 2016 6:41 am
Contact:

Re: Pick-A-Signal combinator?

Post by Optera »

RedshiftOTF wrote: ↑Sat May 30, 2020 8:41 pm Unless I'm missing a trick here, and if you are happy with only positive outputs, you can do this with 2 combinators and an electric pole.

Factorio_filter01.jpg

The left combinator contains item inputs with amounts. The right combinator contains item(s) you want filter with the amount set to a large negative number, (I used -1,000,000 but you could use any number). Both combinators go into a power pole and then to a decider combinator set to Each < 0 output Each (item count). The output of this goes into an arithmetic combinator set to Each + 1,000,000 output Each, (which just adds back the negative number your filter was set at) and the output will be your filter item with the correct amount.

Edit: I just realised you don't need the electric pole XD. Just connect both outputs of the combinators into the input of the first combinator.
That's basically fgcapo and my design with two major shortcomings:
1) no filter against negative signals
2) has to be supplied with the negative number for filtering

With a static cc already containing -2^31 like yours, fgcapo's can be reduced to 2 combinators including an input filter.
RedshiftOTF
Manual Inserter
Manual Inserter
Posts: 3
Joined: Mon May 07, 2018 6:57 pm
Contact:

Re: Pick-A-Signal combinator?

Post by RedshiftOTF »

Optera wrote: ↑Sun May 31, 2020 4:50 am
That's basically fgcapo and my design with two major shortcomings:
1) no filter against negative signals
2) has to be supplied with the negative number for filtering

With a static cc already containing -2^31 like yours, fgcapo's can be reduced to 2 combinators including an input filter.
Ah I see, thanks for the explanation. I guess I was searching for something super basic, couldn't find it, and so made my own but yours and fgcapo's designs are more efficient for sure. :)
BloodyRain2k
Burner Inserter
Burner Inserter
Posts: 18
Joined: Sun Jul 01, 2018 5:55 pm
Contact:

Re: Pick-A-Signal combinator?

Post by BloodyRain2k »

And here I was about to suggest a filter gate that just works like the CC just with in and out and only signals that are selected in it (like in a filter inserter) are allowed through, or removed when set to blacklisting mode instead (optional).

Edit: I've made my own version of Redshift's build which basically just sacrifices one signal to use for the multiplier and is used to multiply all filter signals once by it to get them to the negative threshold and afterwards substract it from the result.

Blueprint:

Code: Select all

0eNrNls2OmzAQx1+lmmMFVfhoI6Ge9wV6rFbIwCQZCWxkhrQo4t07Nm033TgJWe2hHBC2Z/6e8c9jc4KqHbG3pBmKE1Bt9ADF9xMMtNeqdX089QgFEGMHEWjVuZayxIcOmeq4Nl1FWrGxMEdAusGfUCRzdFejwZoatGGBdIWAC5aV5rBCFlQ4kuVRev6KLBbx05lnPj9HgJqJCZfV8I2p1GNXoZXsbuUQQW8GcTXaTStycfLpcwST+5A5GrJYL6Np5FJga9qywoM6kniLy2/NUsYarzO43h3ZgcvV+aCqDy6lP2sExcY1ul5ZH2UBX8XHjNyPb1LtJ4lv1FzurOlK0iIDBdsR52VSvSTpQ0/cy2JzvpTULPmTrUfipTk/i2/qjPcWUb82z/41T8R8doxfwUnvbNLrfDar8Lyovg+hAZ1MebfgmNoW7RSzsnuZXe9ji51hdBqmR8Hqo4aPb+Z6DV2QRv5CK4A2Wccqe5TV5rFS+t9Zxe/OKsDCH2dBhsllAYYo5TdP3EtGoWLKw4B21DLalVfOrVX1h5Hsi3Tjn4cuoh/GNGcayUOX0GBaauLdiG1QIlt1j/WyJ2JjMSixVNpK2JeH5BX2aahCxdiHVpz9FkTQqkqyK+CbT+PDk2cm/Uch5+Fut1mSpPmXLNvO8y+6a9kn
Image
mika89
Burner Inserter
Burner Inserter
Posts: 10
Joined: Tue Nov 26, 2019 7:18 pm
Contact:

Re: Pick-A-Signal combinator?

Post by mika89 »

to come back to the original problem, i created this "pick a signal" monstrosity:

Code: Select all

0eNrdWtGOqzYQ/Rc/trCKDYQQtZW26uvty31rdRURMmStgolss7rpKh/QD+mP9UtqwyZxiEkMSTdXXWlXAuzDjM94zozZN7QsathwyiSavyGaVUyg+e9vSNA1Swt9T243gOaISiiRh1ha6quUU/lSgqSZn1XlkrJUVhztPETZCr6iOd55VzFWkNEVcDsA2X3xEDBJJYXWouZiu2B1uQSu3nAJx0ObSqipFdNv1/bEE/wUeWiL5j5JEvWeFeWQtSNCDym/Ja+KxRJe0leqENS0d9yFerZqsIS+m1Mu5OLMtVfKZa3uHKxqR/iQZi/aLQEaxn3ez3qS8miT8sajOfpRjalqualHvD2rNlvlR83kIudVuaBMwaC55DXsmseMtYvRuIj1Hw4rc9mpuiJqJOVZTWV7qTk2H+PdFwVG9Ow1B2Dd+dPT+Xr4zsDYM0uuRJmNXHJKro3OI9htjH4eQ+eznlRtQJHZ2I38EWyqmBjAVtBlS20oKy3x2cA9ixZU7MZhMILD4Bvn8FOXw+dffxnB4vMgFmNXFmdDWCRuLIZH2+ulkK3fNuriPXEzd8/wlXSC415fcdhjcHQwGAplAldBBwz4eusrgQOepxnY7McT0/5lnecq7Qv6pwLCk8OP5X3TEWFu6FDspEP3CvqOFGmpl6nW/cbH09D+brTY9MW2nchBqWdyFrV98eEY3/HQGiI45e4/rxqOHE061cBPIwj6PLIUsK9x4F4NXFenfi7PqPQupb0+pme31RTxB+qRsS9vLxk+DdyQ/bWAdXjgtvrJiNU/SMr0KTpNk+RBabKTIr8fQcdvg7T/XCEvs6EV07r+OnOObpaij2+WzqTpJPX989ffD2+Fpq5lWVOqXNA0C8VWBvENUhU9Vqp+uD9beVqIQZ3rxIkgJ6HrS3L4xr41+jaKQR8/pBKcDqkEw26rMLlciySODI7pWsPr++wDOHtcBY+HaVTsSMWx9dy7eY2I6ZGI8KmPipwWqg90O+IUAsplQdnaL9W6UAY+aVNSrdc8jAYddrI6KyDlfl5DYaAEB5DQAUTIioExm5DD9KnDdMor5mcvIKSBgTWD7yCxA0ieCunXajxfc4Ww8pdQmHhRdDRq5oAHXzcchLgEeQRMmugaHZz4St7oPu/mGeKq1pFBWZr94VMmgKvAswburBu4pgrY0Kc2Rq8gRwrZhhV3LG03yGWDk1PYE4On9n23X7WyWsGiyhdGpjI4EqB+tRnvhy+6KPNawxZ71KYCGFZxO5cJYW+VkDgSPxtAPJ64ZKz9aw/K0dy8cC4wLH0nfZ4kjkFmehHtvXCqyYjzcc6s70vBZLBKGI1N4NhY3k8zfDxIM0SZFkqU9yeZm6oAOxgZm/wNjGC8iBkoY1TMmB715ndb7+T4LYLgwVESPDJK7hkk5PYYCe8RIrObIkQr3qgIcc0wjlUpIbccZAWOWvk/aPFsXCTX+uy+jzokGFJNJZe2rg6AJtTmxv89eOhVbdx2wAyHcULiIImVsgW73b8W+DhZ
blueprint contains small proof of concept with a stack filter inserter (you have to fill the chests to your liking).

conditions to use: limited to about 20 different signals. you have to prepare two constant combinators: one for creating a bitmask representing your signals, and one with all the signals set to -1.

idea:
1) encode signals to bits
2) create a bitmask representing all positive signals (=S)
3) find an arbitrary bit that is set (here: the lowest one, =B)
4) decode bit to signal
5) recover original value of signal

maybe you'll have ideas for simplifications or find bugs :)
Qon
Smart Inserter
Smart Inserter
Posts: 2164
Joined: Thu Mar 17, 2016 6:27 am
Contact:

Re: Pick-A-Signal combinator?

Post by Qon »

mika89 wrote: ↑Mon Jun 28, 2021 2:55 pm to come back to the original problem, i created this "pick a signal" monstrosity:

maybe you'll have ideas for simplifications
Screenshot 2021-06-28 at 18-07-55 Screenshot from 2021-06-28 18-04-20 (copy) png (PNG Image, 1920 Γ— 1080 pixels) β€” Scaled ([...].png
Screenshot 2021-06-28 at 18-07-55 Screenshot from 2021-06-28 18-04-20 (copy) png (PNG Image, 1920 Γ— 1080 pixels) β€” Scaled ([...].png (41.1 KiB) Viewed 5586 times
Old topic is dead.
My mods: Capsule Ammo | HandyHands - Automatic handcrafting | ChunkyChunks - Configurable Gridlines
Some other creations: Combinassembly Language GitHub w instructions and link to run it in your browser | 0~drain Laser
Post Reply

Return to β€œGameplay Help”