Small bug in GreedyILS / searchspace
Closed this issue · 1 comments
There is a small bug in the GreedyILS strategy in combination with the Searchspace object when using neighbor method 'adjacent'.
The mutation method inside GreedyILS reuses the mutation method from genetic_algorithm which in turn uses Searchspace, basically get_neighbors using Hamming and return a random choice. So far, so good. However, when GreedyILS is set to use 'adjacent' as the neighbor method, the hillclimber also uses Searchspace with adjacent as the neighbor method. Then, when genetic_algorithm's mutate comes along and uses Hamming on get_neighbors, the Searchspace object returns a cached list of neighbors obtained using 'adjacent' rather than 'Hamming' breaking the mutation capabilities and causing GreedyILS to hang forever in certain conditions. There is actually a sanity check inside Searchspace's get_neighbors_indices_no_cache method, but it seems the get_neighbors method returns the list of neighbors obtained with the wrong neighbor method regardless.
The bug can be triggered by setting adding neighbor="adjacent" to the strategy_options dict inside the test/strategies/test_strategies.py::test_strategies test. If you run to test multiple times you should see that it sometimes hangs forever.
Problem solved!