示例#1
0
def create_test_graph(n: int, seed: int) -> nx.Graph:
    internet: nx.Graph = nx.random_internet_as_graph(n, seed=seed)
    node_types: List[str] = ['source', 'destination']

    for i in range(n):
        internet.add_node(i, type=random.choice(node_types))

    return internet
示例#2
0
def apply_elmokashfi_strategy(number_of_nodes: int,
                              seed: int = 1234,
                              out_name: str = "graph") -> nx.DiGraph:
    G = nx.random_internet_as_graph(number_of_nodes, seed)
    nx.write_graphml(G, out_name + "_original.graphml")
    plot_original(G, out_name)
    G = nx.DiGraph(G)
    #insert_random_destination(G)
    correct_graph_data(G)
    return G
示例#3
0
def generate_graph_data(num_nodes, random_seed):
    """Generates a graph of 10k nodes with a 3D force layout

    This function is unused but serves as an example of how the data in
    this visualization was generated
    """
    import networkx as nx  # noqa

    g = nx.random_internet_as_graph(num_nodes, random_seed)
    node_positions = nx.fruchterman_reingold_layout(g, dim=3)

    force_layout_df = pd.DataFrame.from_records(node_positions).transpose()
    force_layout_df["group"] = [d[1]["type"] for d in g.nodes.data()]
    force_layout_df.columns = ["x", "y", "z", "group"]
    return force_layout_df
示例#4
0
    for (node, nodedata) in G.nodes.items():
        if H.nodes[node]['cluster_label'] is None:
            H.nodes[node]['cluster_label'] = cluster_number
            # print(nodedata)

            for i in nodedata['community']:
                H.nodes[i]['cluster_label'] = cluster_number

            cluster_number += 1

    G = H.copy()

# Random Internet AS Graph
if args.generation[0] == 'internet-as':
    G = nx.random_internet_as_graph(args.n * 5)
    for node in range(0, args.n * 5):
        if G.nodes[node]['type'] == 'C':
            G.remove_node(node)

# Random Partition Graph
if args.generation[0] == 'partition':
    communities = [0
                   ] * args.k if args.communities is None else args.communities
    if args.communities is None:
        for i in range(0, args.k):
            communities[i] = random.randint(args.c_min, args.c_max)

    G = nx.random_partition_graph(communities,
                                  args.p_in,
                                  args.p_out,
示例#5
0
from datetime import datetime, timedelta


result=  'bgp-data-path.csv' 
#bw_details = 'BW_OF_LINKS.csv'
fp = open(result, 'a')
fp.write("Type, Prefix, S-AS, D-AS \n")

pfx = '10.0.0.0/8' ### initial prefix from which subnets for each node is derived ###########
net = ipaddress.ip_network(pfx)

N = int(sys.argv[1])  ## number of nodes in Internet AS graph
#P = int(sys.argv[2])  ### number of prefixes per node


G = nx.random_internet_as_graph(N)
#print (G.edges(), G.nodes())

prefix_graphs = {}


prefix_len = math.ceil(math.log(N,2))
#print (prefix_len)
subnets = list(net.subnets(prefixlen_diff=prefix_len))

node_prefixes = {}

for i in G.nodes():
	node_prefixes[i] = str(subnets[i])

print (node_prefixes)
示例#6
0
def build_graph(args):
    """ Builds graph from user specified parameters or use defaults."""

    # Build graph using networkx
    if args.graph == 'karate':
        print("\nReading in karate graph...")
        G = nx.karate_club_graph()
    elif args.graph == 'internet':
        if args.nodes < 1000 or args.nodes > 5000:
            args.nodes = 1000
            print(
                "\nSize for internet graph must be between 1000 and 5000.\nSetting size to 1000.\n"
            )
        print("\nReading in internet graph of size", args.nodes, "...")
        G = nx.random_internet_as_graph(args.nodes)
    elif args.graph == 'rand-reg':
        if args.nodes < 1:
            print(
                "\nMust have at least one node in the graph.\nSetting size to 1000.\n"
            )
        if args.degree < 0 or args.degree >= args.nodes:
            print(
                "\nDegree must be between 0 and n-1. Setting size to min(4, n-1).\n"
            )
            args.degree = min(4, args.nodes - 1)
        if args.degree * args.nodes % 2 == 1:
            print("\nRequirement: n*d must be even.\n")
            if args.degree > 0:
                args.degree -= 1
                print("\nSetting degree to", args.degree, "\n")
            elif args.nodes - 1 > args.degree:
                args.nodes -= 1
                print("\nSetting nodes to", args.nodes, "\n")
            else:
                print("\nSetting nodes to 1000 and degree to 4.\n")
                args.nodes = 1000
                args.degree = 4
        print("\nGenerating random regular graph...")
        G = nx.random_regular_graph(args.degree, args.nodes)
    elif args.graph == 'ER':
        if args.nodes < 1:
            print(
                "\nMust have at least one node in the graph. Setting size to 1000.\n"
            )
            args.nodes = 1000
        if args.prob < 0 or args.prob > 1:
            print(
                "\nProbability must be between 0 and 1. Setting prob to 0.25.\n"
            )
            args.prob = 0.25
        print("\nGenerating Erdos-Renyi graph...")
        G = nx.erdos_renyi_graph(args.nodes, args.prob)
    elif args.graph == 'SF':
        if args.nodes < 1:
            print(
                "\nMust have at least one node in the graph. Setting size to 1000.\n"
            )
            args.nodes = 1000
        if args.new_edges < 0 or args.new_edges > args.nodes:
            print("\nNumber of edges must be between 1 and n. Setting to 5.\n")
            args.new_edges = 5
        print("\nGenerating Barabasi-Albert scale-free graph...")
        G = nx.barabasi_albert_graph(args.nodes, args.new_edges)
    else:
        print("\nReading in karate graph...")
        G = nx.karate_club_graph()

    return G