예제 #1
0
def get_path_network(G, listNodes, path_length_cutoff=10000):
    """
    Returns a subgraph containing only nodes in listNodes

    Nodes are connected if exist a path between them, and weight of the edge consists in the length of shortest path

    If the shortest between two nodes includes another node in the list, this edge is not added
    """
    # First, check all nodes in listNodes are in network
    new_graph = networkx.MultiGraph()

    for x in xrange(len(listNodes)):
        for y in xrange(x):
            sp = networkx.shortest_path(G, listNodes[x], listNodes[y])
            if sp:
                if (len(sp)-1)<=path_length_cutoff:
                    if len(set(listNodes).intersection(set(sp[1:-1])))==0:
                        new_graph.add_edge(listNodes[x],listNodes[y],len(sp)-1)
            
    return new_graph
예제 #2
0
def get_path_network(G, listNodes, path_length_cutoff=10000):
    """
    Returns a subgraph containing only nodes in listNodes

    Nodes are connected if exist a path between them, and weight of the edge consists in the length of shortest path

    If the shortest between two nodes includes another node in the list, this edge is not added
    """
    # First, check all nodes in listNodes are in network
    new_graph = networkx.MultiGraph()

    for x in xrange(len(listNodes)):
        for y in xrange(x):
            sp = networkx.shortest_path(G, listNodes[x], listNodes[y])
            if sp:
                if (len(sp) - 1) <= path_length_cutoff:
                    if len(set(listNodes).intersection(set(sp[1:-1]))) == 0:
                        new_graph.add_edge(listNodes[x], listNodes[y],
                                           len(sp) - 1)

    return new_graph
예제 #3
0
def get_shortest_path_between(G, source_id, target_id):
    return networkx.shortest_path(G, source_id, target_id)
예제 #4
0
def get_shortest_path_between(G, source_id, target_id):
    return networkx.shortest_path(G, source_id, target_id)