adjusted temperature in assignment 2

master
Ruben-FreddyLoafers 2025-10-08 10:45:02 +02:00
parent f8b889c213
commit 3bf9ec3d2e
1 changed files with 4 additions and 4 deletions

View File

@ -38,7 +38,7 @@ board = np.array([
board_size = len(board) # Board is always quadratic
last_fitness = calculate_fitness(board)
T = 10
T = 100
print("Working...")
while calculate_fitness(board) < 0:
@ -54,13 +54,13 @@ while calculate_fitness(board) < 0:
last_fitness = current_fitness
else:
p = math.e ** (-(last_fitness - current_fitness) / T) # adjusted formula
# print(p) # debugging
print(p) # debugging
if p > random.random(): # if probability occurs
last_fitness = current_fitness
else:
board[rand_row, swap_col], board[rand_row, rand_col] = board[rand_row, rand_col], board[rand_row, swap_col]
T = max(T - 0.1, 0.1) # Decrease T more slowly and don't let it reach 0
T = max(T - 0.01, 0.1) # Decrease T more slowly and don't let it reach 0
print(last_fitness) # debugging
# print(last_fitness) # debugging
print(board)