Beispiel #1
0
def do_ranges(options, stats, write_filepath, topo_name):

    # Grab topo to enable analysis that requires generating new metric values,
    # such as the value of one metric with a combo optimized for another one.
    '''
    topo_graph returns
        @param g: NetworkX Graph
        @param usable: boolean: locations on all nodes and connected?
        @param note: error or note about mods
    '''
    print "generating topo for: %s" % topo_name
    graph, usable, note = get_topo_graph(topo_name)
    if not usable:
        raise Exception("unusable graph?")

    if not write_filepath:
        write_filepath = get_output_filepath(options.input)

    for metric in options.metrics:

        this_write_filepath = write_filepath + '_' + metric
        xlabel = 'number of controllers (k)'

        for ptype in options.plots:
            if ptype in PLOT_FCNS.keys():
                p = PLOT_FCNS[ptype]
                #print "plotting %s" % ptype

                filepath = this_write_filepath + '_' + ptype
                aspect_fcns = get_aspect_fcns(p, stats, metric, graph)
                aspects = aspect_fcns.keys()
                aspect_colors = p['aspect_colors']
                ylabel = p['ylabel'](metric)
                min_x = p['min_x'](options) if 'min_x' in p else None
                max_x = p['max_x'](options) if 'max_x' in p else None
                min_y = p['min_y'](options) if 'min_y' in p else None
                max_y = p['max_y'](options) if 'max_y' in p else None
                ylabel2 = p['ylabel2'](metric) if 'ylabel2' in p else None
                y2_scale_factor = p['y2_scale_factor'] if 'y2_scale_factor' in p else None
                hlines = p['hlines'] if 'hlines' in p else None

                plot.ranges(stats, metric, aspects, aspect_colors, aspect_fcns,
                            "linear", "linear", None, None, filepath,
                            options.write, ext = options.ext,
                            xlabel = xlabel,
                            ylabel = ylabel,
                            min_x = min_x,
                            max_x = max_x,
                            min_y = min_y,
                            max_y = max_y,
                            ylabel2 = ylabel2,
                            y2_scale_factor = y2_scale_factor,
                            hlines = hlines)
            else:
                raise Exception("undefined ptype: %s" % ptype)

    if not options.write:
        plot.show()
Beispiel #2
0
def for_each_zoo_topo(fcn, data, max_iters = None):
    '''Execute the specified function for each topology in the zoo'''
    # Extract to just names
    topos = zoo_topos()
    t = len(topos)
    for i, topo in enumerate(topos):
        if not max_iters == None and i >= max_iters:
            break
        g = get_topo_graph(topo)
        fcn(topo, g, i, t, data)
Beispiel #3
0
 def add_to_data(name, g, i, t, data):
     g = get_topo_graph(name)
     print ">>>%s: %s of %s" % (name, i, t)
     de = GraphData(name=name,
                    n=g.number_of_nodes(),
                    e=g.number_of_edges(),
                    ad=g.number_of_edges() / float(g.number_of_nodes()),
                    ic=nx.is_connected(g),
                    c=nx.number_connected_components(g),
                    w=total_weight(g) if has_weights(g) else 0)
     data.append(de)
     print "\t" + str(de)
Beispiel #4
0
 def add_to_data(name, g, i, t, data):
     g = get_topo_graph(name)
     print ">>>%s: %s of %s" % (name, i, t)
     de = GraphData(name = name,
                    n = g.number_of_nodes(),
                    e = g.number_of_edges(),
                    ad = g.number_of_edges() / float(g.number_of_nodes()),
                    ic = nx.is_connected(g),
                    c = nx.number_connected_components(g),
                    w = total_weight(g) if has_weights(g) else 0)
     data.append(de)
     print "\t" + str(de)
Beispiel #5
0
def for_each_zoo_topo(fcn, data, max_iters=None):
    '''Execute the specified function for each topology in the zoo.
    
    @param fcn: function accepting the following params:
        @param name: topology name
        @param g: topology graph
        @param i: index
        @param t: total topologies in the zoo
        @param data: arbitrary object
    @data: data pass-through
    @param max_iters: maximum number of topologies to use (for debug)
    '''
    # Extract to just names
    topos = zoo_topos()
    t = len(topos)
    for i, topo in enumerate(topos):
        if not max_iters == None and i >= max_iters:
            break
        g = get_topo_graph(topo)
        fcn(topo, g, i, t, data)
