FFrankyy / FINDER

FINDER - FInding key players in complex Networks through DEep Reinforcement learning (Nature Machine Intelligence)
MIT License
176 stars 46 forks source link

Fixes an error when nodes were removed from the networkx graph #11

Closed jernsting closed 3 years ago

jernsting commented 3 years ago

If you create a networkx graph from an edge list where a component is disconnected, FINDER will fail and raise a std::bad_alloc.

This happened because the GenNetwork function created an array of length g.nodes(), but indexed it with the original names of the node.

Example:

>>> test = np.array([0, 0, 0, 1], [0, 0, 0, 1], [0, 0, 0, 1], [1, 1, 1, 0]])
>>> g = nx.from_numpy_array(test)
>>> g.remove_node(2)
>>> 
>>> # some more detail:
>>> a, b = zip(*g.edges())
>>> a
(0, 1)
>>> b    # <<< Here is the error!
(3, 3)
>>> len(g.nodes())
3

The resulting graph can not be processed with finder.

This patch resolves this and makes handling of such graphs possible.

jernsting commented 3 years ago

Sorry, please do not merge this pull request as I accidentally made some unintended changes.