til/applied-sciences/engineering/tech-tree-and-dag
tech-tree-and-dag.mdupdated 2026-07-162455 words
ダブルクリックで英日反転
Applied Sciences · Engineering

Tech Trees and DAGs — Dependencies Demystified

EN

A game's craft tree is, in CS terms, precisely a DAG (Directed Acyclic Graph). The same structure underpins npm install, make, and CI job ordering — anything where order of operations must respect dependencies.

What a Tech Tree Really Is

  • A chart of arrows: "unlock/craft B only after you have A".
  • Examples: Dr. STONE sulfa-drug chain, Minecraft recipes, Civilization tech tree.
  • Pattern: raw materials → intermediates → final product, joined by directed arrows.

DAG in Three Words

  • Graph: nodes (items) connected by edges (relationships).
  • Directed: arrows have a one-way direction ("A is input for B").
  • Acyclic: no cycle exists — circular deps ("C needs D needs C") make ordering impossible.

Topological Sort

  • Flattens a DAG into a single ordered list that satisfies all dependencies.
  • Algorithms: Kahn's (queue nodes with in-degree 0 first) or reverse-DFS.
  • Used by make, npm install, CI pipelines, and task schedulers.

Visualisation & Libraries

  • Mermaid: text-based, ideal for docs/READMEs — use `flowchart LR`.
  • React Flow: interactive draggable nodes, embeds in web apps.
  • D3 / d3-dag: fully custom layouts; maximum control, maximum effort.
Every dependency graph — game crafting chart or CI pipeline — is a DAG; topological sort gives you the correct build order for free.
Applied Sciences · Engineering

テックツリーと​DAG — 依存関係の​正体

JP

ゲームの​「クラフトツリー」は​CS​(コンピュータサイエンス)​用語で​正確に​DAG​(有向非循環グラフ)と​呼ばれる​構造。​npm installや​make、​CIジョブの​順序付けも​全て​同じ​仕組みで​動いている。

テックツリーとは​何か

  • 「Bを​作るには​Aが​先に​必要」を​矢印で​つないだ図。
  • 例:Dr.STONEの​硫黄→硫酸→サルファ剤、​Minecraftの​レシピ、​Civilizationの​テックツリー。
  • 共通パターン:素材 → 中間生成物 → 最終成果物を​有向の​矢印で​つなぐ。

DAGを​3語で​理解する

  • グラフ(Graph)​:ノード​(点)を​エッジ​(線)で​つないだ構造。
  • 有向​(Directed)​:矢印に​向きが​ある​(​「Aは​Bの​材料」)。
  • 非循環​(Acyclic)​:ループなし。​「Cは​Dが​必要、​Dは​Cが​必要」の​循環依存は​順序決定不能に​なる。

トポロジカルソート​(位相的整列)

  • DAGの​ノードを​「依存関係を​満たす順」に​一列に​並べる​操作。
  • アルゴリズム:カーンの​アルゴリズム​(入次数0の​ノードから​キュー)​または​DFS​(深さ優先探索)の​逆順。
  • make・npm install・CIパイプライン・タスクスケジューラが​内部で​使用している。

描画ライブラリの​選び方

  • Mermaid​(マーメイド)​:テキスト記法。​ドキュメント・README向け。​`flowchart LR`で​DAGを​表現。
  • React Flow:Webアプリ組み込み向け。​ノードを​ドラッグできる​インタラクティブ表示。
  • D3 / d3-dag:完全カ​スタム。​自由度​最大・​実装コスト最大。
依存関係の​グラフは​必ずDAG。​トポロジカルソートを​使えば​ビルドや​インストールの​正しい​実行順序が​自動で​決まる。
148 notestil