Any Ideas for optimization?

Hi all,

i try to write a TSP-Solver to generate a toolpath for milling and after first results i need some advice how to optimize code and how structure it to prevent rhino crashes.

The script work like this.

  1. Take given startpoint (stpt)
  2. Copy the given Points for the path
  3. Find nearest points (clpt) to startpoint (first tried pointcompare and switched to ktree)
  4. create vectors (vec) between stpt and clpt
  5. take the vec with smallest 1 > |X| (clspt) > |Y| (switch X and Y change apth direction)
  6. the endpoint of the the shortest (clspt) is the new startpoint
  7. if (clspt) is empty take just the shortest distance point
  8. remove old startpoint from pointlist

Code


pic

Maybe someone can give me advice to store data or split it to avoid a crash when the point count increas.
I will delete every second point in the x direction to reduce the amount.
Any idea where i can invest my research is very welcome

You’ll need to upload a Grasshopper definition for us to provide any meaningful feedback (I assume this is a GHPython question, judging from the second screenshot).

Thanks for reply,

you are right here is the reduced version.
50*50 points are already to much it crashes rhino.
TSP_path.gh (6.3 KB)

Pleace tell if anything else is needed