"""依頼311:清掃の回を回す(run310.py の写し。分け方 "default" は -c263Split を渡さない=標準)(同時 --par 本まで・画面なし)。 使い方: python3 run310.py check|main|edge [--par 4] 回ごとのフォルダは runs/ に、Unity のログは logs/ に。索引は index311.csv に足す。""" import subprocess, sys, os, json, csv, time from concurrent.futures import ThreadPoolExecutor ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) BUILD = os.environ.get('C310_BUILD', 'cleaning311') EXE = os.path.expanduser(f'~/Robotics_UX/ServiceSim/Builds/{BUILD}/CleaningSim.app/Contents/MacOS/ServiceSim') BI = os.path.expanduser(f'~/Robotics_UX/ServiceSim/Builds/{BUILD}/build_info.json') RUNS = os.environ.get('C310_RUNS', 'runs') FIX = os.environ.get('C310_FIX', 'on') FAST = os.environ.get('C310_FAST', 'on') RECT = os.environ.get('C310_RECT', 'on') KIRI = os.environ.get('C310_KIRI', 'on') CS = json.load(open(BI))['unity_cs'].split('/')[-1] def jobs(kind): if kind == 'check': return [('chk311a', 2, 'split', 0, False), ('chk311b', 2, 'split', 0, False), ('chk311c', 1, 'none', 0, False), ('chk311d', 2, 'default', 0, False)] + [('chk311e', 2, 'shared', s, False) for s in range(5)] if kind.startswith('list:'): # list:label;r,split,seed,edge,rect;... a = kind[5:].split(';'); lab = a[0]; out = [] for x in a[1:]: r, sp, sd, ed, rc = x.split(',') out.append((lab, int(r), sp, int(sd), ed == '1', rc)) return out if kind.startswith('one:'): # one:label,r,split,seed,edge(0/1),rect a = kind[4:].split(',') return [(a[0], int(a[1]), a[2], int(a[3]), a[4] == '1', a[5])] if kind == 'main': out = [] for s in range(5): out.append(('main311', 1, 'none', s, False)) for r in (2, 3): for sp in ('split', 'shared'): out.append(('main311', r, sp, s, False)) return out if kind == 'edge': return [('edge311', 2, 'split', s, True) for s in range(5)] raise SystemExit('check|main|edge') def one(j): label, r, sp, s, edge = j[:5] rect = j[5] if len(j) > 5 else RECT name = f'{label}_r{r}_{"split" if sp == "default" else sp}{"_edge" if edge else ""}_s{s}' # 渡さない回は Unity が split の名前にする log = os.path.join(ROOT, 'logs', name + '.log') cmd = [EXE, '-batchmode', '-nographics', '-logFile', log, '-c263Robots', str(r), '-c263Seed', str(s), '-c263Out', os.path.join(ROOT, RUNS), '-c263Label', label, '-c263Cs', CS, '-c263MaxWallMin', '60'] if r > 1 and sp != 'default': cmd += ['-c263Split', sp] if edge: cmd += ['-c263Edge', 'on'] cmd += ['-c290Rect', rect, '-c291Kiri', KIRI if rect == 'on' else 'off', '-c310Fix', FIX if rect == 'on' else 'off', '-c310Fast', FAST if rect == 'on' else 'off'] t0 = time.time() rc = subprocess.call(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) summ = os.path.join(ROOT, RUNS, name, 'summary.json') st = json.load(open(summ))['status'] if os.path.exists(summ) else 'no_summary' return dict(run=name, label=label, robots=r, split=sp, edge='on' if edge else 'off', seed=s, unity_cs=CS, exit=rc, status=st, rect=rect, kiri=KIRI if rect == 'on' else 'off', fix310=FIX if rect == 'on' else 'off', fast310=FAST if rect == 'on' else 'off', wall_s=round(time.time() - t0, 1), folder=RUNS + '/' + name) if __name__ == '__main__': kind = sys.argv[1] par = int(sys.argv[sys.argv.index('--par') + 1]) if '--par' in sys.argv else 4 with ThreadPoolExecutor(par) as ex: rows = list(ex.map(one, jobs(kind))) if os.environ.get('C310_NOINDEX'): [print(r) for r in rows]; raise SystemExit(0) idx = os.path.join(ROOT, 'index311.csv') new = not os.path.exists(idx) with open(idx, 'a', newline='', encoding='utf-8') as f: w = csv.DictWriter(f, fieldnames=list(rows[0].keys())) if new: w.writeheader() w.writerows(rows) for r in rows: print(r)