Make some cosmetic changes

This commit is contained in:
Cory Balaton 2024-10-01 19:06:28 +02:00
parent 4455a4e6f4
commit 0e7965f06a
Signed by: coryab
GPG Key ID: F7562F0EC4E4A61B

View File

@ -1,6 +1,6 @@
import time import time
from itertools import permutations from itertools import permutations
from typing import Callable, Tuple from typing import Tuple
import numpy.typing as npt import numpy.typing as npt
@ -25,8 +25,8 @@ 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, perm,
@ -53,7 +53,7 @@ if __name__ == "__main__":
print(f"time to find solution: {time_elapsed_ms:>12.6f}ms\n") print(f"time to find solution: {time_elapsed_ms:>12.6f}ms\n")
""" Running example """Running example
oblig1 on main [?] via 🐍 v3.12.6 took 7s oblig1 on main [?] via 🐍 v3.12.6 took 7s
python exhaustive_search.py python exhaustive_search.py