Download scripts/flow_debug/cycles.py from beyarkay/factorio-blueprints: direct link, hf CLI and curl.
- Browser
- Download file 1.03 kB
-
https://huggingface.co/datasets/beyarkay/factorio-blueprints/resolve/main/scripts/flow_debug/cycles.py
- Command line
-
hf download hf://datasets/beyarkay/factorio-blueprints/scripts/flow_debug/cycles.py
-
curl -L -o cycles.py https://huggingface.co/datasets/beyarkay/factorio-blueprints/resolve/main/scripts/flow_debug/cycles.py
1.03 kB
| import random, sys | |
| import networkx as nx, numpy as np, torch | |
| import factorion_rs | |
| import corpus.convert as cv | |
| from functional import sample | |
| from factorion import count_unpowered | |
| views = sample(open(sys.argv[1]).read().split(), 300, nudge=True) | |
| stats = dict(n=0, cyc=0, dead=0, dead_cyc=0, dead_unpowered=0, machine_cyc=0) | |
| for r, lab, x0, y0 in views: | |
| r.lanes = {k: {getattr(cv.str2item(n), "value", -1) or -1 for n in v} for k, v in lab.items()} | |
| r.drills = [(fx, fy, d) for (fx, fy), d in r.drills] | |
| w = cv.paste(r, x0, y0, 32, cv.edit(r, x0, y0, 32, random.Random(0))) | |
| W = np.ascontiguousarray(w.transpose(1, 2, 0)) | |
| nodes, edges = factorion_rs.py_build_graph(W) | |
| g = nx.DiGraph(edges); g.add_nodes_from(range(len(nodes))) | |
| cyc = not nx.is_directed_acyclic_graph(g) | |
| dead = cv.deliveries(w, set())[0] == 0 | |
| stats["n"] += 1; stats["cyc"] += cyc; stats["dead"] += dead; stats["dead_cyc"] += dead and cyc | |
| stats["dead_unpowered"] += dead and count_unpowered(torch.from_numpy(w)) > 0 | |
| print(stats) | |