Live data from Hacker News

B-trees in Factorio

razberry.substack.com

11–20 of 65 posts

Re: B-trees in Factorio

#11
Awesome to see this.

> i've been reading Database Internals with a book club, and this week was chapter 2, about B-Trees.

For the crowd: signups are closed. But if you want: grab a copy of Database Internals and follow along "read-only" with the schedule and notes here: https://eatonphil.com/2023-database-internals.html.

Re: B-trees in Factorio

#12
post #9

Earlier quoted context omitted.

The fastest "filter inserter" in modern Factorio meta is the splitter, which operates at full speed of the belt. There's almost no reason to use inserters for belt-to-belt transfers for modern meta, aside from a few speed-running stats where you use red-inserters while skipping logistics2 or something. But if you're trying to sort items on a belt by placing them onto another belt, the answer is a splitter. Item A spl…

> Item A splits off to another belt, while all other items loop back. This doesn't address the parent comment's concern: > IIRC splitters only accept a single filter, and so you'd need many of them at each junction I haven't played Factorio in years, but IIRC the splitter maintains state (direction for next item) per item type, so I guess it can be set up to filter as many types as you like? I remember you had to pri…

> I haven't played Factorio in years

Oh geez, your comment reminds me of like 8 years ago. You've really been out of the loop haven't ya? Yeah, what you say used to be true, but that's not what I'm talking about.

All splitters today can split items off. You can just click on a modern splitter and say "Left side Iron ore", and all iron-ore leaves the left side of the splitter, and all other items go out the right side. This operates at full speed, no glitches.

> so I guess it can be set up to filter as many types as you like?

So use a splitter per item, and then merge the belts back together later.

If you have 5 items to sort, create 5 filters, and then run the belts to route them where those 5 items need to go.

For "Meta" builds, the key requirement isn't size. Its throughput. When you have 5 filters inserters, you barely will have ~10 items/second throughput (and that will glitch out depending on how successful your inserters are at picking up items, corners can pose issues for example)

When you have 5 filter-splitters (on 5 different items), you easily prove that every decision point operates at the full 15/30/45 items/second (yellow/red/blue belts respectively).

Re: B-trees in Factorio

#13

