Get oriented path in python networkx

I want to get only a directional path between two nodes in a directional G using networkx.

I am currently doing this:

G=nx.fast_gnp_random_graph(NUMBER_OF_NODES,PPROB_OF_EDGE,True)
nx.bidirectional_dijkstra(G,u, v) #u and v are some nodes in G

This will return the path even if the list of edges of G has only the following entries

[(u,w),(v,w)]

My goal is to get only a directional path. Is there a way in networkx to do this?

+4
source share
1 answer

When you do

G=nx.fast_gnp_random_graph(NUMBER_OF_NODES,PPROB_OF_EDGE,True)

you will get an undirected graph. Thus, the edge (u,w)is an undirected edge --- there is no difference between (u,w)and (w,u). It makes no sense to talk about a "directional path."

, , , True . - , nx.fast_gnp_random_graph , , .

G = nx.fast_gnp_random_graph(NUMBER_OF_NODES, PROB_OF_EDGE, directed=True)

( , , python).

+2

Source: https://habr.com/ru/post/1675427/


All Articles