From 375e2066b4bef872e87fc2f466ae4bce1c27818a Mon Sep 17 00:00:00 2001 From: Cory Balaton Date: Tue, 1 Oct 2024 19:17:10 +0200 Subject: [PATCH] Change return statement to use numpy arrays --- exhaustive_search.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/exhaustive_search.py b/exhaustive_search.py index ec2042c..3584979 100644 --- a/exhaustive_search.py +++ b/exhaustive_search.py @@ -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)), ),