Pairwise division is ridiculous

Post all other topics which do not belong to any other category.
Post Reply
Optymistyk
Long Handed Inserter
Long Handed Inserter
Posts: 52
Joined: Sun Jun 14, 2020 9:41 pm
Contact:

Pairwise division is ridiculous

Post by Optymistyk »

There's a bunch of really annoying things in vanilla circuit network, chief among them the inability to perform pairwise operations.
For example if I wanted to multiply every channel on the red wire by the corresponding channel on the green wire I just can't do it in one combinator(need 5).

However to my surprise I couldn't find any blueprint for pairwise division *at all*. It would seem noone has ever done that. I tried to do it myself but can't think of a way to do that in less than two dozen combinators. I even made a post on Stack Exchange and I got mathematically proven that it's impossible with a non-iterative approach. The easiest way to do it seems to be something like the Goldshmidt algorithm, implementing which in Factorio would require an excessive ammount of circuitry.

So while it may be possible I don't think it's feasible with the way circuit networks currently operate. Which goes to show how borked the circuit system really is. We really need to be able to distinguish between red and green wire channels

User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3699
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: Pairwise division is ridiculous

Post by DaveMcW »

Yes, that sounds difficult.

What is the overall problem you are trying to solve? There is probably a better approach that does not require pairwise division.

User avatar
jamiechi1
Fast Inserter
Fast Inserter
Posts: 196
Joined: Wed Jan 03, 2018 10:12 pm

Re: Pairwise division is ridiculous

Post by jamiechi1 »

Optymistyk wrote:
Wed Aug 05, 2020 1:37 pm

... Which goes to show how borked the circuit system really is. We really need to be able to distinguish between red and green wire channels
I always thought the 'wired-or' input thing was stupid.

Optymistyk
Long Handed Inserter
Long Handed Inserter
Posts: 52
Joined: Sun Jun 14, 2020 9:41 pm
Contact:

Re: Pairwise division is ridiculous

Post by Optymistyk »

DaveMcW wrote:
Thu Aug 06, 2020 12:13 am
Yes, that sounds difficult.

What is the overall problem you are trying to solve? There is probably a better approach that does not require pairwise division.
I'm creating an on-demand factory design. The player uses a constant combinator to make demands and the factory will automatically produce the exact ammount of items and deposit them in the nearby chest. To do that I'm using cell-like modules. Each module produces only one thing (for example Green Science module) and if it lacks the components it can demand them from other modules. So for example if it needs to make 2000 Green Science packs it can demand 2000 Inserters and 2000 Transport belts from other modules, which in turn can broadcast their own demands to produce the items. Modules are connected by railway and trains deliver items to and from each cell.

Now, imagine an Iron Gear module only has to make 1 gear. It's gonna order a train to bring it 2 iron plates. Delivering 2 iron plates over a train is a waste of time and fuel and might create unnecessary bottlenecks. Which is why I want to separate every kind of item into batches. A batch is a unit of quantity. Let's define a batch of iron plates as 200 iron plates. Now instead of demanding 2 iron plates the Iron Gear module would demand 1 batch of iron plates(200). If it needed 300 iron plates it would order 2 batches(400 iron plates) etc. Spare iron plates would be stored for use in the nearest future to handle small orders like these.

And it's for separating items into batches that I need pairwise division.

Ajedi32
Inserter
Inserter
Posts: 28
Joined: Thu May 07, 2020 9:46 pm
Contact:

Re: Pairwise division is ridiculous

Post by Ajedi32 »

IMO every place where Factorio lets you select a circuit network signal should have options to choose which connected network to read/write the signal on. E.g. Instead of just selecting "x signal on the network", you could also select "x signal on green network" or "x signal on red network". That would make a _lot_ of circuit network operations so much simpler, especially pairwise operations like division, multiplication, set union, set intersection, etc.

farcast
Long Handed Inserter
Long Handed Inserter
Posts: 86
Joined: Fri Jul 06, 2018 8:25 am
Contact:

Re: Pairwise division is ridiculous

Post by farcast »

Pairwise division isn't easy, but since we have pairwise multiplication, we can use the "Multiply by the Reciprocal" trick to make your situation a little easier. We can't divide 1 by 200, but we can pretend a very large number is "1" and go from there. The exact value of the large number doesn't matter much, as long as it's several times larger than the largest batch size.

Here's how it goes:

A = a very large number
B = the set of batch sizes for each item
R = the set of requested items
  1. Divide A by Each of B. This will give you a set of magic numbers for the next step. We can't divide a constant by Each either, so this part has to be done manually for each item. Presumably the batch sizes don't change while the factory is running, so you only have to do this "Once".
  2. Pairwise multiply R with the set of magic numbers in a constant combinator(s).
  3. Divide Each of the results by A. This will give you the number of batches for each item, rounded down.
  4. Add 1 to each result if the number requested for that item is greater than 0. This will give you rounded up batches.
For example: let A = 1000, B(iron) = 200, R(iron) = 3125

Code: Select all

1000 / 200   = 5
5 * 3125     = 15625
15625 / 1000 = 15
15 + 1       = 16
Dividing 3125 by 200 directly results in 15.625. Rounding up, that's 16 batches, so this process does get you an accurate result. However, this process isn't perfectly accurate. If the requested items is just a little over the batch size, the result can be one less than it should be. Using an even larger value for A can fix this, but be careful, as the size of A limits how many items can be requested before you run into integer overflow problems during the multiply step.
Efficient inefficient design.

Post Reply

Return to “General discussion”