ED_LRR/benchmark_sweep.py

85 lines
2.3 KiB
Python
Raw Normal View History

2022-02-23 21:45:59 +00:00
from tqdm import tqdm
import time
import json
import os
import statistics
def stats(values):
ret={
"max":max(values),
"min":min(values),
"mean":statistics.mean(values),
"range":abs(max(values)-min(values)),
"sum":sum(values)
}
if len(values)>1:
ret["stdev"]=statistics.stdev(values)
else:
ret["stdev"]=0
return ret
last_seen=float('inf')
pbar=None
def callback(state):
try:
global pbar,last_seen
if state['n_seen']<last_seen:
if pbar:
pbar.close()
pbar=tqdm(total=state['d_total'],unit="Ly",unit_scale=True)
last_seen=state['n_seen']
pbar.n=round(state['d_total']-state['d_rem'],2)
pbar.set_description("[J:{depth} | Q:{queue_size} | D:{d_rem:.2f} Ly | S:{n_seen} ({prc_seen:.2f}%)] {system}".format(**state))
pbar.update(0)
except Exception as e:
print(e)
if not 'callback' in vars():
callback=None
import _ed_lrr
callback=None
r=_ed_lrr.PyRouter(callback)
r.load("stars.csv")
res=[]
done=set()
if os.path.isfile("res.json"):
with open("res.json","r") as fh:
try:
res=json.load(fh)
except:
pass
for v in res:
done.add((v[0],v[1]))
systems=r.resolve_systems("Sol","Colonia")
min_dt_total=60*10
print("Warming up...")
r.route([systems['Sol'],systems['Sol']],48.0,0.0,0.0,0) # warmup
print("Done")
for g in [0.0, 0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0]:
for w in [0.0, 0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0]:
if (g,w) in done:
continue
dt=[]
lr=[]
l=0
while sum(dt)<min_dt_total:
l+=1
print({'g':g,'w':w,'l':l})
t=time.time()
route=r.route([systems['Sol'],systems['Colonia']],48.0,g,w,0)
dt.append(time.time()-t)
lr.append(len(route))
print(stats(dt))
dt=sum(dt)/len(dt)
res.append((g,w,lr,dt))
with open("res.json","w") as of:
json.dump(res,of)
# for n in range(21):
# grid=r.get_grid(1<<n)
# max_v=max(grid.items(),key=lambda v:v[1])
# mean_v=sum(grid.values())/len(grid)
# print(1<<n,len(grid),mean_v,max_v)