File size: 1,026 Bytes
0a3edb6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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)