File size: 1,459 Bytes
248ea7d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env python3
"""Supplement: reuse the installed generator rather than rebuild it per query.

This deployment regime was specified AFTER the primary experiment. New seeds
are used for its assessment. It does not replace or conceal the cold-start result.
"""
from collections import deque
from engine import Guard
import time


def search_installed(generators, guard: Guard | None, expansions=6000, wall_budget=None):
 start=time.perf_counter();ident=tuple(range(len(generators[0])))
 best={ident:()};products=0;popped=0
 if guard is None:
  todo=deque([(ident,())])
  while todo and popped<expansions:
   if wall_budget is not None and time.perf_counter()-start>=wall_budget:break
   sig,w=todo.popleft();popped+=1
   for a,g in enumerate(generators):
    value=tuple(g[x] for x in sig);products+=1
    if value not in best:
     child=w+(a,);best[value]=child;todo.append((value,child))
 else:
  todo=deque([(ident,(),0)])
  while todo and popped<expansions:
   if wall_budget is not None and time.perf_counter()-start>=wall_budget:break
   sig,w,state=todo.popleft();popped+=1
   for a,g in enumerate(generators):
    ns=guard.next[state][a]
    if guard.bad[ns]:continue
    value=tuple(g[x] for x in sig);products+=1
    if value not in best:
     child=w+(a,);best[value]=child;todo.append((value,child,ns))
 return {'known_semantics':len(best),'products':products,'popped':popped,
         'wall_seconds':time.perf_counter()-start,'best':best}