An inefficient design, but computer-science theory in Factorio means playing suboptimally necessarily. (Factorio wasn't designed to show off B-Trees, all the tools were designed to ya know... play Factorio) ------------ So I have to comments. #1 is about the Comp-Sci side, and #2 is about the optimization side. #3 combines both together for what I'd like to talk about. 1. Self-balancing trees (2-3 trees, Red-black Tr…

thanks for the notes! def want to see if I can implement self-balancing next - was thinking the bots would come in handy here? not sure if its possible to have them dynamically build blueprints

Re: B-trees in Factorio

#14
post #2

You could do this all with splitters, don’t need the boxes and filter inserters. Nice explanation!

thanks! but yea as some people mentioned, i need to sort/filter multiple items, (ie the first node needs wood,coal,stone to go left and the metals to go right), and the splitters can only filter 1 item.

Re: B-trees in Factorio

#15

An inefficient design, but computer-science theory in Factorio means playing suboptimally necessarily. (Factorio wasn't designed to show off B-Trees, all the tools were designed to ya know... play Factorio) ------------ So I have to comments. #1 is about the Comp-Sci side, and #2 is about the optimization side. #3 combines both together for what I'd like to talk about. 1. Self-balancing trees (2-3 trees, Red-black Tr…

if you treat splitters as moving the computation backward on the belt, I'm pretty sure they're universal, so the intersection of splitters and computer science is computer science

Re: B-trees in Factorio

#16

An inefficient design, but computer-science theory in Factorio means playing suboptimally necessarily. (Factorio wasn't designed to show off B-Trees, all the tools were designed to ya know... play Factorio) ------------ So I have to comments. #1 is about the Comp-Sci side, and #2 is about the optimization side. #3 combines both together for what I'd like to talk about. 1. Self-balancing trees (2-3 trees, Red-black Tr…

thanks for the notes! def want to see if I can implement self-balancing next - was thinking the bots would come in handy here? not sure if its possible to have them dynamically build blueprints

The main issue with bots is that they "cheat" what you're trying to do and just instantly solve the problem.

You can click on your logistic auto-fetch feature and just have robots search all the boxes for the items you want, and they'll automatically refill your inventory to 300-belts.

And then when you build a belt somewhere, you can either choose from your inventory, or shift-click and/or blueprint build to have robots search for those items in your entire logistic network and they just fly out, find the item, come back, and place it for you. Just in like 2 or 3 clicks (or less).

So for a lot of these challenges and demonstrations, Factorio players aim for "belts only" or other such constraints, to try and force ourselves into design constraints. Belts-only also uses zero-power (bots need power to function, and its rather substantial in practice). So there's power-benefits to going belt-only.

-----------------------

So what is your goal here? If its to build a tree in Factorio, I think we can say you succeeded.

But its not the optimal play or the "meta" factory design, lol. But I recognize that's not quite what you were going for. (Ex: the meta would be to just use bots in a bot-factory. Or keep items sorted in a belt factory, no reason to mix belts)

I think pushing players to think deeply about the "meta", including the deep thoughts upon how CLOS Networks apply to high-quality Belts/and/splitter designs, is very rewarding. Its not about trees though.

-----------

Mixed-belts are fun though. And I think I spent many good hours and weeks thinking about them back in my Factorio days. Lots of interesting problems to solve, but I think my problem was that these solutions weren't meta, nor did they demonstrate any beautiful mathematical concept.

Benes Networks / CLOS networks applied to belts however, were a perfect match. The best builds were those that matched the deep mathematical/comp. sci foundation of Benes Networks. So it was the "more fun" part of Factorio to me. Not only was I learning some deep Comp. Sci topic, but when I improved my designs based on CLOS Networks, they instantly led to improved belt-balance and throughput in my factory designs.

Re: B-trees in Factorio

#17
post #10

An inefficient design, but computer-science theory in Factorio means playing suboptimally necessarily. (Factorio wasn't designed to show off B-Trees, all the tools were designed to ya know... play Factorio) ------------ So I have to comments. #1 is about the Comp-Sci side, and #2 is about the optimization side. #3 combines both together for what I'd like to talk about. 1. Self-balancing trees (2-3 trees, Red-black Tr…

Per the cheat sheet, 1.625 stack inserters can half fill a blue belt at their stack bonus of 7

That's pulling out of a chest, where they can pick up the entire stack in a single tick.

Pulling off a belt will be a notable slowdown, and picking items off of a wildly mixed belt will be a huge slowdown.

Re: B-trees in Factorio

#18
post #9

Earlier quoted context omitted.

> Item A splits off to another belt, while all other items loop back. This doesn't address the parent comment's concern: > IIRC splitters only accept a single filter, and so you'd need many of them at each junction I haven't played Factorio in years, but IIRC the splitter maintains state (direction for next item) per item type, so I guess it can be set up to filter as many types as you like? I remember you had to pri…

> I haven't played Factorio in years Oh geez, your comment reminds me of like 8 years ago. You've really been out of the loop haven't ya? Yeah, what you say used to be true, but that's not what I'm talking about. All splitters today can split items off. You can just click on a modern splitter and say "Left side Iron ore", and all iron-ore leaves the left side of the splitter, and all other items go out the right side…

Who said anything about throughput ?

Splitters can still only filter out a single item type, so if your goal is to do comparisons using a single entity (for clarity reasons for instance), they won't cut it.

----

Also, Factorio speedrunning has no metagame, since it's not a PvP game (well, aside from the less played PvP mode) : speedrunners don't have to adapt to changes in tactics of other speedrunners, they only have to learn new tricks that other speedrunners might discover, which is part of discovering the game itself.

Re: B-trees in Factorio

#19

An inefficient design, but computer-science theory in Factorio means playing suboptimally necessarily. (Factorio wasn't designed to show off B-Trees, all the tools were designed to ya know... play Factorio) ------------ So I have to comments. #1 is about the Comp-Sci side, and #2 is about the optimization side. #3 combines both together for what I'd like to talk about. 1. Self-balancing trees (2-3 trees, Red-black Tr…

Is there a Factorio extension like "Scriptorio" that lets you put JSON on conveyor belts? With JavaScript or Lua function factories.

Then you could pass the b-trees themselves around with conveyor belts and inserters, as well as the objects to insert and search.

And write a recursive search function with a loop of conveyor belts running through factories, that just loops the tree around peeling off a level at a time until it hits the leaf, breaking the loop and outputting the result.

It's an interesting execution model, not standard JavaScript, more data flow. Should you allow "quantum tunneling" and "action at a distance" by allowing multiple references to the same underlying JSON objects from different conveyor belts / inserters / factories? That could be useful, but Factorio itself traditionally treats each physical item having a unique identity, so maybe it would be more "realistic" not to support multiple references. Or you can only make multiple references once you research "Quantum Tunneling JSON" technology, with the "JSON Reference Entangler Factory"!

Re: B-trees in Factorio

#20
post #9

Earlier quoted context omitted.

> Item A splits off to another belt, while all other items loop back. This doesn't address the parent comment's concern: > IIRC splitters only accept a single filter, and so you'd need many of them at each junction I haven't played Factorio in years, but IIRC the splitter maintains state (direction for next item) per item type, so I guess it can be set up to filter as many types as you like? I remember you had to pri…

> I haven't played Factorio in years Oh geez, your comment reminds me of like 8 years ago. You've really been out of the loop haven't ya? Yeah, what you say used to be true, but that's not what I'm talking about. All splitters today can split items off. You can just click on a modern splitter and say "Left side Iron ore", and all iron-ore leaves the left side of the splitter, and all other items go out the right side…

It's more complicated when you have many types of item and not many of each item, because a filter inserter can do five types and a splitter can do one.

And if you add some wires, you can have each inserter automatically grab whatever is directly in front of it that isn't on a blacklist. At that point a max-throughput build with inserters is a big but roughly fixed size, while a build for splitters is proportional to the number of items.

Post reply on HN