2022-06-08 21:52:46 +02:00
|
|
|
import mlrose
|
|
|
|
|
|
|
|
def best_route (lista_paczek):
|
|
|
|
|
|
|
|
koordynaty_paczek = mlrose.TravellingSales(coords = lista_paczek)
|
2022-06-08 21:58:06 +02:00
|
|
|
|
|
|
|
#length oznacza liczbe paczek w naszej liscie
|
|
|
|
problem_fit = mlrose.TSPOpt(length = 5, fitness_fn = koordynaty_paczek, maximize = False)
|
|
|
|
|
|
|
|
# Znalesc najlepsza paczke za pomocy algorytmu genetycznego
|
|
|
|
best_state, best_fitness = mlrose.genetic_alg(problem_fit, mutation_prob = 0.5, max_attempts = 100, random_state = 2)
|
|
|
|
|
|
|
|
print('Najlepsza sciezka: ', best_state)
|
2022-06-08 21:52:46 +02:00
|
|
|
return best_state
|