Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def hill_climbing2(problem):
- current = problem.initial
- countrepeats = 0 # selle lisasin
- while True:
- # find highest-valued successor
- neighbors = problem.neighbors(current)
- random.shuffle(neighbors)
- best_neighbor = neighbors[0]
- for next_neighbor in neighbors[1:]:
- if problem.value(next_neighbor) > problem.value(best_neighbor) or problem.value(next_neighbor) == problem.value(best_neighbor):
- best_neighbor = next_neighbor
- print(best_neighbor)
- if problem.value(best_neighbor) <= problem.value(current):
- array, start, end = current
- return array[start:end] # solution state as normal array
- if problem.value(best_neighbor) == problem.value(current): # selle osa lisasin
- countrepeats = countrepeats + 1
- if countrepeats == 10: return False
- current = best_neighbor
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement