What am I supposed to pass as the source parameter to the find_negative_cycle()
method of the python networkx module? In the documentation it says to pass a list, but when I try to do so, I get the error:
TypeError: unhashable type: 'list'
you could also try to modify the function itself
https://github.com/networkx/networkx/blob/main/networkx/algorithms/shortest_paths/weighted.py#L2191
in find_negative_cycle
line 2191
pred = {source: []}
v = _inner_bellman_ford(G, [source], weight, pred=pred)
with
pred = {v: [] for v in sources}
v = _inner_bellman_ford(G, source, weight, pred=pred)
if source
is a list. I think this issue should be reported
Can you try this:
def get_sequence_upto(x):
for i in range(x):
yield i
source = get_sequence_upto([1,2,3])
find_negative_cycle(G, source )
where [1,2,3] should be your list of source
There was an error in the documentation. It should be fixed in version 2.8.1 https://github.com/networkx/networkx/issues/5610#event-6575071112
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.