Beispiel #6
0
def for_each_zoo_topo(fcn, data, max_iters = None):
    '''Execute the specified function for each topology in the zoo.
    
    @param fcn: function accepting the following params:
        @param name: topology name
        @param g: topology graph
        @param i: index
        @param t: total topologies in the zoo
        @param data: arbitrary object
    @data: data pass-through
    @param max_iters: maximum number of topologies to use (for debug)
    '''
    # Extract to just names
    topos = zoo_topos()
    t = len(topos)
    for i, topo in enumerate(topos):
        if not max_iters == None and i >= max_iters:
            break
        g = get_topo_graph(topo)
        fcn(topo, g, i, t, data)
Beispiel #7
0
        if not os.path.exists(dirname):
     	   os.mkdir(dirname)
        write_json_file(filename_domain+"Flowspace table" , FlowSpace_domain)
	dirname = os.path.dirname(filename_switch)
        if not os.path.exists(dirname):
    	    os.mkdir(dirname)
        write_json_file(filename_switch+"Flowspace table", FlowSpace_switch)
	dirname = os.path.dirname(filename_port)
    	if not os.path.exists(dirname):
        	os.mkdir(dirname)
       	write_json_file(filename_port + "Flowspace table", FlowSpace_port)

    '''creation of file containing acceptance ratio results and number of flowspace rules for each slicing method in /acceptance_ratio folder'''

    if options.use_prior:
        data = read_json_file(filename)
    else:
    	if options.write:
        	dirname = os.path.dirname(filename)
        	if not os.path.exists(dirname):
            		os.mkdir(dirname)
    			write_json_file(filename + 'acceptance_ratio', data)
       
    return data, filename

if __name__ == '__main__':
    options = parse_args()
    for topo in options.topos:
        g = get_topo_graph(topo)
        do_metrics(options, topo, g)
Beispiel #8
0
def do_ranges(options, stats, write_filepath, topo_name):

    # Grab topo to enable analysis that requires generating new metric values,
    # such as the value of one metric with a combo optimized for another one.
    '''
    topo_graph returns
        @param g: NetworkX Graph
        @param usable: boolean: locations on all nodes and connected?
        @param note: error or note about mods
    '''
    print "generating topo for: %s" % topo_name
    graph, usable, note = get_topo_graph(topo_name)
    if not usable:
        raise Exception("unusable graph?")

    if not write_filepath:
        write_filepath = get_output_filepath(options.input)

    for metric in options.metrics:

        this_write_filepath = write_filepath + '_' + metric
        xlabel = 'number of controllers (k)'

        for ptype in options.plots:
            if ptype in PLOT_FCNS.keys():
                p = PLOT_FCNS[ptype]
                #print "plotting %s" % ptype

                filepath = this_write_filepath + '_' + ptype
                aspect_fcns = get_aspect_fcns(p, stats, metric, graph)
                aspects = aspect_fcns.keys()
                aspect_colors = p['aspect_colors']
                ylabel = p['ylabel'](metric)
                min_x = p['min_x'](options) if 'min_x' in p else None
                max_x = p['max_x'](options) if 'max_x' in p else None
                min_y = p['min_y'](options) if 'min_y' in p else None
                max_y = p['max_y'](options) if 'max_y' in p else None
                ylabel2 = p['ylabel2'](metric) if 'ylabel2' in p else None
                y2_scale_factor = p[
                    'y2_scale_factor'] if 'y2_scale_factor' in p else None
                hlines = p['hlines'] if 'hlines' in p else None

                plot.ranges(stats,
                            metric,
                            aspects,
                            aspect_colors,
                            aspect_fcns,
                            "linear",
                            "linear",
                            None,
                            None,
                            filepath,
                            options.write,
                            ext=options.ext,
                            xlabel=xlabel,
                            ylabel=ylabel,
                            min_x=min_x,
                            max_x=max_x,
                            min_y=min_y,
                            max_y=max_y,
                            ylabel2=ylabel2,
                            y2_scale_factor=y2_scale_factor,
                            hlines=hlines)
            else:
                raise Exception("undefined ptype: %s" % ptype)

    if not options.write:
        plot.show()
Beispiel #9
0
    plt.close(fig)


def do_plot(options, stats, g, write_filepath):
    city_data = None
    if os.path.isfile(LATLONG_FILE):
        city_data = read_json_file(LATLONG_FILE)

    data = {}
    if not write_filepath:
        write_filepath = get_output_filepath(options.input)
    write_filepath += '_map_'

    print "reformatting data & doing plot..."
    for i, c in enumerate(stats['group']):
        if options.max and i >= options.max:
            break
        data[str(c)] = stats['data'][str(c)]
        metric_data = []
        for metric in options.metrics:
            metric_data.append(data[str(c)][metric]['lowest_combo'])
        write_map(g, city_data, options.metrics, metric_data, write_filepath + str(c), options.write,
                  options.ext, options.labels, color = COLORS[i])


if __name__ == "__main__":
    options = parse_args()
    print "loading JSON data..."
    stats = plot.load_stats(options)
    g, usable, note = get_topo_graph(options.input.split('/')[1])
    do_plot(options, stats, g, None)
Beispiel #10
0
    # Grab raw data
    # plot_data[ptype] = [dict of metric data, keyed by ptype]:
    # plot_data[ptype][metric] = [dict of topo data, keyed by metric]
    # each value includes:
    # x: list of sorted controller k's
    # lines: dict of y-axis lists, keyed by aspect
    plot_data = {}
    # CSV format:
    csv_fields = ['metric', 'ptype', 'name', 'topo', 'n', 'e', 'w', 'gdf_name', 'x', 'y']
    csv_tuples = []
    for i, topo in enumerate(topos):
        if not options.max == None and i >= options.max:
            break

        g, usable, note = get_topo_graph(topo)

        if usable:
            w = total_weight(g)

            # Check for --force here?
            print "usable topo: %s" % topo
            total_usable += 1
            controllers = metrics.get_controllers(g, options)
            exp_filename = metrics.get_filename(topo, options, controllers)

            path_exists = os.path.exists(exp_filename + '.json')
            compute_metrics = 'metrics' in options.operations

            # Compute data only when the following conditions hold:
            # - asked to complete metrics, AND
Beispiel #11
0
        write_filepath = get_output_filepath(options.input)
    write_filepath += "_map_"

    print "reformatting data & doing plot..."
    for i, c in enumerate(stats["group"]):
        if options.max and i >= options.max:
            break
        data[str(c)] = stats["data"][str(c)]
        metric_data = []
        for metric in options.metrics:
            metric_data.append(data[str(c)][metric]["lowest_combo"])
        write_map(
            g,
            city_data,
            options.metrics,
            metric_data,
            write_filepath + str(c),
            options.write,
            options.ext,
            options.labels,
            color=COLORS[i],
        )


if __name__ == "__main__":
    options = parse_args()
    print "loading JSON data..."
    stats = plot.load_stats(options)
    g, usable, note = get_topo_graph(options.input.split("/")[1])
    do_plot(options, stats, g, None)
Beispiel #12
0
        for i in [10, 100, 1000]:
            metrics.run_best_n(data, g, apsp, i, options.weighted)
            metrics.run_worst_n(data, g, apsp, i, options.weighted)

    print(
        "*******************************************************************")

    # Ignore the actual combinations in CSV outputs as well as single points.
    exclude = ["distribution", "metric", "group", "id"]
    if not options.write_combos:
        exclude += ['highest_combo', 'lowest_combo']

    if options.write:
        dirname = os.path.dirname(filename)
        if not os.path.exists(dirname):
            os.mkdir(dirname)
        write_json_file(filename + '.json', data)
        if options.write_csv:
            write_csv_file(filename, data["data"], exclude=exclude)
            if options.write_dist:
                write_dist_csv_file(filename + '_dist', data["data"], exclude)

    return data, filename


if __name__ == '__main__':
    options = parse_args()
    for topo in options.topos:
        g = get_topo_graph(topo)
        do_metrics(options, topo, g)