fillipe-gsm / python-tsp

Library to solve Traveling Salesperson Problems with pure Python code
MIT License
174 stars 28 forks source link

Feature request: deterministic solutions #41

Open nullSoup opened 1 year ago

nullSoup commented 1 year ago

In order to experiment with the various options in the heuristic solvers, it would be helpful to use them in a deterministic fashion where the same parameters always lead to the same solution. Single threaded, I think this can be achieved by simply calling random.seed() before using the module, but this does not work multi threaded where calls to the global random number generator occur in an unpredictable order. Would it be possible to add an optional argument to the heuristic solvers where an already initialized instance of random.Random can be passed in so as to allow deterministic solutions?

I don't know if this may be an excessively niche request, but if this is something you're interested in including but don't want to spend time on, I can try making a pull request.

fillipe-gsm commented 1 year ago

Hey, @nullSoup , sorry for the late answer, Github either never sends me notifications or it floods me with every single project update, so I may have lost your open issue.

Indeed, that looks like a very niche request, but I am personally o.k. with it as long as the code does not get more complicated (e.g., no global variables, which would be a simple but a bad long-term solution). The only inconvenience is that implementing it to all heuristic solvers we have now would take a while to do. Is there any specific solver you use the most that we could start with?

Otherwise, if you have an on-going code to handle that you can open a pull-request.