def compose_panopticum(tag): filtered = icfp_api.filter_solutions(None) filtered = [ f for f in filtered if 'panopticum' not in f['tag']] # filtered = [ f for f in filtered if 'fixed-potential' not in f['tag'] ] solutions = [ read_solution(f) for f in filtered ] solutions = [ sol for sol in solutions if is_valid_solution(sol) ] pid_groups = {} for sol in solutions: pid = sol[0]['problemId'] if pid in pid_groups: pid_groups[pid].append(sol) else: pid_groups[pid] = [ sol ] for pid, group in pid_groups.items(): def merge_solutions(sol1, sol2): if len(sol1) > len(sol2): print('lengths do not match: %d' % pid) return sol1 if len(sol1) < len(sol2): print('lengths do not match: %d' % pid) return sol2 return [ merge_problems(p1, p2) for (p1, p2) in zip(sol1, sol2) ] s1 = group[0] for s2 in group: s1 = merge_solutions(s1, s2) for p in s1: p['tag'] = tag fname = '../../data/solutions/solution_%d_%s.json' % (pid, tag) with io.open(fname, 'w') as h: h.write(json.dumps(s1))
def compose_panopticum(tag): filtered = icfp_api.filter_solutions(None) filtered = [f for f in filtered if 'panopticum' not in f['tag']] # filtered = [ f for f in filtered if 'fixed-potential' not in f['tag'] ] solutions = [read_solution(f) for f in filtered] solutions = [sol for sol in solutions if is_valid_solution(sol)] pid_groups = {} for sol in solutions: pid = sol[0]['problemId'] if pid in pid_groups: pid_groups[pid].append(sol) else: pid_groups[pid] = [sol] for pid, group in pid_groups.items(): def merge_solutions(sol1, sol2): if len(sol1) > len(sol2): print('lengths do not match: %d' % pid) return sol1 if len(sol1) < len(sol2): print('lengths do not match: %d' % pid) return sol2 return [merge_problems(p1, p2) for (p1, p2) in zip(sol1, sol2)] s1 = group[0] for s2 in group: s1 = merge_solutions(s1, s2) for p in s1: p['tag'] = tag fname = '../../data/solutions/solution_%d_%s.json' % (pid, tag) with io.open(fname, 'w') as h: h.write(json.dumps(s1))
def compare(tags): table = {} # id -> row n_seeds = [ 1, 1, 10, 5, 50, 10, 50, 5, 10, 5, 1, 5, 10, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ] totals = [0] * len(tags) for i, tag in enumerate(tags): files = [x['fname'] for x in icfp_api.filter_solutions(tag)] for fname in files: ident = None with io.open(fname, 'r') as f: sols = json.loads(f.read()) score = 0 fail = False for sol in sols: if ident == None: ident = sol['problemId'] else: if ident != sol['problemId']: print('different ids in file %s: %d and %d' % (fname, ident, sol['problemId'])) fail = True break if 'score' in sol and 'pscore' in sol: score += sol['score'] + sol['pscore'] elif 'my_score' in sol: score += sol['my_score'] else: print('no score info in file %s' % fname) fail = True break if fail: continue if len(sols) != n_seeds[ident]: print( 'unexpected number of games in file %s: %d instead of %d' % (fname, len(sols), n_seeds[ident])) continue ident = int(ident) if ident not in table: table[ident] = [ident] + ['?' for _ in range(len(tags))] table[ident][i + 1] = score // len(sols) totals[i] += score // len(sols) table = list(table.values()) table.sort(key=lambda x: x[0]) table = [['id'] + tags] + table + [['Total'] + totals] #print(table) with io.open('table.html', 'w') as res: res.write(make_html(table)) print('Done!')
def compare(tags): table = {} # id -> row n_seeds = [1,1,10,5,50,10,50,5,10,5,1,5,10,1,1,1,1,1,1,1,1,1,1,1,1] totals = [0] * len(tags) for i, tag in enumerate(tags): files = [x['fname'] for x in icfp_api.filter_solutions(tag)] for fname in files: ident = None with io.open(fname, 'r') as f: sols = json.loads(f.read()) score = 0 fail = False for sol in sols: if ident == None: ident = sol['problemId'] else: if ident != sol['problemId']: print('different ids in file %s: %d and %d' % (fname, ident, sol['problemId'])) fail = True break if 'score' in sol and 'pscore' in sol: score += sol['score'] + sol['pscore'] elif 'my_score' in sol: score += sol['my_score'] else: print('no score info in file %s' % fname) fail = True break if fail: continue if len(sols) != n_seeds[ident]: print('unexpected number of games in file %s: %d instead of %d' % (fname, len(sols), n_seeds[ident])) continue ident = int(ident) if ident not in table: table[ident] = [ident] + ['?' for _ in range(len(tags))] table[ident][i+1] = score // len(sols) totals[i] += score // len(sols) table = list(table.values()) table.sort(key=lambda x: x[0]) table = [['id'] + tags] + table + [['Total'] + totals] #print(table) with io.open('table.html', 'w') as res: res.write(make_html(table)) print('Done!')