Pick-A-Signal combinator?

Don't know how to use a machine? Looking for efficient setups? Stuck in a mission?
gridstop
Inserter
Inserter
Posts: 47
Joined: Sun Jul 17, 2016 1:46 am
Contact:

Pick-A-Signal combinator?

Post by gridstop »

Has anyone seen, or have ideas for a combinator contraption that can choose a signal (any single signal) out of a wire that has multiple signals on it?

For example, input is 10 stone, 5 copper, 1 electric engine. I need it to pick one (doesn't even matter which one) and output it, so I get for example 5 copper out. Essentially I need it to work the way a stack filter inserter will, in that it will select one of the items in as its filter, ignoring the others. Speed is also critical. The fewer ticks the better. The input amounts are unknown, but not more than a few thousand (It wouldn't be hard to filter them down to value 1, and then combine the output back up to the original amounts, so assume 1 in and any positive/negative out is fine).

So far I've been able to filter down up to 32 pre-selected signals in a parallel/tree structure in about 10-11 ticks. (8 rows, each filters 4 items sequentially, and then we filter the pairs of rows and then between those). If I need to I can parallel the whole thing for 64 signals and only cost me 2-3 more ticks to combine them. Thankfully I only need to build one of these since that's pretty big.

It would be nice if it could be done using values programmed into a constant combinator, but that would invariably involve loops of one kind or another, which would be way too slow at 32+ ticks to loop over a similar number of items. I got partway through something like this (program each item into constant combinators, at sequential values, and then loop a sum value that gets added into them and then each one goes negative or positive in turn, use that to filter the original input values), before I gave up due to its speed.

It seems like it would be hilariously easy in a mod (just look at the input signals, which I assume is a list of some kind, and pick the first one) but that's cheating!
User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3716
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: Pick-A-Signal combinator?

Post by DaveMcW »

There is a long-standing development suggestion to use the existing interface to make this possible. viewtopic.php?t=28946


But let's work with what we have now.

Tick 1: Pick the earliest signal, and cancel everything else. Each decider combinator is backed by a set of constant combinators.
A > 0 β†’ Everything, B = -1000000, C = -1000000, D = -1000000, E = -1000000
B > 0 β†’ Everything, C = -1000000, D = -1000000, E = -1000000
C > 0 β†’ Everything, D = -1000000, E = -1000000
D > 0 β†’ Everything, E = -1000000
E > 0 β†’ Everything

Tick 2: Remove the negative numbers
Each > 0 β†’ Each
gridstop
Inserter
Inserter
Posts: 47
Joined: Sun Jul 17, 2016 1:46 am
Contact:

Re: Pick-A-Signal combinator?

Post by gridstop »

Thanks! Might have to work on a python library for generating blueprint strings though for how complicated repetitive setting up all those constant combinators would be.
reallyLost
Inserter
Inserter
Posts: 39
Joined: Wed Apr 20, 2016 2:12 pm
Contact:

Re: Pick-A-Signal combinator?

Post by reallyLost »

So, ignoring your performance constraints :D , I designed a solution for fun, as long as none of your signals are negative (but I do have an idea to improve performance - see my last paragraph). This is a looping design that uses an alphabet of unique values for each possible input. The alphabet must also, in this design, be negative.

Essentially, this circuit loads the alphabet into an accumulator and then once each tick it adds 1 to each value for every input signal present. Signals that are not present on the input do not get incremented. It repeats this addition every tick until one of the signals goes positive. That is designated as the selected signal. Up until this point the actual values of the input signals are not used (except to check if they are non-zero of course). Then a separate circuit takes the selected signal and extracts the value from the original input. If your purpose is to program some filter inserters, then you can skip that second part (on the right in the pic below) since the values aren't needed. All you need to do to use this circuit is program the alphabet with each possible input signal that you need to handle. Here is a screenshot with some example values:


Image

Here is the blueprint string if you'd like to try it.

Performance-wise, it might, in the worst case loop over all the values in the alphabet before finding the selection. If you have a very large alphabet and this is too slow, then it might be possible to speed it up by filtering the input using another circuit I have which can select the largest signal from a set. That circuit doesn't discriminate between identical signals though so if the highest value is shared by multiple signals then they will all appear on the output. But, as I said, you would use it to pre-filter for the above circuit (well, actually you would use it to filter the alphabet, not the input). It would help with the speed because its complexity is O(log(n)) wrt to the number of signals in the actual input, rather that the above which is O(n) wrt to the alphabet. Although, the filter process itself would also take a few ticks, so overall it might not save enough to help much.
Last edited by reallyLost on Sat Apr 01, 2017 11:33 pm, edited 3 times in total.
Manron
Inserter
Inserter
Posts: 39
Joined: Mon Apr 11, 2016 5:21 pm
Contact:

Re: Pick-A-Signal combinator?

Post by Manron »

Well, i dont exactly know what you are trying to achieve, but if it comes down to unloading chests or train cars, you may want to consider using a filter inserter and one or several stack filter inserters in a master-slave configuration.

the filter inserter is hooked to the main wire and set to 'set filter' and 'read hand contents' (cant remember the exact names, not in game atm, you sure get what i mean), the stack filter inserters connect to the filter inserter by a different coloured wire and are set to 'set filters'. that way the filter inserter will grab any of items available physically and on the wire, and the stack filter ones will pick up exactly the same.

calculation speed is one tick only and there's no combinators involved.
gridstop
Inserter
Inserter
Posts: 47
Joined: Sun Jul 17, 2016 1:46 am
Contact:

Re: Pick-A-Signal combinator?

Post by gridstop »

reallyLost wrote:So, ignoring your performance constraints :D , I designed a solution for fun, as long as none of your signals are negative (but I do have an idea to improve performance - see my last paragraph). This is a looping design that uses an alphabet of unique values for each possible input. The alphabet must also, in this design, be negative.

Essentially, this circuit loads the alphabet into an accumulator and then once each tick it adds 1 to each value for every input signal present. Signals that are not present on the input do not get incremented. It repeats this addition every tick until one of the signals goes positive. That is designated as the selected signal. Up until this point the actual values of the input signals are not used (except to check if they are non-zero of course). Then a separate circuit takes the selected signal and extracts the value from the original input. If your purpose is to program some filter inserters, then you can skip that second part (on the right in the pic below) since the values aren't needed. All you need to do to use this circuit is program the alphabet with each possible input signal that you need to handle. Here is a screenshot with some example values:


Image

Here is the blueprint string if you'd like to try it.

Performance-wise, it might, in the worst case loop over all the values in the alphabet before finding the selection. If you have a very large alphabet and this is too slow, then it might be possible to speed it up by filtering the input using another circuit I have which can select the largest signal from a set. That circuit doesn't discriminate between identical signals though so if the highest value is shared by multiple signals then they will all appear on the output. But, as I said, you would use it to pre-filter for the above circuit (well, actually you would use it to filter the alphabet, not the input). It would help with the speed because its complexity is O(log(n)) wrt to the number of signals in the actual input, rather that the above which is O(n) wrt to the alphabet. Although, the filter process itself would also take a few ticks, so overall it might not save enough to help much.
That's really cool. I started to look at something along those lines, but not nearly that efficient. It seemed like it would still be too slow for what I was doing. Now that the blueprint strings are easier to deal with and built into the game I'll probably look at a script to generate Dave's setup automatically.
XKnight
Filter Inserter
Filter Inserter
Posts: 329
Joined: Thu May 28, 2015 10:40 pm
Contact:

Re: Pick-A-Signal combinator?

Post by XKnight »

gridstop wrote:Has anyone seen, or have ideas for a combinator contraption that can choose a signal (any single signal) out of a wire that has multiple signals on it?

For example, input is 10 stone, 5 copper, 1 electric engine. I need it to pick one (doesn't even matter which one) and output it, so I get for example 5 copper out. Essentially I need it to work the way a stack filter inserter will, in that it will select one of the items in as its filter, ignoring the others. Speed is also critical. The fewer ticks the better. The input amounts are unknown, but not more than a few thousand (It wouldn't be hard to filter them down to value 1, and then combine the output back up to the original amounts, so assume 1 in and any positive/negative out is fine).
Here is my attempt to solve this task:

This build allows to get signal with lowest ID (and its value) among 31 registered signals in 5 ticks.
If you don't need original values you can remove last combinator.
If you need more than 31 signal you can run several similar things in parallel and combine their results in the same way.

Image

Do not forget to propagate input signal to the end of this build, otherwise output will be desynchronized with input.
Blueprint
P.S. can someone move this topic into "Combinator Creations" ?

Update: build was simplified a little bit.
Serenity
Smart Inserter
Smart Inserter
Posts: 1017
Joined: Fri Apr 15, 2016 6:16 am
Contact:

Re: Pick-A-Signal combinator?

Post by Serenity »

ARG! I hoped there would be an easy way to do it. It's hard to believe how arcane the circuit network is :(
Dimanper
Inserter
Inserter
Posts: 47
Joined: Sat Sep 17, 2016 9:50 am
Contact:

Re: Pick-A-Signal combinator?

Post by Dimanper »

Hi, gridstop.
I probably misunderstood something, but as far as i see it, the problem doesn't really seem that hard, and can be implemented with 3-5 combinators, 1 tick delay from main input and 2-4 delay from control input. I don't like explaining circuit stuff in writing, as it is not that easy to show what does what and what goes where, so just check this blueprint in game:
Pick-A-Signal
System will output everything from main input that has its value != 0 in control signal. Possible values in main signal: 0 - (2^31 - 1). You can change possible range of values to any range with (2^31 - |lowest negative number in range|) values in it. So if you plan to use negative numbers >= -2^29 and positive numbers <= (2^31 - 2^29 - 1), you need to change 0 to -2^29 in top and right decider combinators and change -2^31 to -(2^31 - 2^29) in right arithmetic combinator. If you want to use larger range of values, you need to tweak this system furthermore. Also, you can lower (4 tick delay from control signal + pick every != 0) to (3 tick delay + pick every = 1) or (2 tick delay + pick every = -1) by removing 1 or 2 left combinators respectively.
Last edited by Dimanper on Mon May 08, 2017 4:08 pm, edited 1 time in total.
User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3716
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: Pick-A-Signal combinator?

Post by DaveMcW »

Dimanper wrote:I probably missunderstood something
Yes, it is supposed to pick exactly 1 signal. ;)
Bortos
Burner Inserter
Burner Inserter
Posts: 18
Joined: Sun Aug 28, 2016 11:07 am
Contact:

Re: Pick-A-Signal combinator?

Post by Bortos »

gridstop wrote:Has anyone seen, or have ideas for a combinator contraption that can choose a signal (any single signal) out of a wire that has multiple signals on it?

For example, input is 10 stone, 5 copper, 1 electric engine. I need it to pick one (doesn't even matter which one) and output it, so I get for example 5 copper out. Essentially I need it to work the way a stack filter inserter will, in that it will select one of the items in as its filter, ignoring the others. Speed is also critical. The fewer ticks the better. The input amounts are unknown, but not more than a few thousand (It wouldn't be hard to filter them down to value 1, and then combine the output back up to the original amounts, so assume 1 in and any positive/negative out is fine).
I tackled a similar problems trying to get a signal 'separated' into its components by using a filter inserter and some memory cells. It definitely doesn't suit your situation though if speed is an issue, but figured I would share anyway



More info: viewtopic.php?f=18&t=44332

Ideally I was hoping for an in indexing operator, or item-wise bit operations to be added in .15, but no luck.
Dimanper
Inserter
Inserter
Posts: 47
Joined: Sat Sep 17, 2016 9:50 am
Contact:

Re: Pick-A-Signal combinator?

Post by Dimanper »

DaveMcW wrote:
Dimanper wrote:I probably missunderstood something
Yes, it is supposed to pick exactly 1 signal. ;)
Is it supposed to pick it on some kind of condition? If not, then in my system you can choose whatever you want to pass through it from the main signal with sending required signal != 0 via control signal. Let's say you have iron(10), copper(20), coal(30) in main signal, you send copper(1) and you get copper(20) as output, send iron(-4213), copper(4) and get iron(10) and copper(20).
Sorry, but if that doesn't do it, then i really can't get what this Pick-A-Signal system is supposed to do.
Serenity
Smart Inserter
Smart Inserter
Posts: 1017
Joined: Fri Apr 15, 2016 6:16 am
Contact:

Re: Pick-A-Signal combinator?

Post by Serenity »

Dimanper wrote: I probably misunderstood something, but as far as i see it, the problem doesn't really seem that hard, and can be implemented with 3-5 combinators, 1 tick delay from main input and 2-4 delay from control input. I don't like explaining circuit stuff in writing, as it is not that easy to show what does what and what goes where, so just check this blueprint in game:
Great. That works as I expected it to :)
nubjub
Burner Inserter
Burner Inserter
Posts: 6
Joined: Sat May 13, 2017 1:57 pm
Contact:

Re: Pick-A-Signal combinator?

Post by nubjub »

This topic was discussed here as well: viewtopic.php?t=28946
Perhaps that's the more correct description. Circuit that takes everything as input signal and outputs anything.
siggboy wrote:You can do the "for-loop" filtering right now, but it's too difficult, and it takes an unknown number of ticks (in the general case).
Does anyone have a working implementation of what siggboy is describing?

I'd really like to have a look at reallyLost's solution, it sounds like it could be adapted to work perfectly for my current problem, but for some reason the blueprint fails to import.
reallyLost wrote:Image

Here is the blueprint string if you'd like to try it.
I'm still trying to get my head around XKnight's solution, but there appears to be a small bug. Input signals with values < the value associated with the selected constant, (output by the each = red combinator) output from the final combinator with values of 2.1G. So for the iron chest as you set it up input signal values < 3, if it were the blue belt it'd be values < 127.
XKnight wrote: Image
Blueprint
This is something I'd very much like a general solution for, and I don't really care how many cycles it takes.
nubjub
Burner Inserter
Burner Inserter
Posts: 6
Joined: Sat May 13, 2017 1:57 pm
Contact:

Re: Pick-A-Signal combinator?

Post by nubjub »

nubjub wrote:I'm still trying to get my head around XKnight's solution, but there appears to be a small bug. Input signals with values < the value associated with the selected constant, (output by the each = red combinator) output from the final combinator with values of 2.1G. So for the iron chest as you set it up input signal values < 3, if it were the blue belt it'd be values < 127.
I realized that Dimanper's solution to not quite the problem is a working alternative to the final step in XKnight's solution that doesn't exhibit the bug I described. Then I realized that Dimanper's solution has a different minor bug: For the first two ticks all of the positive input signals are on the output. Easily solved with a couple of dummy combinators to get the timing right.
Pick-A-Signal XKnight+Dimanper.jpg
Pick-A-Signal XKnight+Dimanper.jpg (160.29 KiB) Viewed 19670 times
blueprint XKnight+Dimanper
mrvn
Smart Inserter
Smart Inserter
Posts: 5860
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Re: Pick-A-Signal combinator?

Post by mrvn »

DaveMcW wrote:There is a long-standing development suggestion to use the existing interface to make this possible. viewtopic.php?t=28946


But let's work with what we have now.

Tick 1: Pick the earliest signal, and cancel everything else. Each decider combinator is backed by a set of constant combinators.
A > 0 β†’ Everything, B = -1000000, C = -1000000, D = -1000000, E = -1000000
B > 0 β†’ Everything, C = -1000000, D = -1000000, E = -1000000
C > 0 β†’ Everything, D = -1000000, E = -1000000
D > 0 β†’ Everything, E = -1000000
E > 0 β†’ Everything

