






"""simple docstring"""
from __future__ import annotations

from itertools import permutations
from random import randint
from timeit import repeat


def 							A						(				)    ->		tuple[list[int], int]:

       """simple docstring"""





       __magic_name__      				=    [randint(-1_0_0_0 ,     1_0_0_0  ) for i in range(1_0  )]
       __magic_name__      				=    randint(-5_0_0_0 ,     5_0_0_0  )
       return (arr, r)


snake_case : Optional[Any]     		=		make_dataset()


def 							A						(				__snake_case: list[int] ,     __snake_case: int  )    ->		tuple[int, ...]:

       """simple docstring"""





       for triplet in permutations(__snake_case ,     3  ):
              if sum(__snake_case  ) == target:
                     return tuple(sorted(__snake_case  )  )
       return (0, 0, 0)


def 							A						(				__snake_case: list[int] ,     __snake_case: int  )    ->		tuple[int, int, int]:

       """simple docstring"""





       arr.sort()
       __magic_name__      				=    len(__snake_case  )
       for i in range(n - 1  ):
              __magic_name__				,  __magic_name__      				=    i + 1, n - 1
              while left < right:
                     if arr[i] + arr[left] + arr[right] == target:
                            return (arr[i], arr[left], arr[right])
                     elif arr[i] + arr[left] + arr[right] < target:
                            left += 1
                     elif arr[i] + arr[left] + arr[right] > target:
                            right -= 1
       return (0, 0, 0)


def 							A						(				)    ->		tuple[float, float]:

       """simple docstring"""





       __magic_name__      				=    '\nfrom __main__ import dataset, triplet_sum1, triplet_sum2\n'
       __magic_name__      				=    '\ntriplet_sum1(*dataset)\n'
       __magic_name__      				=    '\ntriplet_sum2(*dataset)\n'
       __magic_name__      				=    repeat(setup=__snake_case ,     stmt=__snake_case ,     repeat=5 ,     number=1_0_0_0_0  )
       __magic_name__      				=    repeat(setup=__snake_case ,     stmt=__snake_case ,     repeat=5 ,     number=1_0_0_0_0  )
       return (min(__snake_case  ), min(__snake_case  ))


if __name__ == "__main__":
 from doctest import testmod

 testmod()
 snake_case : Union[str, Any]     		=		solution_times()
 print(f"""The time for naive implementation is {times[0]}.""")
 print(f"""The time for optimized implementation is {times[1]}.""")







"""simple docstring"""
import argparse
import copy


def 							A						(				__snake_case: Union[str, Any]  )    ->		Tuple:

       """simple docstring"""





       __magic_name__      				=    {}

       with open(__snake_case  ) as f:
              for line in f:
                     if line.split()[0] not in dict_of_neighbours:
                            __magic_name__      				=    []
                            _list.append([line.split()[1], line.split()[2]]  )
                            __magic_name__      				=    _list
                     else:
                            dict_of_neighbours[line.split()[0]].append(
                                [line.split()[1], line.split()[2]]  )
                     if line.split()[1] not in dict_of_neighbours:
                            __magic_name__      				=    []
                            _list.append([line.split()[0], line.split()[2]]  )
                            __magic_name__      				=    _list
                     else:
                            dict_of_neighbours[line.split()[1]].append(
                                [line.split()[0], line.split()[2]]  )

       return dict_of_neighbours


def 							A						(				__snake_case: Optional[Any] ,     __snake_case: str  )    ->		List[str]:

       """simple docstring"""





       with open(__snake_case  ) as f:
              __magic_name__      				=    f.read(1  )
       __magic_name__      				=    start_node

       __magic_name__      				=    []

       __magic_name__      				=    start_node

       __magic_name__      				=    0
       while visiting not in first_solution:
              __magic_name__      				=    1_0_0_0_0
              for k in dict_of_neighbours[visiting]:
                     if int(k[1]  ) < int(__snake_case  ) and k[0] not in first_solution:
                            __magic_name__      				=    k[1]
                            __magic_name__      				=    k[0]

              first_solution.append(__snake_case  )
              __magic_name__      				=    distance_of_first_solution + int(__snake_case  )
              __magic_name__      				=    best_node

       first_solution.append(__snake_case  )

       __magic_name__      				=    0
       for k in dict_of_neighbours[first_solution[-2]]:
              if k[0] == start_node:
                     break
              position += 1

       __magic_name__      				=    (
           distance_of_first_solution
           + int(dict_of_neighbours[first_solution[-2]][position][1]  )
           - 1_0_0_0_0
       )
       return first_solution, distance_of_first_solution


