Change return statement to use numpy arrays

This commit is contained in:
Cory Balaton 2024-10-01 19:17:10 +02:00
parent 2ee3f59702
commit 375e2066b4
Signed by: coryab
GPG Key ID: F7562F0EC4E4A61B

View File

@ -2,12 +2,13 @@ import time
from itertools import permutations
from typing import Tuple
import numpy as np
import numpy.typing as npt
from common import plot_plan, read_data
def exhaustive_search(distances: npt.NDArray) -> Tuple[float, Tuple]:
def exhaustive_search(distances: npt.NDArray) -> Tuple[float, npt.NDArray]:
"""An implementation of exhaustive search.
This implementation takes a permutation iterator, then maps each
@ -25,11 +26,11 @@ def exhaustive_search(distances: npt.NDArray) -> Tuple[float, Tuple]:
size = len(distances)
return min( # Find the smallest travel distance from the array
map( # Map the permutation array to contain tuples (distance, permutation)
return min( # Find the smallest travel distance from the array
map( # Map the permutation array to contain tuples (distance, permutation)
lambda perm: (
sum([distances[perm[i - 1], perm[i]] for i in range(size)]),
perm,
np.array(perm)
),
permutations(range(size)),
),