Change return statement to use numpy arrays
This commit is contained in:
parent
2ee3f59702
commit
375e2066b4
@ -2,12 +2,13 @@ import time
|
|||||||
from itertools import permutations
|
from itertools import permutations
|
||||||
from typing import Tuple
|
from typing import Tuple
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
import numpy.typing as npt
|
import numpy.typing as npt
|
||||||
|
|
||||||
from common import plot_plan, read_data
|
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.
|
"""An implementation of exhaustive search.
|
||||||
|
|
||||||
This implementation takes a permutation iterator, then maps each
|
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)
|
size = len(distances)
|
||||||
|
|
||||||
return min( # Find the smallest travel distance from the array
|
return min( # Find the smallest travel distance from the array
|
||||||
map( # Map the permutation array to contain tuples (distance, permutation)
|
map( # Map the permutation array to contain tuples (distance, permutation)
|
||||||
lambda perm: (
|
lambda perm: (
|
||||||
sum([distances[perm[i - 1], perm[i]] for i in range(size)]),
|
sum([distances[perm[i - 1], perm[i]] for i in range(size)]),
|
||||||
perm,
|
np.array(perm)
|
||||||
),
|
),
|
||||||
permutations(range(size)),
|
permutations(range(size)),
|
||||||
),
|
),
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user