ComfyFactory / ComfyFactorio

A compilation of factorio scenarios, featuring many different maps.
GNU General Public License v3.0
45 stars 53 forks source link

MTN: Charging station is effectively O(n^2) #451

Closed vadcx closed 2 months ago

vadcx commented 7 months ago

https://github.com/ComfyFactory/ComfyFactorio/blob/cd2cda7a0e7a92d76180cd41bd2692b21e140fc4/maps/mountain_fortress_v3/charging_station.lua#L76-L81

However the n is low. It is: O( #dischargedEquip * #nearbyAccumulators )

To charge all equipment from all available accumulators we would need to iterate both at least once. Assuming that fetching nearby accumulator entities is a more expensive operations, I would rewrite it like this:

  1. Iterate all equipment
  2. Add discharged items to table, count up needed power
  3. Iterate nearby accumulators. Count up available power, break return if >= needed power
  4. Iterate saved discharged items and charge them based on available power
stale[bot] commented 5 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

vadcx commented 5 months ago

Bad bot!

stale[bot] commented 3 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.