Exemplo n.º 1
0
def _execute(density):
    num_process = 10
    batch_size = 20
    pool = multiprocessing.Pool(processes=num_process)
    pool.map(Worker(density, batch_size), range(num_process))
    pool.close()
    pool.join()

    results = {
        'ff': [],
        'pq': [],
        'ek': [],
        'df': [],
        'cs': [],
        'pr': [],
        'rf': []
    }
    for i in range(num_process):
        res = json.load(open(util.get_out_file('worker', '%s_%d.txt' % (density, i+1))))
        for k, v in res.items():
            results[k].extend(v)
    with open(util.get_out_file('%s.txt' % density), 'w') as f:
        json.dump(results, f)

    print '%s DONE' % density.upper()
Exemplo n.º 2
0
def draw_bar(means, density):
    from matplotlib import rcParams
    rcParams.update({'figure.autolayout': True})

    ind = np.arange(len(means))  # the x locations for the groups
    width = 0.35       # the width of the bars

    fig, ax = plt.subplots()
    rects = ax.bar(ind, means, width, color='g')

    # add some text for labels, title and axes ticks
    ax.set_ylabel('Milliseconds')
    ax.set_title('Average running time on %s networks' % density)
    ax.set_xticks(ind+width)
    ax.set_xticklabels(('Ford-Fulkerson', 'Edmonds-Karp', 'Capacity scaling', 'Generic push relabel', 'Relabel to front'),
                       rotation=40, ha='right', fontsize=10)

    def autolabel(rects):
        # attach some text labels
        for i, rect in enumerate(rects):
            height = rect.get_height()
            ax.text(rect.get_x()+rect.get_width()/2., height + 0.05, '%d' % means[i],
                    ha='center', va='bottom')

    autolabel(rects)

    plt.savefig(util.get_out_file('chart', '%s.png' % density))
Exemplo n.º 3
0
    def __call__(self, ord):
        self._ord = ord + 1
        self._start = ord * self._batch_size + 1
        results = self._run_batch()
        with open(util.get_out_file('worker', 'sparse_%d.txt' % self._ord), 'w') as f:
            json.dump(results, f)

        print "WORKER %d DONE" % self._ord
Exemplo n.º 4
0
def _run_by_density(density, maxflow_func):
    results = [_run_maxflow(maxflow_func, '%s_%d.txt' % (density, i+1)) for i in range(200)]
    return results


def _run_batch(density):
    results = {
        'ek': _run_by_density(density, maxflow.edmonds_karp),
        'df': _run_by_density(density, maxflow.edmonds_karp_dfs),
        'ff': _run_by_density(density, maxflow.ford_fulkerson),
        'pq': _run_by_density(density, maxflow.ford_fulkerson_pq),
        'cs': _run_by_density(density, maxflow.capacity_scaling),
        'pr': _run_by_density(density, maxflow.generic_push_relabel),
        'rf': _run_by_density(density, maxflow.relabel_to_front)
    }
    return results

if __name__ == '__main__':
    sparse_results = _run_batch('sparse')
    with open(util.get_out_file('sparse.txt'), 'w') as f:
        json.dump(sparse_results, f)

    medium_results = _run_batch('medium')
    with open(util.get_out_file('medium.txt'), 'w') as f:
        json.dump(medium_results, f)

    dense_results = _run_batch('dense')
    with open(util.get_out_file('dense.txt'), 'w') as f:
        json.dump(dense_results, f)