Circuit Network: Filter Signal

Post all other topics which do not belong to any other category.
Megatron
Inserter
Inserter
Posts: 47
Joined: Fri Apr 08, 2016 7:00 pm
Contact:

Circuit Network: Filter Signal

Post by Megatron »

I have more than one signal on a wire, for example 100 iron ore, 200 copper cables, 10 advanced circuits (...). On another I have one item as a selector, say, 1 copper cable. Can I use combinators to extract the amount of copper cables on the first wire without using a combinator for every single type of item?

Image
BlakeMW
Filter Inserter
Filter Inserter
Posts: 954
Joined: Thu Jan 21, 2016 9:29 am
Contact:

Re: Circuit Network: Filter Signal

Post by BlakeMW »

It can be done.
  • Multiply the control signals by 10M:
    Each * 10M: output Each
  • Combine the multiplied control signals with the input signals in a decider combinat that filters out low values:
    Each > 10M: output Each
  • Then you subtract the control signal * 10M:
    Each * -10M: output Each
There are numerous other close variants
Megatron
Inserter
Inserter
Posts: 47
Joined: Fri Apr 08, 2016 7:00 pm
Contact:

Re: Circuit Network: Filter Signal

Post by Megatron »

I has to work with every possible input size.
I found a way but its quirky.

The selector has to have a value of -2147483648.
Split the input into positive and negative signals. Add the selector to both which makes the desired signal flip it's sign. Split them again by sign so the output has all signals but the selected. Now seperately add these outputs with the outputs from the first split multiplied by -1, which sets all non-selected signals to zero. Then filter the outputs again for sign, combine them and multiply by -1. It does of course not work when the input is exacly -2147483648, but imo this shouldnt be a valid signed integer anyway (C++ISO :/ ). Or it might be resolved by treating it as a special case somehow.

Code: Select all

s = (SELECTOR * -2147483648)

ap = SIGNALS > 0
an = SIGNALS < 0

ap = ap + s
an = an + s

bp = ap > 0
bn = an < 0

cp = bp + -ap
cn = bn + -an

dp = cp < 0
dn = cn > 0

RESULT = (dp+dn)*-1
Can be done in 4 ticks. Im not sure if I made a mistake there or if there is a quicker and better solution.
DOSorDIE
Filter Inserter
Filter Inserter
Posts: 255
Joined: Sat Oct 11, 2014 3:43 pm
Contact:

Re: Circuit Network: Filter Signal

Post by DOSorDIE »

Megatron
Inserter
Inserter
Posts: 47
Joined: Fri Apr 08, 2016 7:00 pm
Contact:

Re: Circuit Network: Filter Signal

Post by Megatron »

Thank you. I looked around for a while but couldn't find a post. Yet this has the same problem. It does not work with any amount. In that case only signals which are less than 100k.
Megatron
Inserter
Inserter
Posts: 47
Joined: Fri Apr 08, 2016 7:00 pm
Contact:

Re: Circuit Network: Filter Signal

Post by Megatron »

Here again my solution as resolved ingame. I use Version 0.13.x so I don't have the blueprint mod to store the string.
In fact this does work with more than one selector as well so that several signals can be filtered.

4 ticks for this might a bit slow but it can be pipelined for a throughput of 1 tick.

Image
BlakeMW
Filter Inserter
Filter Inserter
Posts: 954
Joined: Thu Jan 21, 2016 9:29 am
Contact:

Re: Circuit Network: Filter Signal

Post by BlakeMW »

Here's one which uses 3 combinators with a latency of 2 ticks and I believe should work on the maximum spectrum of values.
simpler.jpg
simpler.jpg (73.46 KiB) Viewed 22120 times
  • The green wire combinator is just a filter to remove negative input signals. Each > 0: Output Each
  • Arithmetic: Each * -2147483648, output Each - this converts a control signal of '1' into a maximum negative value
  • Decider: Each < 0: Output Each
The maximum negative control signal is wired to both the input and output side of the decider combinator, this first results in all non-controlled signal being filtered out, and then restores the controlled signals back to their original values (by underflowing - if you don't like to exploit integer underflow it can be done without underflow with a single extra arithmetic combinator, just adding: control signal * 2147483647 + control signal )
blueprint string
Megatron
Inserter
Inserter
Posts: 47
Joined: Fri Apr 08, 2016 7:00 pm
Contact:

Re: Circuit Network: Filter Signal

Post by Megatron »

BlakeMW wrote:Here's one which uses 3 combinators with a latency of 2 ticks and I believe should work on the maximum spectrum of values.
It does, of course, not work with negative values. Thats why I made the second circuit to treat those as well.
Post Reply

Return to “General discussion”