I am trying to write a function that calculates the maximum number of unexplored cells in a grid that is reachable within a given fuel limit. For example I have a 10x10 grid, and each cell in the grid is connected to each other and their weight is the Manhattan distance between them. From this grid I create an adjacency matrix whose dimensions are then 100x100, and create a graph from the adjacency matrix using the networkx library. I then use the all_simple_paths function which returns a generator that contains all the paths from a source to a target node.
Now comes the problem, when trying to sort through this generator in order to find the path that contains the most unexplored cells (in this case just equal to the path length), my program either runs out of memory, or it takes a really long time to execute.
I have tried to convert the generator into a list, and then sort the list from longest to shortest path length, but this just causes the python script to keep growing in memory size until it takes all available memory on my PC (16GB). I have also tried using the sorted function to sort the generator as below, but this just takes too long to execute, and eventually runs out of memory as well.
```
G = nx.from_numpy_array(A)
sorted_paths = sorted(nx.all_simple_paths(G, source=current_node, target=target_node), key=len, reverse=True)
```
If anybody has any suggestions as to how I can tackle my problem, it would be greatly appreciated. Whether it be sorting the generator, or maybe another function inside networkx/another python library that could help me find the max number of unexplored cells in a grid.
--
You received this message because you are subscribed to the Google Groups "networkx-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to networkx-discu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/networkx-discuss/2e7fefa1-d571-4b26-86cf-ec9d5a1c18c9n%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/networkx-discuss/3c93d593-b643-4120-80f9-37e372d3c427n%40googlegroups.com.