N-Wouda / ALNS

Adaptive large neighbourhood search (and more!) in Python.
https://alns.readthedocs.io/en/latest/
MIT License
442 stars 123 forks source link

Replace `RandomState` with `Generator` #166

Closed leonlan closed 1 week ago

leonlan commented 1 year ago

Is your feature request related to a problem? Please describe

The ALNS library currently uses numpy.random's RandomState for random number generation. But this object is considered legacy and no longer receives updates from Numpy 1.16 onwards.

The main problem happens when users pass their own rng to ALNS. The current default RNG from numpy is Generator, but it has a different interface than RandomState (e.g., integers vs. randint). Since we implement some acceptance criteria/operator selection schemes assuming that the RNG is a RandomState object, users that use Generator object will run into problems.

Describe the solution you'd like

We should replace RandomState with Generator.

Describe alternatives you have considered

N/A

Additional context

N/A

N-Wouda commented 1 year ago

I think I worked around this a few years ago in SimulatedAnnealing (but might've been somewhere else). Back then the generator interface was quite new, so I hadn't wanted to move over yet. By now I think we can just port.

leonlan commented 1 year ago

Yup, here: https://github.com/N-Wouda/ALNS/blob/04991b6b2d21437992da2da415a3f98958ec9e2c/alns/accept/SimulatedAnnealing.py#L113-L118

I initially thought of supporting both RandomState and Generator like this, but since RandomState is legacy we should just replace it entirely.