Tick 2: Remove the negative numbers
Each > 0 β†’ Each
This is a really fast solution, assuming you only want positive signals. For me that is the case but I have 40+ signals to select from. So a single constant combinator can't even provide all the constants. I'm trying to think of ways to re-use a single constant combinator for multiple entries. Like in the above example E=-1000000 occurs in A-D and could be one constant combinator. Then A-C only has to get the additional constants. Having just 2 wire colors makes this tricky though.
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 »

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.

2019-08-02-08-35-59-1351794.png
2019-08-02-08-35-59-1351794.png (75.49 KiB) Viewed 15007 times

  • It let's any positive signals set to 1 in the cc pass and blocks everything else.
  • Delay and combinator count are constant regardless of the number of signals input and filtered.
  • the filter cc can easily be replaced with deciders to cycle filtered signals.


Here's a version able to filter positive and negative signals by duplicating the filter path.

2019-08-02-08-56-06-4815136.png
2019-08-02-08-56-06-4815136.png (91.35 KiB) Viewed 15002 times
Last edited by Optera on Sat Apr 11, 2020 4:37 pm, edited 1 time in total.
User avatar
disentius
Filter Inserter
Filter Inserter
Posts: 694
Joined: Fri May 12, 2017 3:17 pm
Contact:

Re: Pick-A-Signal combinator?

Post by disentius »

OOO thaks!
Just what I need.
mrvn
Smart Inserter
Smart Inserter
Posts: 5860
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Re: Pick-A-Signal combinator?

Post by mrvn »

mrvn wrote: ↑Mon Aug 14, 2017 1:05 pm
DaveMcW wrote:There is a long-standing development suggestion to use the existing interface to make this possible. viewtopic.php?t=28946


But let's work with what we have now.

Tick 1: Pick the earliest signal, and cancel everything else. Each decider combinator is backed by a set of constant combinators.
A > 0 β†’ Everything, B = -1000000, C = -1000000, D = -1000000, E = -1000000
B > 0 β†’ Everything, C = -1000000, D = -1000000, E = -1000000
C > 0 β†’ Everything, D = -1000000, E = -1000000
D > 0 β†’ Everything, E = -1000000
E > 0 β†’ Everything

Tick 2: Remove the negative numbers
Each > 0 β†’ Each
This is a really fast solution, assuming you only want positive signals. For me that is the case but I have 40+ signals to select from. So a single constant combinator can't even provide all the constants. I'm trying to think of ways to re-use a single constant combinator for multiple entries. Like in the above example E=-1000000 occurs in A-D and could be one constant combinator. Then A-C only has to get the additional constants. Having just 2 wire colors makes this tricky though.
It also only works for numbers lower than 1000000. You can easily change it to work with -1000000 to 1000000 by using "A > -1000000" and "B = -2000000".

Next, if you don't mind the time you can first pick one from group of 8 signals. Then pick one from the resulting 5 signals. Doubles the time to 4 ticks.

Otherwise you need to use arithmetic combinators "each + 0 = each" to isolate signals when you share constant combinators. You need one arithmetic combinator per shared constant combinator per decider combinator.
gridstop
Inserter
Inserter
Posts: 47
Joined: Sun Jul 17, 2016 1:46 am
Contact:

Re: Pick-A-Signal combinator?

Post by gridstop »

mrvn,

Because the sum of all the negative values doesn't change, you can accumulate that statically alongside the deciders. So in my setup there was a column of constant combinators and arithmetics,each one adding the negative value of the item for that row, and then the decider checking for > 0 of the same item. So the whole things works in one tic, is fairly easy to blueprint and copy, and just set he constant & decider for each item in the same row.

Positives:
Works in two ticks (all the signal deciders are in parallel & final decider checking > 0)
Prioritizes (items at the end where all the constant negative values accumulate are highest priority)

Downsides:
Gets very long in one direction
Have to manually add every signal
Values are limited by the negative value (also some risk of negative overflow if multiple input signals are present)
Hard to re-prioritize since 'making room' is difficult
Post Reply

Return to β€œGameplay Help”