def 							A						(				__snake_case: Union[str, Any] ,     __snake_case: Optional[Any]  )    ->		Dict:

       """simple docstring"""





       __magic_name__      				=    []

       for n in solution[1:-1]:
              __magic_name__      				=    solution.index(__snake_case  )
              for kn in solution[1:-1]:
                     __magic_name__      				=    solution.index(__snake_case  )
                     if n == kn:
                            continue

                     __magic_name__      				=    copy.deepcopy(__snake_case  )
                     __magic_name__      				=    kn
                     __magic_name__      				=    n

                     __magic_name__      				=    0

                     for k in _tmp[:-1]:
                            __magic_name__      				=    _tmp[_tmp.index(__snake_case  ) + 1]
                            for i in dict_of_neighbours[k]:
                                   if i[0] == next_node:
                                          __magic_name__      				=    distance + int(i[1]  )
                     _tmp.append(__snake_case  )

                     if _tmp not in neighborhood_of_solution:
                            neighborhood_of_solution.append(_tmp  )

       __magic_name__      				=    len(neighborhood_of_solution[0]  ) - 1

       neighborhood_of_solution.sort(key=lambda __snake_case  : x[index_of_last_item_in_the_list]  )
       return neighborhood_of_solution


def 							A						(				__snake_case: List[str] ,     __snake_case: Union[str, Any] ,     __snake_case: List[str] ,     __snake_case: Optional[int] ,     __snake_case: List[str]  )    ->		Dict:

       """simple docstring"""





       __magic_name__      				=    1
       __magic_name__      				=    first_solution
       __magic_name__      				=    []
       __magic_name__      				=    distance_of_first_solution
       __magic_name__      				=    solution

       while count <= iters:
              __magic_name__      				=    find_neighborhood(__snake_case ,     __snake_case  )
              __magic_name__      				=    0
              __magic_name__      				=    neighborhood[index_of_best_solution]
              __magic_name__      				=    len(__snake_case  ) - 1

              __magic_name__      				=    False
              while not found:
                     __magic_name__      				=    0
                     while i < len(__snake_case  ):
                            if best_solution[i] != solution[i]:
                                   __magic_name__      				=    best_solution[i]
                                   __magic_name__      				=    solution[i]
                                   break
                            __magic_name__      				=    i + 1

                     if [first_exchange_node, second_exchange_node] not in tabu_list and [
                         second_exchange_node,
                         first_exchange_node,
                     ] not in tabu_list:
                            tabu_list.append([first_exchange_node, second_exchange_node]  )
                            __magic_name__      				=    True
                            __magic_name__      				=    best_solution[:-1]
                            __magic_name__      				=    neighborhood[index_of_best_solution][best_cost_index]
                            if cost < best_cost:
                                   __magic_name__      				=    cost
                                   __magic_name__      				=    solution
                     else:
                            __magic_name__      				=    index_of_best_solution + 1
                            __magic_name__      				=    neighborhood[index_of_best_solution]

              if len(__snake_case  ) >= size:
                     tabu_list.pop(0  )

              __magic_name__      				=    count + 1

       return best_solution_ever, best_cost


def 							A						(				__snake_case: Union[str, Any]=None  )    ->		Tuple:

       """simple docstring"""





       __magic_name__      				=    generate_neighbours(args.File  )

       __magic_name__				,  __magic_name__      				=    generate_first_solution(
           args.File ,     __snake_case  )

       __magic_name__				,  __magic_name__      				=    tabu_search(
           __snake_case ,     __snake_case ,     __snake_case ,     args.Iterations ,     args.Size ,     )

       print(F"""Best solution: {best_sol}, with total distance: {best_cost}."""  )


if __name__ == "__main__":
 snake_case : str     		=		argparse.ArgumentParser(description="""Tabu Search""")
 parser.add_argument(
     """-f""",
     """--File""",
     type=str,
     help="""Path to the file containing the data""",
     required=True,
 )
 parser.add_argument(
     """-i""",
     """--Iterations""",
     type=int,
     help="""How many iterations the algorithm should perform""",
     required=True,
 )
 parser.add_argument(
     """-s""", """--Size""", type=int, help="""Size of the tabu list""", required=True
 )

 # Pass the arguments to main method
 main(parser.parse_args())