Page 1 of 1

Circuit Design - Implementing a X < Y Decider with no signal on X.

Posted: Sat Nov 24, 2018 12:36 am
by Ickis
Hello,

I'm trying to wrap my head around circuits. I feel I'm getting a decent handle, but I just can't work out how to achieve this.

1) I have a filter inserter moving goods from chest A to chest B.
2) It has its filter configured by a decider combinator.
3) It is set up currently such that if chest B has less than 10 of item X, then the combinator outputs 1 for EACH, and sets the filter of the inserter to this.
3) The inserter will then move the items from chest A to chest B.

This ensures that chest B always has 10 of every item contained within chest A. However, this method fails if chest B does not contain item X, as then item X has no signal, and is not considered within the EACH, so the filter is never set for item X.

I'm well aware I could specifically set the items to filter on the inserter and it would work fine, however I'm wanting to keep it generic so as to be able to transfer all items from one chest to another. How can I get around this limitation that X == 0, is actually X == NULL?

Re: Circuit Design - Implementing a X < Y Decider with no signal on X.

Posted: Sat Nov 24, 2018 9:13 am
by DaveMcW
Attach a constant combinator to the chest with every item you want equal to 1.

Re: Circuit Design - Implementing a X < Y Decider with no signal on X.

Posted: Sat Nov 24, 2018 9:25 am
by Trebor
This is a little involved:

1) Connect a red wire from chest A to decider combiner 1, set condition to Each > 0 output 1 Each. Output will be 1 for every item in chest A.

2) Connect a red wire from decider combiner 1 to arithmetic combiner 2, set condition to Each * -10 output Each. Output will be -10 for every item in chest A.

3) Connect a red wire from arithmetic combiner 2 to decider combiner 3, connect a green wire from chest B to decider combiner 3, set condition to Each < 0 output Each. Output will be a negative number for every item in chest A that does not have 10 items in chest B.

4) Connect a red wire from decider combiner 3 to arithmetic combiner 4, set condition to Each * -1 output Each. Output will be the count of each item missing from chest B that is in chest A.

5) Connect a red wire from arithmetic combiner 4 to filter inserter. Filter will be set to the five items that are most needed in chest B.

As items are added/removed to/from chest A or B the filter on the filter inserter will be updated.

Re: Circuit Design - Implementing a X < Y Decider with no signal on X.

Posted: Sat Nov 24, 2018 10:21 am
by Ickis
DaveMcW wrote:
Sat Nov 24, 2018 9:13 am
Attach a constant combinator to the chest with every item you want equal to 1.
Thanks that wouldn't keep it generic though. ;)

Re: Circuit Design - Implementing a X < Y Decider with no signal on X.

Posted: Sat Nov 24, 2018 10:23 am
by Ickis
Trebor wrote:
Sat Nov 24, 2018 9:25 am
This is a little involved:

1) Connect a red wire from chest A to decider combiner 1, set condition to Each > 0 output 1 Each. Output will be 1 for every item in chest A.

2) Connect a red wire from decider combiner 1 to arithmetic combiner 2, set condition to Each * -10 output Each. Output will be -10 for every item in chest A.

3) Connect a red wire from arithmetic combiner 2 to decider combiner 3, connect a green wire from chest B to decider combiner 3, set condition to Each < 0 output Each. Output will be a negative number for every item in chest A that does not have 10 items in chest B.

4) Connect a red wire from decider combiner 3 to arithmetic combiner 4, set condition to Each * -1 output Each. Output will be the count of each item missing from chest B that is in chest A.

5) Connect a red wire from arithmetic combiner 4 to filter inserter. Filter will be set to the five items that are most needed in chest B.

As items are added/removed to/from chest A or B the filter on the filter inserter will be updated.
That's brilliant thanks! Although I found that arithmetic combiner 4 was messing things up, I removed it and simply connecting a red wire from decider combiner 3 to the filter is what worked.

Have you thought about doing some tutorials on circuit design? Seen many things on it, but your way of writing has been by far the clearest.

Re: Circuit Design - Implementing a X < Y Decider with no signal on X.

Posted: Sat Nov 24, 2018 11:23 am
by Optera
You can do it much easier with integer overflow.

Specific:
One constant combinator set to 2147483647 - how much you want in chest B of whatever linked to both chest and filter inserter.

Generic:
read chest into a
1) decider combinator set to each != 0 each = 1 feed the output into
2) arithmetic combinator set to each * (2147483647 - desired amount) = each (sadly we cant directly set the decider output to any number or we could skip this arithmetic entirely)
and finally feed that to the filter inserter


