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 (983.25 KiB) Viewed 5714 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.
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.
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.
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:
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.
Re: Pick-A-Signal combinator?
Posted: Mon Jan 13, 2020 6:44 pm
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.
Re: Pick-A-Signal combinator?
Posted: Tue Jan 14, 2020 5:55 am
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
Re: Pick-A-Signal combinator?
Posted: Wed Jan 15, 2020 1:36 pm
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.
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.
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.
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 (866.24 KiB) Viewed 5237 times
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?
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 (692.97 KiB) Viewed 5194 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.
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
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.
Re: Pick-A-Signal combinator?
Posted: Sat May 30, 2020 8:41 pm
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 (188.14 KiB) Viewed 5059 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.
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.
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.
Re: Pick-A-Signal combinator?
Posted: Mon Jun 01, 2020 10:08 am
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 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