Ejemplo n.º 1
0
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")
Ejemplo n.º 2
0
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))
Ejemplo n.º 3
0
Archivo: init.py Proyecto: Udopia/gbd
def init_local(api: GBD, root):
    clocal = util.prepend_context("local", api.context)
    api.database.create_feature(clocal, permissive=True)
    sanitize = [
        path[0] for path in api.query_search(group_by=clocal)
        if not isfile(path[0])
    ]
    if len(sanitize) and confirm(
            "{} files not found. Remove stale entries from local table?".
            format(len(sanitize))):
        for paths in slice_iterator(sanitize, 1000):
            api.database.delete_values("local", paths)
    resultset = []
    #if clocal in api.get_features():
    for suffix in config.suffix_list(api.context):
        for path in glob.iglob(root + "/**/*" + suffix, recursive=True):
            if not len(api.query_search("{}='{}'".format(clocal, path))):
                resultset.append(("", path))
    run(api, resultset, compute_hash, api.get_limits())
Ejemplo n.º 4
0
Archivo: init.py Proyecto: Udopia/gbd
def init_transform_cnf_to_kis(api: GBD, query, hashes, max_edges, max_nodes):
    api.database.create_feature('kis_local', permissive=True)
    api.database.create_feature('kis_nodes', "empty", permissive=True)
    api.database.create_feature('kis_edges', "empty", permissive=True)
    api.database.create_feature('kis_k', "empty", permissive=True)
    api.database.create_feature('cnf_to_kis', permissive=True)
    api.database.create_feature('kis_to_cnf', permissive=True)
    resultset = api.query_search(query, hashes, ["local"], collapse="MIN")
    run(api, resultset, transform_cnf_to_kis, {
        **api.get_limits(), 'max_edges': max_edges,
        'max_nodes': max_nodes
    })
Ejemplo n.º 5
0
Archivo: init.py Proyecto: Udopia/gbd
def init_networkit_features(api: GBD, query, hashes):
    try:
        import networkit as nk
    except ImportError as e:
        raise GBDException(
            "Module 'networkit' not found. Setup https://networkit.github.io/")
    nk.setNumberOfThreads(min(multiprocessing.cpu_count(), api.jobs))
    resultset = api.query_search(query, hashes, ["local"], collapse="MIN")
    for (hash, local) in resultset:
        result = networkit_features(hash, local, {})
        eprint(result['hashvalue'])
        for att in result['attributes']:
            eprint(att[1] + "=" + att["2"])
Ejemplo n.º 6
0
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)))
Ejemplo n.º 7
0
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])
Ejemplo n.º 8
0
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]))
Ejemplo n.º 9
0
def scatter(api: GBD, query, runtimes, timeout, groups):
    plt.rcParams.update({'font.size': 6})
    fig = plt.figure()
    ax = fig.add_subplot(111)
    ax.set_aspect('equal', adjustable='box')
    plt.axline((0, 0), (1, 1), linewidth=0.5, color='grey', zorder=0)
    plt.axhline(y=timeout,
                xmin=0,
                xmax=1,
                linewidth=0.5,
                color='grey',
                zorder=0)
    plt.axvline(x=timeout,
                ymin=0,
                ymax=1,
                linewidth=0.5,
                color='grey',
                zorder=0)
    plt.xlabel(runtimes[0], fontsize=8)
    plt.ylabel(runtimes[1], fontsize=8)
    markers = itertools.cycle(plt.Line2D.markers.items())
    next(markers)
    next(markers)
    plt.rcParams['axes.prop_cycle'] = plt.cycler(color=coolors)
    if not groups:
        groups = []

    result = api.query_search(query, [], runtimes)
    dfall = pd.DataFrame(result, columns=["hash"] + runtimes)
    for r in runtimes:
        dfall[r] = pd.to_numeric(dfall[r], errors='coerce')
        dfall.loc[(dfall[r] >= timeout) | pd.isna(dfall[r]), r] = timeout
    print(dfall)

    plots = []
    title = []
    for g in groups:
        color = next(ax._get_lines.prop_cycler)['color']
        marker = next(markers)[0]

        result = api.query_search(query + " and (" + g + ")", [], runtimes)
        df = pd.DataFrame(result, columns=["hash"] + runtimes)
        for r in runtimes:
            df[r] = pd.to_numeric(df[r], errors='coerce')
            df.loc[(df[r] >= timeout) | pd.isna(df[r]), r] = timeout
        dfall = pd.concat([dfall, df]).drop_duplicates(keep=False)

        plots = plots + [
            plt.scatter(data=df,
                        x=runtimes[0],
                        y=runtimes[1],
                        c=color,
                        marker=marker,
                        alpha=0.7,
                        linewidth=0.7,
                        zorder=2)
        ]
        title = title + [g]

    plt.scatter(data=dfall,
                x=runtimes[0],
                y=runtimes[1],
                marker='.',
                alpha=0.7,
                linewidth=0.7,
                color="black",
                zorder=1)

    plt.legend(tuple(plots),
               tuple(title),
               scatterpoints=1,
               bbox_to_anchor=(0., 1.02, 1., .102),
               loc='lower left',
               ncol=5,
               mode="expand",
               borderaxespad=0.)
    plt.savefig('out.svg', transparent=True, bbox_inches='tight', pad_inches=0)
    plt.show()
Ejemplo n.º 10
0
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()
Ejemplo n.º 11
0
Archivo: init.py Proyecto: Udopia/gbd
def init_iso_hash(api: GBD, query, hashes):
    if not api.feature_exists("isohash"):
        api.create_feature("isohash", "empty")
    resultset = api.query_search(query, hashes, ["local"], collapse="MIN")
    run(api, resultset, compute_iso_hash, api.get_limits())
Ejemplo n.º 12
0
Archivo: init.py Proyecto: Udopia/gbd
def init_gate_features(api: GBD, query, hashes):
    resultset = api.query_search(query, hashes, ["local"], collapse="MIN")
    run(api, resultset, gate_features, api.get_limits())
Ejemplo n.º 13
0
Archivo: gbd.py Proyecto: Udopia/gbd
def cli_get(api: GBD, args):
    resultset = api.query_search(args.query, args.hashes, args.resolve,
                                 args.collapse, args.group_by)
    for result in resultset:
        print(args.separator.join([(str(item or '')) for item in result]))