Prevent memory error in itertools.permutation

Try to use the iterator generated by the permutations instead of recreating a list with it :

perm_iterator = itertools.permutations(list(graph.Nodes))

for item in perm_iterator:
   do_the_stuff(item)

by doing this, python will keep in memory only the currently used permutation, not all the permutations (in term of memory usage, it is really better 😉 )

On the other side, once the memory problem solved, the time to treat all the permutations will be growing exponentially with the number of vertices….

Leave a Comment

tech