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
|
2022-06-08 22:20:08 +02:00
|
|
|
best_state, best_fitness = mlrose.genetic_alg(problem_fit, mutation_prob = 0.2, max_attempts = 200, random_state = 2)
|
2022-06-08 21:58:06 +02:00
|
|
|
|
|
|
|
print('Najlepsza sciezka: ', best_state)
|
2022-06-08 21:52:46 +02:00
|
|
|
return best_state
|