In: Computer Science
I need to implement an algorithm based on local search that are in the following list in Python or Matlab( tabu search, simulated annealing, iterated local search, evolutionary local search, variable neighborhood search, variable neighborhood descent)
PLEASE HELP :)
#Simulated annealing Python
import random
import math
def simulated_annealing(initial_state):
"""Peforms simulated annealing to find a solution"""
initial_temp = 90
final_temp = .1
alpha = 0.01
current_temp = initial_temp
# Start by initializing the current state with the initial state
current_state = initial_state
solution = current_state
while current_temp > final_temp:
neighbor = random.choice(get_neighbors())
# Check if neighbor is best so far
cost_diff = get_cost(self.current_state) = get_cost(neighbor)
# if the new solution is better, accept it
if cost_diff > 0:
solution = neighbor
# if the new solution is not better, accept it with a probability of e^(-cost/temp)
else:
if random.uniform(0, 1) < math.exp(cost_diff / current_temp):
solution = neighbor
# decrement the temperature
current_temp -= alpha
return solution
def get_cost(state):
"""Calculates cost of the argument state for your solution."""
raise NotImplementedError
def get_neighbors(state):
"""Returns neighbors of the argument state for your solution."""
raise NotImplementedError