Advertisement
Guest User

Untitled

a guest
Mar 21st, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. def hill_climbing2(problem):
  2. current = problem.initial
  3. countrepeats = 0 # selle lisasin
  4. while True:
  5. # find highest-valued successor
  6. neighbors = problem.neighbors(current)
  7. random.shuffle(neighbors)
  8. best_neighbor = neighbors[0]
  9. for next_neighbor in neighbors[1:]:
  10. if problem.value(next_neighbor) > problem.value(best_neighbor) or problem.value(next_neighbor) == problem.value(best_neighbor):
  11. best_neighbor = next_neighbor
  12. print(best_neighbor)
  13.  
  14. if problem.value(best_neighbor) <= problem.value(current):
  15. array, start, end = current
  16. return array[start:end] # solution state as normal array
  17.  
  18. if problem.value(best_neighbor) == problem.value(current): # selle osa lisasin
  19. countrepeats = countrepeats + 1
  20. if countrepeats == 10: return False
  21.  
  22. current = best_neighbor
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement