homework.py
def aris_distance(author_id: int, reduced: bool = False):
    '''
    Gets the shortest distance between author_id and Aris
    Args:
        author_id: The integer id of an author
        reduced: If reduced equals true it will use the reduced data
            to create the graph, otherwise it will use the full data
    '''
    graph = Graph(reduced)
    author_name = graph.get_author_name(author_id)
    print("Getting shortest path weight between {} and Aris\n".format(author_name))
    path = graph.aris_distance(author_id)
    edge_labels = []
    if path is not None:
        aris_graph = nx.Graph()
        aris_graph.add_node(path[0][2])
        for i in range(0, len(path)-1):
            current = path[i]
            next_n = path[i+1]
            aris_graph.add_node(next_n[2])
            aris_graph.add_edge(current[2], next_n[2], {"weight":next_n[1]})
            edge_labels.append(((current[2], next_n[2]), round(abs(current[1]-next_n[1]), 2)))
        pos = nx.fruchterman_reingold_layout(aris_graph)
        cmap = plt.cm.get_cmap('hsv', len(path)+1)
        plt.figure(figsize=(16, 12))
        nx.draw_networkx_edge_labels(aris_graph, pos, edge_labels=dict(edge_labels))
        for index, value in enumerate(path):
            color = cmap(index)
            nx.draw_networkx(aris_graph, pos=pos, nodelist=[value[2]], node_color=color,
                             with_labels=True, node_size=1500)
        plt.title('Shortest path between Aris and {} = {}'\
            .format(author_name, str(round(path[-1][1], 4))))
        plt.show()
    else:
        print("There is no path between Aris and {}".format(author_name))

    Gets the shortest distance between author_id and Aris
    Args:
        author_id: The integer id of an author
        reduced: If reduced equals true it will use the reduced data
            to create the graph, otherwise it will use the full data
    
Gets the shortest distance between author_id and Aris
Gets the shortest distance between author_id and Aris
def aris_distance(author_id: int, reduced: bool = False):
    graph = Graph(reduced)
    author_name = graph.get_author_name(author_id)
    print("Getting shortest path weight between {} and Aris\n".format(author_name))
    path = graph.aris_distance(author_id)
    edge_labels = []
    if path is not None:
        aris_graph = nx.Graph()
        aris_graph.add_node(path[0][2])
        for i in range(0, len(path)-1):
            current = path[i]
            next_n = path[i+1]
            aris_graph.add_node(next_n[2])
            aris_graph.add_edge(current[2], next_n[2], {"weight":next_n[1]})
            edge_labels.append(((current[2], next_n[2]), round(abs(current[1]-next_n[1]), 2)))
        pos = nx.fruchterman_reingold_layout(aris_graph)
        cmap = plt.cm.get_cmap('hsv', len(path)+1)
        plt.figure(figsize=(16, 12))
        nx.draw_networkx_edge_labels(aris_graph, pos, edge_labels=dict(edge_labels))
        for index, value in enumerate(path):
            color = cmap(index)
            nx.draw_networkx(aris_graph, pos=pos, nodelist=[value[2]], node_color=color,
                             with_labels=True, node_size=1500)
        plt.title('Shortest path between Aris and {} = {}'\
            .format(author_name, str(round(path[-1][1], 4))))
        plt.show()
    else:
        print("There is no path between Aris and {}".format(author_name))
def aris_distance ( author_id : int , reduced : bool = False ) : graph = Graph ( reduced ) author_name = graph . get_author_name ( author_id ) print ( "Getting shortest path weight between {} and Aris\n" . format ( author_name ) ) path = graph . aris_distance ( author_id ) edge_labels = [ ] if path is not None : aris_graph = nx . Graph ( ) aris_graph . add_node ( path [ 0 ] [ 2 ] ) for i in range ( 0 , len ( path ) - 1 ) : current = path [ i ] next_n = path [ i + 1 ] aris_graph . add_node ( next_n [ 2 ] ) aris_graph . add_edge ( current [ 2 ] , next_n [ 2 ] , { "weight" : next_n [ 1 ] } ) edge_labels . append ( ( ( current [ 2 ] , next_n [ 2 ] ) , round ( abs ( current [ 1 ] - next_n [ 1 ] ) , 2 ) ) ) pos = nx . fruchterman_reingold_layout ( aris_graph ) cmap = plt . cm . get_cmap ( 'hsv' , len ( path ) + 1 ) plt . figure ( figsize = ( 16 , 12 ) ) nx . draw_networkx_edge_labels ( aris_graph , pos , edge_labels = dict ( edge_labels ) ) for index , value in enumerate ( path ) : color = cmap ( index ) nx . draw_networkx ( aris_graph , pos = pos , nodelist = [ value [ 2 ] ] , node_color = color , with_labels = True , node_size = 1500 ) plt . title ( 'Shortest path between Aris and {} = {}' . format ( author_name , str ( round ( path [ - 1 ] [ 1 ] , 4 ) ) ) ) plt . show ( ) else : print ( "There is no path between Aris and {}" . format ( author_name ) )
Gets the shortest distance between author_id and Aris
Gets the shortest distance between author_id and Aris
'''
    Gets the shortest distance between author_id and Aris
    Args:
        author_id: The integer id of an author
        reduced: If reduced equals true it will use the reduced data
            to create the graph, otherwise it will use the full data
    '''
author_id
int
The integer id of an author
The integer id of an author
reduced
bool
If reduced equals true it will use the reduced data
to create the graph, otherwise it will use the full data
If reduced equals true it will use the reduced data to create the graph otherwise it will use the full data