Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Randomized Hill Climbing improvement #51

Open
wtld opened this issue Apr 25, 2020 · 1 comment
Open

Randomized Hill Climbing improvement #51

wtld opened this issue Apr 25, 2020 · 1 comment

Comments

@wtld
Copy link

wtld commented Apr 25, 2020

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.

@walintonc
Copy link

Thanks, @wtld
Can you create Pull Request with your proposed changes so that it can be properly reviewed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants