def par2(api: GBD, query, runtimes, timeout, divisor): for name in runtimes: times = api.query_search(query, [], [name]) div = len(times) if divisor is None else divisor par2 = sum(float(time[1]) if util.is_number(time[1]) and float(time[1]) < timeout else 2*timeout for time in times) / div solved = sum(1 if util.is_number(time[1]) and float(time[1]) < timeout else 0 for time in times) print(str(round(par2, 2)) + " " + str(solved) + "/" + str(div) + " " + name) times = api.query_search(query, [], runtimes) div = len(times) if divisor is None else divisor vbs_par2 = sum([min(float(val) if util.is_number(val) and float(val) < timeout else 2*timeout for val in row[1:]) for row in times]) / div solved = sum(1 if t < timeout else 0 for t in [min(float(val) if util.is_number(val) else 2*timeout for val in row[1:]) for row in times]) print(str(round(vbs_par2, 2)) + " " + str(solved) + "/" + str(div) + " VBS")
def calculate_par2_score(self, query, feature): info = self.database.meta_record(feature) if not "timeout" in info: eprint( "Time-limit 'timeout' missing in meta-record of table '{}'.". format(feature)) eprint("Unable to calculate score.") return if not "memout" in info: eprint( "Memory-limit 'memout' missing in meta-record of table '{}'.". format(feature)) if not "machine" in info: eprint( "Machine-id 'machine' missing in meta-record of table '{}'.". format(feature)) timeout = int(info["timeout"]) times = self.query_search(query, [], [feature]) score = 0 penalized = set() for time in times: if is_number(time[1]): score += int(time[1]) else: score += 2 * timeout penalized.add(time[1]) print(score / len(times)) print(penalized)
def greedy_comb(api: GBD, query, runtimes, timeout, size): result = api.query_search(query, [], runtimes) result = [[float(val) if util.is_number(val) and float(val) < float(timeout) else 2*timeout for val in row] for row in result] runtimes.insert(0, "dummy") for comb in combinations(range(1, len(runtimes)), size): comb_par2 = sum([min(itemgetter(*comb)(row)) for row in result]) / len(result) print(str(itemgetter(*comb)(runtimes)) + ": " + str(comb_par2))
def table_values(self, table): result = {"numeric": [None, None], "discrete": []} values = self.value_query( 'SELECT DISTINCT value FROM {}'.format(table)) for val in values: if is_number(val): value = float(val) if result["numeric"][0] == None: result["numeric"] = [value, value] elif value < result["numeric"][0]: result["numeric"][0] = value elif value > result["numeric"][1]: result["numeric"][1] = value else: result["discrete"].append(val) return result
def optimal_comb(api: GBD, args): result = api.query_search(args.query, [], args.runtimes) result = [[ int(float(val)) if is_number(val) and float(val) < float(args.tlim) else int(2 * args.tlim) for val in row[1:] ] for row in result] cnf = dimacs.DIMACSPrinter() _ACT = [cnf.create_literal() for _ in range(0, len(args.runtimes))] _MAX = get_bitvector(cnf, int(pow(2, _BW - 1) - 1)) for c in encode_at_most_k_constraint_ltseq(cnf, args.size, _ACT): cnf.consume_clause(c) # encode row-wise minima MINS = [] for row in result: i = 0 B0_ = get_bitvector(cnf, int(row[0])) B0 = if_then_else(cnf, B0_, _MAX, _ACT[i]) for rt in row[1:]: i = i + 1 B1_ = get_bitvector(cnf, int(rt)) B1 = if_then_else(cnf, B1_, _MAX, _ACT[i]) Bcarry = get_carry_bits(cnf, B1, [-i for i in B0]) Bmin = if_then_else(cnf, B0, B1, Bcarry[_BW - 1]) B0 = Bmin MINS.append(B0) # B0 is now minimum of row # encode sum of minima A = MINS[0] for B in MINS[1:]: SUM = get_sum_bits(cnf, A, B) A = SUM solver = Cadical(bootstrap_with=cnf.clauses, with_proof=False) result = solver.solve() if result == True: model = solver.get_model() print(slice_model(model, _ACT)) print(decode_bitvector(slice_model(model, A)))
def optimal_comb(api: GBD, query, runtimes, timeout, k): result = api.query_search(query, [], runtimes) result = [[ int(float(val)) if is_number(val) and float(val) < float(timeout) else int(2 * timeout) for val in row[1:] ] for row in result] dataset = pd.DataFrame(result, columns=runtimes) dataset = dataset[(dataset != 2 * timeout).any(axis='columns')] model = mip.Model() instance_solver_vars = [[ model.add_var(f'x_{i}_{j}', var_type=mip.BINARY) for j in range(dataset.shape[1]) ] for i in range(dataset.shape[0])] solver_vars = [ model.add_var(f's_{j}', var_type=mip.BINARY) for j in range(dataset.shape[1]) ] for var_list in instance_solver_vars: # per-instance constraints model.add_constr(mip.xsum(var_list) == 1) for j in range(dataset.shape[1]): # per-solver-constraints model.add_constr( mip.xsum(instance_solver_vars[i][j] for i in range(dataset.shape[0])) <= dataset.shape[0] * solver_vars[j]) # "Implies" in Z3 model.add_constr(mip.xsum(solver_vars) <= k) model.objective = mip.minimize( mip.xsum(instance_solver_vars[i][j] * int(dataset.iloc[i, j]) for i in range(dataset.shape[0]) for j in range(dataset.shape[1]))) print(dataset.sum().min()) print(model.optimize()) print(model.objective_value) for index, item in enumerate([var.x for var in solver_vars]): if item > 0: print(runtimes[index])
def vbs(api: GBD, query, runtimes, timeout, separator): result = api.query_search(query, [], runtimes) resultset = [(row[0], min(float(val) if util.is_number(val) else 2*timeout for val in row[1:])) for row in result] for result in resultset: print(separator.join([(str(item or '')) for item in result]))
def cdf(api: GBD, query, runtimes, timeout, title): plt.rcParams.update({'font.size': 8}) result = api.query_search(query, [], runtimes) result = [[ float(val) if util.is_number(val) and float(val) < float(timeout) else timeout for val in row[1:] ] for row in result] df = pd.DataFrame(result) df.columns = runtimes df['vbs'] = df[runtimes].min(axis=1) print(df) plt.rcParams['axes.prop_cycle'] = plt.cycler(color=coolors2 + coolors) params = { 'legend.fontsize': 'small', 'axes.labelsize': 6, 'axes.titlesize': 6, 'xtick.labelsize': 6, 'ytick.labelsize': 6, 'axes.titlepad': 10 } plt.rcParams.update(params) fig = plt.figure() ax = fig.add_subplot(111) plt.xlim(0, timeout + 100) plt.grid(linestyle='-', linewidth=.5) plt.axvline(x=timeout, linestyle='dashed', color='black', linewidth=.5) #plt.ylim(0, len(result)) # Build Title if (title is None): title = [] for elem in query.split('=')[1:]: parts = elem.strip().split(' ') title = title + [parts[0].replace('_', ' ').title()] ax.set_title(", ".join(title), fontsize=6, variant='small-caps') else: ax.set_title(title, fontsize=6, variant='small-caps') df2 = pd.DataFrame(index=range(timeout + 100), columns=runtimes) df2.fillna(0) for col in ['vbs'] + runtimes: df2[col] = [0] * (timeout + 100) for val in df[col]: if val < timeout: df2.loc[round(val), col] = df2[col][round(val)] + 1 sum = 0 for val in range(1, timeout + 100): df2.loc[val, col + "_"] = NaN if df2[col][val] != 0: df2.loc[val, col + "_"] = sum sum = sum + df2.loc[val, col] df2.loc[val, col] = sum markers = itertools.cycle([ 'o', 'v', '^', '<', '>', 'p', 'P', '*', 'h', 'H', '8', 'X', 'd', 'D', 's' ]) #next(markers) #next(markers) order = len(runtimes) + 1 for col in ['vbs'] + runtimes: color = next(ax._get_lines.prop_cycler)['color'] ax.plot(df2[col], zorder=order, linestyle='-', linewidth=.5, color=color) ax.plot(df2[str(col) + "_"], label=col, zorder=order, fillstyle='none', marker=next(markers)[0], alpha=.9, markeredgewidth=.5, markersize=3, drawstyle='steps-post', color=color) order = order - 1 plt.legend(ncol=2, loc='lower right') plt.savefig('out.svg', transparent=True, bbox_inches='tight', pad_inches=0) plt.show()