Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.80 KB | None | 0 0
  1. def hill_climbing(self):
  2.         self.number_of_bytes()
  3.         candidate_solution = []
  4.         current_solution = []
  5.         solution = self.solution_bitstring()
  6.         best = self.func(self.solution_decimal(solution))
  7.         print(best)
  8.         for i in range(10**3):
  9.             local=False
  10.             candidate_solution = self.solution_bitstring()
  11.             candidate_best = self.func(self.solution_decimal(candidate_solution))
  12.             while local is False:
  13.                 list_of_neighbours = self.neighbours(candidate_solution,doShuffle=True)
  14.                 for neighbour in list_of_neighbours:
  15.                     local=True
  16.                     if self.func(self.solution_decimal(neighbour))<candidate_best:
  17.                         candidate_best = self.func(self.solution_decimal(neighbour))
  18.                         candidate_solution = neighbour
  19.                         local=False
  20.                         break
  21.             if candidate_best < best:
  22.                 best = candidate_best
  23.         return best
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement