Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. def simulated(self):
  2. self.number_of_bytes()
  3. candidate = self.solution_bitstring()
  4. candidate_value = self.func(self.solution_decimal(candidate))
  5. generation = 0
  6. while self.temperature>0.001:
  7. for i in range(self.bytes_number*2):
  8. current = choice(self.neighbours(candidate))
  9. current_value = self.func(self.solution_decimal(current))
  10. if current_value < candidate_value:
  11. candidate = current
  12. candidate_value = current_value
  13. elif uniform(0,1)< np.exp(-abs(candidate_value-current_value)/self.temperature):
  14. candidate = current
  15. candidate_value = current_value
  16. self.update_temperature(generation)
  17. generation = generation + 1
  18. return candidate_value
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement