According to referenced "Clever Algorithms: Nature-Inspired Programming Recipes":
neighbors with better or equal cost should be accepted, allowing the technique to navigate across plateaus in the response surface
I suggest a change in the code like this:
while (attempts < max_attempts) and (iters < max_iters):
iters += 1
attempts += 1
# Find random neighbor and evaluate fitness
next_state = problem.random_neighbor()
next_fitness = problem.eval_fitness(next_state)
improvement = next_fitness - problem.get_fitness()
# If the neighbor is better or equal move to that state
if improvement >= 0:
problem.set_state(next_state)
# if better than reset attempts counter
if improvement > 0:
attempts = 0
I personally work with problems where this small change has a big impact on results.
According to referenced "Clever Algorithms: Nature-Inspired Programming Recipes":
I suggest a change in the code like this:
I personally work with problems where this small change has a big impact on results.