Skip to content Skip to sidebar Skip to footer

Why My Graphs Are Not Bipartite, Thought I Create Them As Bipartite Using Corresponding Networkx Function?

I have written a function: B = nx.Graph() B.add_nodes_from([1, 2, 3, 4], bipartite=0) B.add_nodes_from(['a', 'b', 'c'], bipartite=1) B.add_edges_from([(1, 'a'), (1, 'b'), (2, 'b'),

Solution 1:

You've assigned the nodes an attribute bipartite=0 or 1. However, that's just an attribute of the nodes. You can assign them any attribute you want, with any name (a color, a weight, a species name, etc) - it has no impact on what edges exist. In particular, there's no special attention paid to the name of the attribute. You've named an attribute 'bipartite', but as far as the networkx commands are concerned you could have just as easily named that attribute 'fubar'. It doesn't care.

You added an edge between nodes 1 and 2. Networkx won't look at the attributes of the graph and make a choice to refuse to allow you the edge you asked it to create.

In your case, I think the answer to your question is that there doesn't seem to be a point in setting an attribute named 'bipartite'.

Post a Comment for "Why My Graphs Are Not Bipartite, Thought I Create Them As Bipartite Using Corresponding Networkx Function?"