Page 1 of 1

Circuit Network: Filter Signal

Posted: Sun Aug 07, 2016 8:37 pm
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

Re: Circuit Network: Filter Signal

Posted: Sun Aug 07, 2016 11:31 pm
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

Re: Circuit Network: Filter Signal

Posted: Mon Aug 08, 2016 12:18 am
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.

Re: Circuit Network: Filter Signal

Posted: Mon Aug 08, 2016 9:40 am
by DOSorDIE

Re: Circuit Network: Filter Signal

Posted: Mon Aug 08, 2016 1:41 pm
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.

Re: Circuit Network: Filter Signal

Posted: Mon Aug 08, 2016 2:15 pm
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

Re: Circuit Network: Filter Signal

Posted: Mon Aug 08, 2016 4:11 pm
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 22121 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

Re: Circuit Network: Filter Signal

Posted: Mon Aug 08, 2016 4:34 pm
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.