Skip to content

Instantly share code, notes, and snippets.

@rocreguant
Created January 31, 2021 16:19
Show Gist options
  • Save rocreguant/e0abf4b20d03542f77ae3278f88e22c4 to your computer and use it in GitHub Desktop.
Save rocreguant/e0abf4b20d03542f77ae3278f88e22c4 to your computer and use it in GitHub Desktop.
# 2. Evaluation of the fitness
#individual solution
def fitness_eval(city_list, cities_dict):
total = 0
for i in range(n_cities-1):
a = city_list[i]
b = city_list[i+1]
total += compute_city_distance_names(a,b, cities_dict)
return total
#All solutions
def get_all_fitnes(population_set, cities_dict):
fitnes_list = np.zeros(n_population)
#Looping over all solutions computing the fitness for each solution
for i in range(n_population):
fitnes_list[i] = fitness_eval(population_set[i], cities_dict)
return fitnes_list
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment