def hill_climbing_first_choice_simulated_annealing(status):
'''??????????????????????????????????????
??????????
'''
global chess_status_count, temperature
pos = [(x, y) for x in range(8) for y in range(8)]
random.shuffle(pos)
for col, row in pos:
if status[col] == row:
continue
chess_status_count += 1
status_copy = list(status)
status_copy[col] = row
delta = get_num_of_conglict(status) - get_num_of_conglict(status_copy)
# ??
if temperature > 0:
temperature -= 0.0001
if delta > 0:
status[col] = row
return status
elif delta < 0 and temperature != 0:
probability = math.exp(delta / temperature)
random_num = random.random()
if random_num < probability:
status[col] = row
return status
return status
评论列表
文章目录