Beispiel #1
0
def repeat_find_cover(graph, find_path, r=100):
    scores = []
    verts = graph.vertices
    edges = graph.edgelist
    print("V: %s, E: %s" % (len(verts), len(edges)))
    limit = len(verts) * sum(graph[v].value for v in (verts))
    for i in range(r):
        caller = supress_stdout(find_cover)
        random.seed(i)
        try:
            np.random.seed(i)
        except Exception:
            pass  # no numpy
        res = caller(deepcopy(graph), find_path)
        total = sum(score for (score, path) in res.itervalues())
        print("Score for R-%s: %s" % (i, total))
        scores.append(total)
        if total == limit:
            print("Reached theoretical limit of %s" % limit)
            break
    print(scores)
    try:
        print(np.median(scores), np.mean(scores), np.max(scores))
    except Exception:
        print("Max Score: %s" % max(scores))
    return scores
Beispiel #2
0
def find_and_save_path(name, seed):
    edges, perfs = validate_file(name)
    graph = make_weighted_graph(edges, perfs)
    caller = supress_stdout(find_cover)
    random.seed(seed)
    res = caller(deepcopy(graph), find_sets)
    outname = "%s_path_%s.txt" % (name.replace(".in", ""), str(seed).zfill(4))
    save_path(res, outname)
Beispiel #3
0
def find_and_save_path(filename, seed):
    fpath = "final_inputs/%s" % filename
    graph = make_weighted_graph(*validate_file(fpath))
    random.seed(seed)
    caller = supress_stdout(find_cover)
    res = caller(deepcopy(graph), find_sets)
    outname = "paths/%s_%s_hail.txt" % (filename.replace(".in", ""), str(seed).zfill(4))
    save_path(res, outname)