Edit: just realized you want a generic way independent of chest B having an item so my generic way won't work.

Edit2:
Here's a generic way that will ensure anything in chest A will have > 10 in B.
2018-11-24-12-35-07-5331553.png
2018-11-24-12-35-07-5331553.png (162.2 KiB) Viewed 2871 times


Con:
It may lock the inserter if chest B contains enough things <10 that Chest A can't provide.

Re: Circuit Design - Implementing a X < Y Decider with no signal on X.

Posted: Sat Nov 24, 2018 12:53 pm
by quyxkh
Trebor wrote:
Sat Nov 24, 2018 9:25 am
This is a little involved:

1) Connect a red wire from chest A to decider combiner 1, set condition to Each > 0 output 1 Each. Output will be 1 for every item in chest A.

2) Connect a red wire from decider combiner 1 to arithmetic combiner 2, set condition to Each * -10 output Each. Output will be -10 for every item in chest A.

3) Connect a red wire from arithmetic combiner 2 to decider combiner 3, connect a green wire from chest B to decider combiner 3, set condition to Each < 0 output Each. Output will be a negative number for every item in chest A that does not have 10 items in chest B.

4) Connect a red wire from decider combiner 3 to arithmetic combiner 4, set condition to Each * -1 output Each. Output will be the count of each item missing from chest B that is in chest A.

5) Connect a red wire from arithmetic combiner 4 to filter inserter. Filter will be set to the five items that are most needed in chest B.

As items are added/removed to/from chest A or B the filter on the filter inserter will be updated.
This is the one, except you can do it with three combinators. I'd describe the setup as A greenwired to Each>0⇒1 Each greenwired to Each*-10⇒Each redwired to Each*-1⇒Each, B greenwired to the Each*-1 negator greenwired to your filter. So the negator sees -10 X for each X in A, plus n X for every X in B, and negates the sum, giving -nX+(10 if X in A), positive only if X is in A and there's less than 10 of it in B.

Another wiring that gets the same result is to make the multiplier be *10 instead of *-10 and greenwire its output to the negator's output.

Re: Circuit Design - Implementing a X < Y Decider with no signal on X.

Posted: Sat Nov 24, 2018 4:00 pm
by Trebor
quyxkh wrote:
Sat Nov 24, 2018 12:53 pm
This is the one, except you can do it with three combinators. I'd describe the setup as A greenwired to Each>0⇒1 Each greenwired to Each*-10⇒Each redwired to Each*-1⇒Each, B greenwired to the Each*-1 negator greenwired to your filter. So the negator sees -10 X for each X in A, plus n X for every X in B, and negates the sum, giving -nX+(10 if X in A), positive only if X is in A and there's less than 10 of it in B.

Another wiring that gets the same result is to make the multiplier be *10 instead of *-10 and greenwire its output to the negator's output.
I like that but my OCD would have wired it just a little differently:
A greenwired to Each>0⇒1 Each greenwired to Each*-10⇒Each greenwired to Each*-1⇒Each, B redwired to the Each*-1 negator redwired to your filter.

That way A travels on the green wire and B travels on the red wire.

Re: Circuit Design - Implementing a X < Y Decider with no signal on X.

Posted: Sat Nov 24, 2018 4:16 pm
by Trebor
Ickis wrote:
Sat Nov 24, 2018 10:23 am
Have you thought about doing some tutorials on circuit design? Seen many things on it, but your way of writing has been by far the clearest.
Thank you.

Re: Circuit Design - Implementing a X < Y Decider with no signal on X.

Posted: Sat Nov 24, 2018 4:42 pm
by quyxkh
Trebor wrote:
Sat Nov 24, 2018 4:00 pm
quyxkh wrote:
Sat Nov 24, 2018 12:53 pm
This is the one, except you can do it with three combinators. I'd describe the setup as A greenwired to Each>0⇒1 Each greenwired to Each*-10⇒Each redwired to Each*-1⇒Each, B greenwired to the Each*-1 negator greenwired to your filter. So the negator sees -10 X for each X in A, plus n X for every X in B, and negates the sum, giving -nX+(10 if X in A), positive only if X is in A and there's less than 10 of it in B.

Another wiring that gets the same result is to make the multiplier be *10 instead of *-10 and greenwire its output to the negator's output.
I like that but my OCD would have wired it just a little differently:
A greenwired to Each>0⇒1 Each greenwired to Each*-10⇒Each greenwired to Each*-1⇒Each, B redwired to the Each*-1 negator redwired to your filter.

That way A travels on the green wire and B travels on the red wire.
Yup. Two mental models. I like using red for negative (want/take) values when I can, color by value source looks like it'd also work.