Python Forum
memory error using permutation list of 11 elements - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: memory error using permutation list of 11 elements (/thread-21019.html)



memory error using permutation list of 11 elements - kikidog - Sep-10-2019

Hi
I am new to python coding but would like to use it to generate all the permutations and combinations of a slot car track layout given a list of pieces of track. I figure each piece of track is a block that connects at each end. Curved pieces are just curved blocks. The blocks have to line up one after another in line and make a loop, if it does not make a loop then the layout is discarded. I got as high as 10 pieces of track before I ran out of memory. I have 75 pieces of track made up of straight and curved pieces. This does not take into account each curved piece of track can face up or down.

Lastly I want to save each completed loop layout so I can use it as an input data list to generate a graphical picture of the slot car track layout.

Any help on how to code this would be deeply appreciated. Thank you.

the code...

import itertools
from pprint import pprint
import numpy as np

inputdata = [9,9,9,15,15,15,15,6,9,3] #track lengths
result = list(itertools.permutations(inputdata))
outputArrays = np.array_split(result,len(result))

pprint(outputArrays)


RE: memory error using permutation list of 11 elements - ichabod801 - Sep-10-2019

Run it in a loop rather than loading it all into a list. Then it's not all in memory at one time.