Esempio n. 1
0
def print_graph_data(graph, name=""):
    out_degrees = m1project.compute_out_degrees(graph)
    in_degrees = m1project.compute_in_degrees(graph)

    num_nodes = len(graph.keys())
    total_in_degrees = sum(in_degrees.values())
    total_out_degrees = sum(out_degrees.values())

    if name is not "":
        print "graph:", name
    print "num nodes: ", str(num_nodes)
    print "total out degree: " + str(total_out_degrees)
    print "total in degree: " + str(total_in_degrees)
    print "average out-degree: " + str(float(total_out_degrees) / num_nodes)
    print "average in-degree: " + str(float(total_in_degrees) / num_nodes)
    print
Esempio n. 2
0
            provided.delete_node(graph, u)

    return attack_order

# import graph_data as gd
# print fast_targeted_order(gd.GRAPH2)
# quit()

"""
generate graph data for use in the questions
"""
# get the network graph
net_g = utils.read_graph_data("alg_rf7.txt")

# generate a upa graph with the given average out-degree
total_out_degrees = sum(m1project.compute_out_degrees(net_g).values())
average_degree = float(total_out_degrees) / len(net_g) / 2
m = int(round(average_degree))
upa_g = upa_graph(len(net_g), m)

# create an ER ugraph
network_size = len(net_g)
total_possible_edges = (network_size * (network_size - 1)) / 2
p = total_out_degrees / float(total_possible_edges) / 2
er_g = generate_random_ugraph(len(net_g), p)

# utils.print_graph_data(net_g, name="net_g")
# utils.print_graph_data(upa_g, name="upa_g")
# utils.print_graph_data(er_g, name="er_g")