Circuits/dynamic mall: Get the 10 (largest) signals from a list of signals
Circuits/dynamic mall: Get the 10 (largest) signals from a list of signals
I'm looking for a general handling of "return n signals from an arbitrary number of signals".
I don't care if these are the n largest signals or the n smallest signals or whatever sorting it is - just n out of an arbitrary number of signals with random values. The n largest would be fine, but this isn't a requirement. Just not more than n.
If this is possible with a small and constant number of combinators I would use it, otherwise I need to find a different approach and not use such functionality at all.
I also want a direct result, not the result of a loop over all items, since this would create an unknown and possibly huge amount of latency.
A possible solution for n=10 would be to build 10 selector combinators and each one picks the 0th, the 1th, the 2nd ... the 9th largest signal, and all signals are added again to get all 10 largest signals. However, this hardcodes the number of combinators, and it requires quite many combinators. Is there a smaller solution? Some kind of array slice functionality? Keep in mind the input signals and their values are stable but random.
This is for creating a mall with dynamic recipes including dependent ingredients. I want it to build a given amount of different items in parallel, but need to limit to for example not more than 5 or may be 10 different items, otherwise all machines could be occupied with building the requests and no machine is left for building the dependent ingredients, so nothing is being built at all.
My idea is to have list of (up to) n items to build. And I have a list of m assembling machines, for example 30. Each assembling machine gets a selector combinator that picks the 0th, 1th, ... 29th item from the list of items to build.
The initial list will contain up to n items all with value=1. These are set as recipe in the first n assembling machines.
Now the ingredients are read from the machines. They are normalized to value=1 and all items already present in the initial list removed, as well as bulk items manufactured elsewhere (plates, green/red/blue chips etc.).
The values in the initial list is increased by 1 (EACH+1), and the normalized+filtered ingredients added. This is the new list of items to build. This way the sorting is kept stable, so the recipes already set don't change, and just new items are added at the end of the list.
Now more assembling machines get a recipe from their corresponding selector combinator.
And their recipes are also being read, processed and the list of items to build extended.
And so on, until there are no more dependent items are added.
This must be running on a timer that runs from 0...3600 or 0..7200 (one or 2 minutes). On tick 0, the list of items is reset and initially set again with the currently requested items, so recipes are being flushed whose item demand has been satisfied. Then the machines will build their stuff for 1 or 2 minutes, then it's reset again. The first few ticks are also needed to perform the EACH+1 in the correct moment when the next tier of ingredients are added to the list.
I don't care if these are the n largest signals or the n smallest signals or whatever sorting it is - just n out of an arbitrary number of signals with random values. The n largest would be fine, but this isn't a requirement. Just not more than n.
If this is possible with a small and constant number of combinators I would use it, otherwise I need to find a different approach and not use such functionality at all.
I also want a direct result, not the result of a loop over all items, since this would create an unknown and possibly huge amount of latency.
A possible solution for n=10 would be to build 10 selector combinators and each one picks the 0th, the 1th, the 2nd ... the 9th largest signal, and all signals are added again to get all 10 largest signals. However, this hardcodes the number of combinators, and it requires quite many combinators. Is there a smaller solution? Some kind of array slice functionality? Keep in mind the input signals and their values are stable but random.
This is for creating a mall with dynamic recipes including dependent ingredients. I want it to build a given amount of different items in parallel, but need to limit to for example not more than 5 or may be 10 different items, otherwise all machines could be occupied with building the requests and no machine is left for building the dependent ingredients, so nothing is being built at all.
My idea is to have list of (up to) n items to build. And I have a list of m assembling machines, for example 30. Each assembling machine gets a selector combinator that picks the 0th, 1th, ... 29th item from the list of items to build.
The initial list will contain up to n items all with value=1. These are set as recipe in the first n assembling machines.
Now the ingredients are read from the machines. They are normalized to value=1 and all items already present in the initial list removed, as well as bulk items manufactured elsewhere (plates, green/red/blue chips etc.).
The values in the initial list is increased by 1 (EACH+1), and the normalized+filtered ingredients added. This is the new list of items to build. This way the sorting is kept stable, so the recipes already set don't change, and just new items are added at the end of the list.
Now more assembling machines get a recipe from their corresponding selector combinator.
And their recipes are also being read, processed and the list of items to build extended.
And so on, until there are no more dependent items are added.
This must be running on a timer that runs from 0...3600 or 0..7200 (one or 2 minutes). On tick 0, the list of items is reset and initially set again with the currently requested items, so recipes are being flushed whose item demand has been satisfied. Then the machines will build their stuff for 1 or 2 minutes, then it's reset again. The first few ticks are also needed to perform the EACH+1 in the correct moment when the next tier of ingredients are added to the list.
Re: Circuits/dynamic mall: Get the 10 (largest) signals from a list of signals
The new selector combinator can pull this. Mode of Operation: Select Input. It'll give you the highest one item in the feed on Index 0, then the second highest on Index 1, and down the line.
So if you want the top 10, you'll need 10 combinators.
So if you want the top 10, you'll need 10 combinators.
- Stargateur
- Fast Inserter
- Posts: 163
- Joined: Sat Oct 05, 2019 6:17 am
- Contact:
Re: Circuits/dynamic mall: Get the 10 (largest) signals from a list of signals
no you would just need to use index 9
Re: Circuits/dynamic mall: Get the 10 (largest) signals from a list of signals
That's unfortunately a solution I already mentioned in the OP - I'm searching for a smaller solution, with less combinators, and may be even where the amount of signals to get is variable and not hardcoded to the number of combinators.
Re: Circuits/dynamic mall: Get the 10 (largest) signals from a list of signals
Index 9 just outputs the 10th item in the list. Not items 1-10.
Re: Circuits/dynamic mall: Get the 10 (largest) signals from a list of signals
Arbitrary is extremely hard to match with less combinators. You could try to do something with selector index, dump onto a memory cell and remove that from input X times, and then output that memory cell. Resetting the memory cell would probably require wiring everything up to a power switch to power reset the cell.
- SupplyDepoo
- Filter Inserter
- Posts: 305
- Joined: Sat Oct 29, 2016 8:42 pm
- Contact:
Re: Circuits/dynamic mall: Get the 10 (largest) signals from a list of signals
I can think of a way that would work for 1 to 15 inputs (dynamically) as long as the inputs are less than 32768 (using half of the bits to unique each signal so that a decider combinator can do each < N where N is the output of one selector combinator with index 1-15). It could also be unlimited but without the ability to sort by the input value.
Either way would probably be around ten or slightly more combinators, so you might as well go with the simpler approach of 10 selector combinators, unless you really need the dynamic limit.
I don't think de-powering would clear the memory cell, but now that we can add multiple conditions to decider combinators you could have a reset signal that stops the feedback loop.
Either way would probably be around ten or slightly more combinators, so you might as well go with the simpler approach of 10 selector combinators, unless you really need the dynamic limit.
That sounds like it would have delay and not be continuously updating based on the inputs at every game tick. Unless the logic is duplicated enough times so that it could process each tick in parallel, but this is probably going to be more than 10 combinators too. Good idea though.Lochar wrote: ↑Wed Nov 13, 2024 4:41 pm Arbitrary is extremely hard to match with less combinators. You could try to do something with selector index, dump onto a memory cell and remove that from input X times, and then output that memory cell. Resetting the memory cell would probably require wiring everything up to a power switch to power reset the cell.
I don't think de-powering would clear the memory cell, but now that we can add multiple conditions to decider combinators you could have a reset signal that stops the feedback loop.
Re: Circuits/dynamic mall: Get the 10 (largest) signals from a list of signals
Yeah, I'd assume it would be X ticks behind without duplication. You're paying for your gains somewhere.
- Stargateur
- Fast Inserter
- Posts: 163
- Joined: Sat Oct 05, 2019 6:17 am
- Contact:
Re: Circuits/dynamic mall: Get the 10 (largest) signals from a list of signals
ahhhhhh
ooooo, I'm not gonna lie I didn't read everything haha
well easy, use a selector as I said to get the 10th items in the list, use arithmetic to abstract the signal, then use the value to set in a compactor to get all signal >= to this value, bim top 10 signals.
Code: Select all
0eNqlll1u2zAMx++ix0EpYltKYgN72N53gqAwHIdthdqSJ8vpgsAH2D12sp1klPJhNTCqCnuTKfFH8k+J8InsmgE6LaQhxYmIWsmeFNsT6cWzrBprk1ULpCCVFualBSPqRa3anZCVUZqMlAi5h1+kSEY647WHWuxBz7uk4yMlII0wAs5R3cexlEO7A41MeuW0sBdDu4AGaqMxhU41QCjpVI/OStqINodN+sApOZJikSTLBz7anO6Y6Y3ZO5p6l9wMMpuQWCNBhYxWTbmDl+og0AXPqQ50dXa6UBF0XpRthZSnqunhUndpNTaVFTyfSzCjH0s+kyILpzixbPy98+/txpPQvSmnxpljZ2MfhDYDWia13IkFVPWLbWEPFuPVgr3yZfiCnmow3RDB/kHGcU4RRj+4TjNy8LAcF9CdFv7X9n+liSnbJtl2lXYVFeTv7z94yg9fSjBvSr+6NDXsSWH0gDfqWQPIy/0a7XM6a37/hj+Z+eeCzPaI35jXKxFo0vRSlzm+1Pk2oZS35kxrLO06dKxKjQF9bw0UnKDlJ25gBWiUSrfu0LsmfHWGwd1tW/B1aAXhaRw89eBZEJ7FwTMPzoJwFgdnHpwH4TwOzj34KghfxcFXHnwdhK/j4GsPvgnCN3HwjQfPg/A8Dp578GQZpH+LfEVLHx9+pN8j8QmOJjuccAq+Ce3+KLYJTSmj7JFuU5pQThO3YjSjKa4yu+dW7LKLvsJAi+Tpv4iSAw4YN7v4Ks1ZnnPGM87SzTj+A9M3EzE=
Code: Select all
0eNrFllGOmzAQhu/ix8pZBWNIQOpD+95eIFohAt6NVbCpMdlGEQfoPXqynqRjhyxuhOJYfeibsWc+zz/jGXFG+2ZgneJCo/yMeCVFj/LdGfX8VZSN2RNly1COzIkuhV5Vst1zUWqp0IgRFzX7gfJoxAs+peL60DLNq2UvMj5jxITmmrPLtfbjVIih3TMFWHxFtazmQ7tiDau0Al4nG4Yw6mQPzlKYS00YW/KUYHRC+SqK1k/JaMK6YZJ3Zm9pUrnBLSDjGQkyTSK0kk2xZ4fyyMEF7GTHVHlxmqgAuiyKtgTKS9n0bNJdzHnSp84EcuRKD7AzR2YtVl/RuKQgxvcTvKCB+jXMrAKOa+vfm4MXrnr9eNCsrA6mxj0zmOL6bmwx3Tx9AE856G4IYH8xCVnICH03rFnFa+YraeJPxwS6yYX7tfvX1ITINkG2Xamsohz9/vkLrNzrC8H0m1TfbJiK1SjXaoAn96oYE9MDHE2/XXJ+2+UPRv7YJYs1SvC9UXK379YZtPJymSCV78WZ1yDtOphMlhrN1O2ut/Uw+g4HoAA2hVStNfqrCB/txmDedgail2WnobLJ/5Qdhcm2Y/86zL1wEgYnDjz2wuMweOzAqRdOw+DUgSdeeBIGTxx46oWnYfDUgW+88E0YfOPAt174Ngy+deCZF56FtvcMj9Ze+qfALlq7eH+Tfg7ER9NwguH/xpX909pFmGCK6TPeERzhFEd2RXCCiV1RHNtVbKzsik52QOGatXDH/OuI0RFGjZ1iSUoymmUJTeKEku04/gHqBHPF
Last edited by Stargateur on Wed Nov 13, 2024 6:47 pm, edited 1 time in total.
- SupplyDepoo
- Filter Inserter
- Posts: 305
- Joined: Sat Oct 29, 2016 8:42 pm
- Contact:
Re: Circuits/dynamic mall: Get the 10 (largest) signals from a list of signals
Only if those signals have unique values, otherwise >= will select more than 10 signals.Stargateur wrote: ↑Wed Nov 13, 2024 6:40 pm well easy, use a selector as I said to get the 10th items in the list, use arithmetic to abstract the signal, then use the value to set in a compactor to get all signal >= to this value, bim top 10 signals.
- Stargateur
- Fast Inserter
- Posts: 163
- Joined: Sat Oct 05, 2019 6:17 am
- Contact:
Re: Circuits/dynamic mall: Get the 10 (largest) signals from a list of signals
MmM, I don't think there is simple solution to this problem then. But my solution unless you really need exactly N should be "good enough".SupplyDepoo wrote: ↑Wed Nov 13, 2024 6:46 pmOnly if those signals have unique values, otherwise >= will select more than 10 signals.Stargateur wrote: ↑Wed Nov 13, 2024 6:40 pm well easy, use a selector as I said to get the 10th items in the list, use arithmetic to abstract the signal, then use the value to set in a compactor to get all signal >= to this value, bim top 10 signals.
Re: Circuits/dynamic mall: Get the 10 (largest) signals from a list of signals
Nice idea. This kind of direct solution is what I was searching for. If the flaw with the non-unique values is a problem, is yet to be seen. Not necessarily a problem for my use case.Stargateur wrote: ↑Wed Nov 13, 2024 6:40 pm well easy, use a selector as I said to get the 10th items in the list, use arithmetic to abstract the signal, then use the value to set in a compactor to get all signal >= to this value, bim top 10 signals.
-
- Inserter
- Posts: 43
- Joined: Sat Nov 28, 2020 5:27 pm
- Contact:
Re: Circuits/dynamic mall: Get the 10 (largest) signals from a list of signals
They don't all need unique values. But the "10 largest signals" selection is undefined if #10 and #11 have the same value. No amount of combinators will fix that... without adding a second-level sorting order.SupplyDepoo wrote: ↑Wed Nov 13, 2024 6:46 pm Only if those signals have unique values, otherwise >= will select more than 10 signals.
But yeah, depending on use-case, "less or equal to #10" (may return more up to all signals) or "less than #11" (may return fewer to no signals) are both easily achievable with this solution and may do the trick. Getting exactly ten signals will be hard, when you consider edge cases like "all signals have the same value". Which ones should it even pick‽
- Stargateur
- Fast Inserter
- Posts: 163
- Joined: Sat Oct 05, 2019 6:17 am
- Contact:
Re: Circuits/dynamic mall: Get the 10 (largest) signals from a list of signals
There is another problem if there is less than N signal, no signals will be outputted. Thus I think add a `or M == 0` to the decider combinator should solve this
- SupplyDepoo
- Filter Inserter
- Posts: 305
- Joined: Sat Oct 29, 2016 8:42 pm
- Contact:
Re: Circuits/dynamic mall: Get the 10 (largest) signals from a list of signals
My idea was to have a constant combinator that gives each possible signal a unique value, then that is added to the input (on the lower 15 bits), fed through a selector, then through a decider with >= and then back to the input values, thanks to the ability to select which input wire colour to use on combinators.jdrexler75 wrote: ↑Wed Nov 13, 2024 7:59 pm Getting exactly ten signals will be hard, when you consider edge cases like "all signals have the same value". Which ones should it even pick‽
Re: Circuits/dynamic mall: Get the 10 (largest) signals from a list of signals
Or instead of subtracting the 10th value pulled out by the selector, use a decider to pass through only those that are greater than it. If there are fewer values, the selector will return a null value and the test will automatically be just 'greater than 0'.Stargateur wrote: ↑Wed Nov 13, 2024 6:40 pm well easy, use a selector as I said to get the 10th items in the list, use arithmetic to abstract the signal, then use the value to set in a compactor to get all signal >= to this value, bim top 10 signals.
Re: Circuits/dynamic mall: Get the 10 (largest) signals from a list of signals
Or use Selector's "Count Inputs" mode to set a max value for N.Stargateur wrote: ↑Wed Nov 13, 2024 8:03 pm There is another problem if there is less than N signal, no signals will be outputted. Thus I think add a `or M == 0` to the decider combinator should solve this
Re: Circuits/dynamic mall: Get the 10 (largest) signals from a list of signals
I have a question for the selector combinators. Could not find anything useful to start learning with.
I followed an older guide with a ton of decider combinators to illustrate my science in the network with colors and display.
However I'd like to improve that, maybe with less combinators and also that the display shows the order descending from most items to least. I tried the blueprint from stargateur but I don't know how to connect the wires to the displays. It shows random numbers I managed to display one item, in another build also orange and blue science (with more selector combinators) but instead of continuing with the other sciences it jumped back to the first science. My blueprint is
I followed an older guide with a ton of decider combinators to illustrate my science in the network with colors and display.
However I'd like to improve that, maybe with less combinators and also that the display shows the order descending from most items to least. I tried the blueprint from stargateur but I don't know how to connect the wires to the displays. It shows random numbers I managed to display one item, in another build also orange and blue science (with more selector combinators) but instead of continuing with the other sciences it jumped back to the first science. My blueprint is