def create_topology(a, g, arrangement, seed=0):

    start_time = time.time()
    G, local_links, global_links = tp.build_drgonfly(a=a,
                                                     p=a // 2,
                                                     h=a // 2,
                                                     gl_arrangmnt=arrangement,
                                                     g=g,
                                                     seed=seed)

    #    print("test printing the global links:")
    #    for idx, (link, props) in enumerate(global_links.items()):
    #        print(idx,link,props)
    #
    #    print("test printing the local links:")
    #    for idx, (link, props) in enumerate(local_links.items()):
    #        print(idx,link, props)

    end_time = time.time()

    print("topology creation time:", end_time - start_time)

    if ut.validate_DF(G, global_links, local_links, a, g):
        print("Valid topology")
        validity = "Valid"
    else:
        print("Invalid topology")
        validity = "Invalid"

    return G

    pass
Beispiel #2
0
def run_test_practice():
    a = 4
    h = a // 2
    Gs = [4]
    #Gs = [x for x in range(2, a*h+1 + 1)]

    #topology = "practice"
    topology = "absolute_improved"
    seed = 0
    #Gs = [129]

    for g in Gs:
        start_time = time.time()
        #print("a {}, h {}, g {}".format(a,h,g) )
        #run_test_for_a_config(a, h, g, topology)

        #build a topology
        G, local_links, global_links = tp.build_drgonfly(a=a,
                                                         p=a // 2,
                                                         h=h,
                                                         gl_arrangmnt=topology,
                                                         g=g,
                                                         seed=seed)

        #draw it
        draw_graph_circular(G)

        #get_path_stat
        #group_pair_vs_global_links_dict = generate_global_link_list_for_all_group_pairs(Graph = G, a = a)

        #min_path_for_an_SD_pair(src = 5, dst = 5, Graph = G, a = a, group_pair_vs_global_links_dict = group_pair_vs_global_links_dict)
        #SD_pairs_vs_paths = min_paths_for_all_SD_pairs(Graph = G, a = a, group_pair_vs_global_links_dict = group_pair_vs_global_links_dict)

        #path_distribution_overall(SD_pairs_vs_paths, a)

        #path_distribution_analytical(a = a, g = g, h = h)

        #print("total nodes:", len(G.nodes))

        reachability_test(Graph=G, a=a, h=h, g=g)

        end_time = time.time()
        print("total time: ", end_time - start_time)
    pass
Beispiel #3
0
def get_node_reachablity_data():
    '''
    calculates how many nodes are reachable in 1-hop, 2-hop 
    and 3-hop long min paths from each node. 
    '''
    a = 16
    h = a // 2
    #Gs = [2, 10, 20, 33]
    Gs = [x for x in range(2, a * h + 1 + 1)]

    #topology = "practice"
    topology = "absolute_improved"
    seed = 0

    records = []

    for g in Gs:
        G, local_links, global_links = tp.build_drgonfly(a=a,
                                                         p=a // 2,
                                                         h=h,
                                                         gl_arrangmnt=topology,
                                                         g=g,
                                                         seed=seed)
        records.append(reachability_test(G, a, h, g))

    results = pd.concat(records, axis=0, ignore_index=True)

    #print(results)

    folder_name = "Path_Stats/Path_Stats_2018_August"
    os.makedirs(folder_name, exist_ok=True)

    filename = "reachability_a_{}_g_{}.csv".format(a, g)

    results.to_csv(folder_name + "/" + filename, index=False)
    pass

if __name__ == "__main__":
    
    from test_jains_and_mcf import draw_graph_circular

    print("Hello world!")
    
    
    a = 4
    g = 5
    p = a//2
    arrangement = "absolute_improved"
    
    #G = create_topology(a,g,arrangement)
    G, local_links, global_links = topologies.build_drgonfly(a=a, p=a // 2, h=a // 2, gl_arrangmnt=arrangement, g=g, seed = 0)
    
    graph_adj_list = generate_graph_adjacency_list(G)
    
    group_pair_vs_global_links = get_list_of_links_between_each_group_pair(G, edge_weight = "w", a = a, g = g )
    
    paths_dj = all_pair_all_shortest_paths_djkstra(G, print_paths = False)
    
    group_pair_vs_nodes = generate_list_of_nodes_connected_to_group_pairs(graph_adj_list, a)
    
    two_hop_neighbor_list = generate_list_of_2hop_neighbors(G, group_pair_vs_global_links, edge_weight = "w", a = a, g = g)
    
    from traffic import create_random_permutation_pattern
    SDpairs = create_random_permutation_pattern(a = a, g = g, seed = 10, verbose = False)
    
    print("\nTraffic pattern:")
Beispiel #5
0
def run_test_for_a_config(a, h, g, arrg, *, seed=0):

    print(
        "\nStarting test for: a {}, h {}, g {}, arrangment {}, seed {}".format(
            a, h, g, arrg, seed))
    config = (a, h, g, arrg)

    #folder_name = "Path_Stats"
    folder_name = "TestFolder_supposedly_unimportant_data"

    os.makedirs(folder_name, exist_ok=True)

    #    file_name1 = folder_name + "/" + "a_{}_h{}_g{}_global_paths.csv".format(a,h,g)
    #    file_name2 = folder_name + "/" + "a_{}_h{}_g{}_global_paths_detailed.csv".format(a,h,g)
    #    file_name3 = folder_name + "/" + "a_{}_h{}_g{}_all_paths_overall.csv".format(a,h,g)
    file_name1 = folder_name + "/" + arrg + "_global_paths.csv"
    file_name2 = folder_name + "/" + arrg + "_global_paths_detailed.csv"
    file_name3 = folder_name + "/" + arrg + "_all_paths_overall.csv"

    if arrg == "practice":
        arrg = "absolute_improved"

    start_time = time.time()

    G, local_links, global_links = tp.build_drgonfly(a=a,
                                                     p=a // 2,
                                                     h=a // 2,
                                                     gl_arrangmnt=arrg,
                                                     g=g,
                                                     seed=seed)
    end_time = time.time()
    #print("topology creation time:", end_time - start_time)

    if ut.validate_DF(G, global_links, local_links, a, g):
        #print("Valid topology")
        validity = "Valid"
    else:
        #print("Invalid topology")
        validity = "Invalid"

    #print_graph(G)
    #draw_graph_circular(G, a = a)

    N = len(G)

    #print("\ncalling all_pair_djkstra: ")
    start_time = time.time()
    paths_djk = all_pair_all_shortest_paths_djkstra(G, edge_weight="w")
    end_time = time.time()
    #print("djkstra returned.")
    #print("execution time: ", end_time - start_time)

    get_path_len_stat(paths_djk,
                      G,
                      config,
                      seed=seed,
                      validity=validity,
                      file_name1=file_name1,
                      file_name2=file_name2,
                      file_name3=file_name3)

    #    print("\ncalling all_pair_networkx: ")
    #    start_time = time.time()
    #    paths_nx = all_pair_all_shortest_paths_networkx(G, edge_weight = "w")
    #    end_time = time.time()
    #    print("netowkrx returned.")
    #    print("execution time: ", end_time - start_time)
    #    get_path_len_stat(paths_nx, G, config, seed = seed, validity = validity, file_name1 = file_name1, file_name2 = file_name2, file_name3 = file_name3)
    pass
Beispiel #6
0
def main(link_arrngment):

    a, g, iterations, isomorfic = parse_args()
    global graphs
    links = []
    all_result = []
    #    iterations = 10

    # which = 1
    #    for g in range(9, 10):
    # plt.close('all')
    #fig, ax = plt.subplots(nrows=2, ncols=2)
    for indx, arrg in enumerate(link_arrngment):
        #print("\n\n")
        if 'random' not in arrg:
            G, local_links, global_links = TP.build_drgonfly(a=a,
                                                             p=a // 2,
                                                             h=a // 2,
                                                             gl_arrangmnt=arrg,
                                                             g=g)

            if not UT.validate_DF(G, global_links, local_links, a):
                continue

            links.append((global_links, local_links))
            G, best_results = UT.link_usage(
                G, global_links, local_links, arrg,
                list(permutations(list(G.nodes()), 2)))
            best_results['a'] = a
            best_results['g'] = g

            all_result.append(best_results)
            UT.print_the_result(G, best_results, arrg, g, a)

            #draw_graph(G, a, indx, arrg,len(link_arrngment))
            graphs.append([G, arrg])

        else:

            best_g = nx.Graph()
            best_avrage = float("inf")
            # best_avr_sh = float("inf")
            best_global_max = float("inf")
            ave_path = []
            var = []
            results = {}
            best_results = {}
            best_global_link = {}
            best_local_link = {}

            for x in tqdm(range(iterations)):
                G, local_links, global_links = TP.build_drgonfly(
                    a=a, p=a // 2, h=a // 2, gl_arrangmnt=arrg, g=g)

                if not UT.validate_DF(G, global_links, local_links, a):
                    continue

                #G, results = link_usage(G, global_links, local_links, arrg,list(permutations(list(G.nodes()),2)))
                #links.append((global_links, local_links))

                asp = nx.average_shortest_path_length(G)
                #print("avrage shortest path :",asp,"\n")
                if asp < best_avrage:
                    best_avrage = asp
                    best_g = copy.copy(G)
                    best_global_link = copy.copy(global_links)
                    best_local_link = copy.copy(local_links)
                #G, results = link_usage(G, global_links, local_links, arrg)


#                ave_path.append([results['avr_l_global']])
#                var.append([math.sqrt(np.var(results['link_load_global']))])
#                if results['over_all_load'] < best_global_max:
#                    best_g = G
#                    best_global_max = results['over_all_load']
#                    best_results = results
            if best_avrage != float("inf"):
                #print([edg for edg in list(best.edges()) if edg not in global_links and edg not in local_links])
                best_g, best_results = UT.link_usage(
                    best_g, best_global_link, best_local_link, arrg,
                    list(permutations(list(best_g.nodes()), 2)))

                best_results['a'] = a
                best_results['g'] = g
                #random_prem_flows(0best_g,global_links,local_links,arrg,best_results)

                all_result.append(best_results)
                UT.print_the_result(best_g, best_results, arrg, g, a)
                #draw_graph(best_g, a, indx, arrg,len(link_arrngment))
                graphs.append([best_g, arrg])

    thr = UT.random_perm_thro(graphs, 35, graphs[0][0].number_of_nodes(),
                              'perm')

    for x, G in enumerate(graphs):
        all_result[x]['perm_thr'] = sum(thr[x]) / len(thr[x])

    thr = UT.random_perm_thro(graphs,
                              35,
                              graphs[0][0].number_of_nodes(),
                              'shift',
                              shift=a)

    for x, G in enumerate(graphs):
        all_result[x]['shift_thr'] = sum(thr[x]) / len(thr[x])

    if isomorfic:
        UT.check_isomorphics(graphs)

    print(Style.BRIGHT)
    print(
        Back.CYAN +
        "{:<20} {:<30} {:<20} {:<20} {:<20} {:<20} {:<20} {:<20} {:<20} {:<20}"
        .format('config (a,h,g)', 'Arrangment Name', 'max load(g/l)',
                'avg load (g/l/all)', '#global links', 'avg sh path',
                'avg sh path (opt)', 'bi bw', 'rand perm thrput',
                'sh by (a) th'))

    print(Style.RESET_ALL)
    for i, v in enumerate(all_result):
        print(
            "{:<20} {:<30} {:<20} {:<20} {:<20} {:<20} {:<20} {:<20}  {:<20} {:<20}"
            .format(
                "\t(" + str(v['a']) + ',' + str(v['a'] // 2) + ',' +
                str(v['g']) + ')', v['name'],
                str(round(v['global_max'], 2)) + '/' +
                str(round(v['local_max'], 2)),
                str(round(v['avr_l_global'], 2)) + '/' +
                str(round(v['avr_l_local'], 2)) +
                "/" + str(round(v['over_all_load'], 2)),
                round(v['g_l_count'] // 2, 2), round(v['avr_shp'], 2),
                round(v['avr_shp_opt'], 2), v['bw'], round(v['perm_thr'], 2),
                round(v['shift_thr'], 2)))
    #
    # for indx,G in enumerate(graphs):
    #     draw_graph(G, a, indx, all_result[indx]['name'], len(graphs))
    print(Style.RESET_ALL)
    plt.show()
    return links, all_result
Beispiel #7
0
@author: oem
"""

import topologies as TP
import utilites as UT
import jains as JS
import convert_topsim_to_nx as CTN
import networkx as nx
import traffic as TF
import time
import numpy as np


#G = TP.build_drgonfly(16,1,16,'random',g=30)[0]
G = TP.build_drgonfly(4,1,1,'random',g=5)[0]
print(G)

sd = TF.traffic_pattrens(G.number_of_nodes(),t='all')

l1 = []

start_time = time.time()
l2 = UT.floyd_warshall_all_pairs_sp(G,weight='w')
print("\nrunning time f-w", (time.time() - start_time)," seconds")

for src,neighbors in enumerate(l2):
    print("src: ",src)
    for dst,paths in enumerate(neighbors):
        print(dst, paths)