my computer tried to calculate paths 9.33×10^157 times.
Posted by silicisbits@reddit | Python | View on Reddit | 10 comments
so I was creating my first tsp algorithm, without any optimizations just calculate every possible path, I got it working for 4 paths then I tried to increase the number of points to 100, and if you don't know my computer had to calculate 93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000 paths and find the closest path between them, some time after I ran the code I saw a pop up that said "you have ran out of application memory" with all the apps that were currently running, python alone was using around 45 gigs of memory, but I only had 8 GIGS OF MEMORY, moral of the story? don't run code without knowing how resource intensive it is.
Python-ModTeam@reddit
Your post was removed for violating Rule #2. All posts must be directly related to the Python programming language. Posts pertaining to programming in general are not permitted. You may want to try posting in /r/programming instead.
Spidey_qbz@reddit
I'm not sure about that algorithm at all , if your program ran out of memory then use notebooks like Google colab.
silicisbits@reddit (OP)
I crashed their system as well💀
tomasemilio@reddit
Wow, that sounds like quite the experience! The Traveling Salesman Problem (TSP) really ramps up in complexity with more points, and brute-forcing it can lead to some wild resource usage. For future projects, you might want to look into optimization techniques like dynamic programming or heuristics like genetic algorithms or simulated annealing. They can help manage the complexity without crashing your system. Also, consider using smaller datasets or testing your algorithm on fewer points to gauge performance before scaling up. Good luck with your coding!
DisappointedLily@reddit
Thanks GPT!
jpgoldberg@reddit
I suspect you knew before hand that the Travelling Saleman Problem is famous for this. But yeah, this is a cool illustration.
If your algorithm for trying a new path is not going to produce duplicate paths, you don't need to store information about each path tried. You just need to store the best path so far. This should substantially reduce the memory requirement.
Hermasetas@reddit
The most experienced developers are the ones who made the most mistakes 😁
silicisbits@reddit (OP)
the thing is I am not experienced python.
Hermasetas@reddit
But you're more experienced now than before
nekokattt@reddit
Swap/page file entered the chat