

'''simple docstring'''
import argparse
import copy







def  _A		(     snake_case					)      ->     Tuple:
   _lowercase      :				Any      					=       {}

   with open(snake_case					) as f:
      for line in f:
         if line.split()[0] not in dict_of_neighbours:
            _lowercase      :				Dict      					=       []
            _list.append([line.split()[1], line.split()[2]]					)
            _lowercase      :				Any      					=       _list
         else:
            dict_of_neighbours[line.split()[0]].append(
                [line.split()[1], line.split()[2]]					)
         if line.split()[1] not in dict_of_neighbours:
            _lowercase      :				Tuple      					=       []
            _list.append([line.split()[0], line.split()[2]]					)
            _lowercase      :				List[Any]      					=       _list
         else:
            dict_of_neighbours[line.split()[1]].append(
                [line.split()[0], line.split()[2]]					)

   return dict_of_neighbours







def  _A		(     snake_case		,							snake_case					)      ->     Optional[int]:

   with open(snake_case					) as f:
      _lowercase      :				str      					=       f.read(1					)
   _lowercase      :				List[str]      					=       start_node

   _lowercase      :				int      					=       []

   _lowercase      :				Optional[Any]      					=       start_node

   _lowercase      :				Optional[Any]      					=       0
   while visiting not in first_solution:
      _lowercase      :				Optional[Any]      					=       1_00_00
      for k in dict_of_neighbours[visiting]:
         if int(k[1]					) < int(snake_case					) and k[0] not in first_solution:
            _lowercase      :				int      					=       k[1]
            _lowercase      :				Tuple      					=       k[0]

      first_solution.append(snake_case					)
      _lowercase      :				Optional[Any]      					=       distance_of_first_solution + int(snake_case					)
      _lowercase      :				List[Any]      					=       best_node

   first_solution.append(snake_case					)

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

   _lowercase      :				List[str]      					=       (
       distance_of_first_solution
       + int(dict_of_neighbours[first_solution[-2]][position][1]					)
       - 1_00_00
   )
   return first_solution, distance_of_first_solution







def  _A		(     snake_case		,							snake_case					)      ->     List[str]:
   _lowercase      :				Dict      					=       []

   for n in solution[1:-1]:
      _lowercase      :				Tuple      					=       solution.index(snake_case					)
      for kn in solution[1:-1]:
         _lowercase      :				Union[str, Any]      					=       solution.index(snake_case					)
         if n == kn:
            continue

         _lowercase      :				List[str]      					=       copy.deepcopy(snake_case					)
         _lowercase      :				str      					=       kn
         _lowercase      :				List[str]      					=       n

         _lowercase      :				List[Any]      					=       0

         for k in _tmp[:-1]:
            _lowercase      :				List[str]      					=       _tmp[_tmp.index(snake_case					) + 1]
            for i in dict_of_neighbours[k]:
               if i[0] == next_node:
                  _lowercase      :				Optional[Any]      					=       distance + int(i[1]					)
         _tmp.append(snake_case					)

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

   _lowercase      :				Any      					=       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		,							snake_case		,							snake_case		,							snake_case		,							snake_case					)      ->     List[Any]:
   _lowercase      :				Union[str, Any]      					=       1
   _lowercase      :				List[Any]      					=       first_solution
   _lowercase      :				Optional[int]      					=       []
   _lowercase      :				Any      					=       distance_of_first_solution
   _lowercase      :				Union[str, Any]      					=       solution

   while count <= iters:
      _lowercase      :				List[Any]      					=       find_neighborhood(snake_case		,							snake_case					)
      _lowercase      :				int      					=       0
      _lowercase      :				Optional[int]      					=       neighborhood[index_of_best_solution]
      _lowercase      :				int      					=       len(snake_case					) - 1

      _lowercase      :				List[str]      					=       False
      while not found:
         _lowercase      :				int      					=       0
         while i < len(snake_case					):
            if best_solution[i] != solution[i]:
               _lowercase      :				Optional[Any]      					=       best_solution[i]
               _lowercase      :				str      					=       solution[i]
               break
            _lowercase      :				Tuple      					=       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]					)
            _lowercase      :				Optional[Any]      					=       True
            _lowercase      :				Dict      					=       best_solution[:-1]
            _lowercase      :				Tuple      					=       neighborhood[index_of_best_solution][best_cost_index]
            if cost < best_cost:
               _lowercase      :				Union[str, Any]      					=       cost
               _lowercase      :				Any      					=       solution
         else:
            _lowercase      :				Tuple      					=       index_of_best_solution + 1
            _lowercase      :				List[Any]      					=       neighborhood[index_of_best_solution]

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

      _lowercase      :				List[Any]      					=       count + 1

   return best_solution_ever, best_cost







def  _A		(     snake_case=None					)      ->     Optional[int]:
   _lowercase      :				List[Any]      					=       generate_neighbours(args.File					)

   _lowercase					,				_lowercase      :				Union[str, Any]      					=       generate_first_solution(
       args.File		,							snake_case					)

   _lowercase					,				_lowercase      :				Optional[int]      					=       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         =  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())









'''simple docstring'''
from math import pi, sqrt, tan







def  _A		(     snake_case					)      ->     float:
   if side_length < 0:
      raise ValueError("surface_area_cube() only accepts non-negative values"					)
   return 6 * side_length**2







def  _A		(     snake_case		,							snake_case		,							snake_case					)      ->     float:
   if length < 0 or breadth < 0 or height < 0:
      raise ValueError("surface_area_cuboid() only accepts non-negative values"					)
   return 2 * ((length * breadth) + (breadth * height) + (length * height))







def  _A		(     snake_case					)      ->     float:
   if radius < 0:
      raise ValueError("surface_area_sphere() only accepts non-negative values"					)
   return 4 * pi * radius**2







def  _A		(     snake_case					)      ->     float:
   if radius < 0:
      raise ValueError("surface_area_hemisphere() only accepts non-negative values"					)
   return 3 * pi * radius**2







def  _A		(     snake_case		,							snake_case					)      ->     float:
   if radius < 0 or height < 0:
      raise ValueError("surface_area_cone() only accepts non-negative values"					)
   return pi * radius * (radius + (height**2 + radius**2) ** 0.5)







def  _A		(     snake_case		,							snake_case		,							snake_case					)      ->     float:
   if radius_a < 0 or radius_a < 0 or height < 0:
      raise ValueError(
          "surface_area_conical_frustum() only accepts non-negative values"					)
   _lowercase      :				Union[str, Any]      					=       (height**2 + (radius_a - radius_a) ** 2) ** 0.5
   return pi * ((slant_height * (radius_a + radius_a)) + radius_a**2 + radius_a**2)







def  _A		(     snake_case		,							snake_case					)      ->     float:
   if radius < 0 or height < 0:
      raise ValueError("surface_area_cylinder() only accepts non-negative values"					)
   return 2 * pi * radius * (height + radius)







def  _A		(     snake_case		,							snake_case					)      ->     float:
   if torus_radius < 0 or tube_radius < 0:
      raise ValueError("surface_area_torus() only accepts non-negative values"					)
   if torus_radius < tube_radius:
      raise ValueError(
          "surface_area_torus() does not support spindle or self intersecting tori"					)
   return 4 * pow(snake_case		,							2					) * torus_radius * tube_radius







def  _A		(     snake_case		,							snake_case					)      ->     float:
   if length < 0 or width < 0:
      raise ValueError("area_rectangle() only accepts non-negative values"					)
   return length * width







def  _A		(     snake_case					)      ->     float:
   if side_length < 0:
      raise ValueError("area_square() only accepts non-negative values"					)
   return side_length**2







def  _A		(     snake_case		,							snake_case					)      ->     float:
   if base < 0 or height < 0:
      raise ValueError("area_triangle() only accepts non-negative values"					)
   return (base * height) / 2







def  _A		(     snake_case		,							snake_case		,							snake_case					)      ->     float:
   if sidea < 0 or sidea < 0 or sidea < 0:
      raise ValueError("area_triangle_three_sides() only accepts non-negative values"					)
   elif sidea + sidea < sidea or sidea + sidea < sidea or sidea + sidea < sidea:
      raise ValueError("Given three sides do not form a triangle"					)
   _lowercase      :				Any      					=       (sidea + sidea + sidea) / 2
   _lowercase      :				List[str]      					=       sqrt(
       semi_perimeter
       * (semi_perimeter - sidea)
       * (semi_perimeter - sidea)
       * (semi_perimeter - sidea)					)
   return area







def  _A		(     snake_case		,							snake_case					)      ->     float:
   if base < 0 or height < 0:
      raise ValueError("area_parallelogram() only accepts non-negative values"					)
   return base * height







def  _A		(     snake_case		,							snake_case		,							snake_case					)      ->     float:
   if basea < 0 or basea < 0 or height < 0:
      raise ValueError("area_trapezium() only accepts non-negative values"					)
   return 1 / 2 * (basea + basea) * height







def  _A		(     snake_case					)      ->     float:
   if radius < 0:
      raise ValueError("area_circle() only accepts non-negative values"					)
   return pi * radius**2







def  _A		(     snake_case		,							snake_case					)      ->     float:
   if radius_x < 0 or radius_y < 0:
      raise ValueError("area_ellipse() only accepts non-negative values"					)
   return pi * radius_x * radius_y







def  _A		(     snake_case		,							snake_case					)      ->     float:
   if diagonal_a < 0 or diagonal_a < 0:
      raise ValueError("area_rhombus() only accepts non-negative values"					)
   return 1 / 2 * diagonal_a * diagonal_a







def  _A		(     snake_case		,							snake_case					)      ->     float:
   if not isinstance(snake_case		,							snake_case					) or sides < 3:
      raise ValueError(
          "area_reg_polygon() only accepts integers greater than or \
equal to three as number of sides"					)
   elif length < 0:
      raise ValueError(
          "area_reg_polygon() only accepts non-negative values as \
length of a side"					)
   return (sides * length**2) / (4 * tan(pi / sides					))
   return (sides * length**2) / (4 * tan(pi / sides					))


if __name__ == "__main__":
    import doctest

    doctest.testmod(verbose=True)  # verbose so we can see methods missing tests

    print('[DEMO] Areas of various geometric shapes: \n')
    print(F'''Rectangle: {area_rectangle(10, 20) = }''')
    print(F'''Square: {area_square(10) = }''')
    print(F'''Triangle: {area_triangle(10, 10) = }''')
    print(F'''Triangle: {area_triangle_three_sides(5, 12, 13) = }''')
    print(F'''Parallelogram: {area_parallelogram(10, 20) = }''')
    print(F'''Rhombus: {area_rhombus(10, 20) = }''')
    print(F'''Trapezium: {area_trapezium(10, 20, 30) = }''')
    print(F'''Circle: {area_circle(20) = }''')
    print(F'''Ellipse: {area_ellipse(10, 20) = }''')
    print('\nSurface Areas of various geometric shapes: \n')
    print(F'''Cube: {surface_area_cube(20) = }''')
    print(F'''Cuboid: {surface_area_cuboid(10, 20, 30) = }''')
    print(F'''Sphere: {surface_area_sphere(20) = }''')
    print(F'''Hemisphere: {surface_area_hemisphere(20) = }''')
    print(F'''Cone: {surface_area_cone(10, 20) = }''')
    print(F'''Conical Frustum: {surface_area_conical_frustum(10, 20, 30) = }''')
    print(F'''Cylinder: {surface_area_cylinder(10, 20) = }''')
    print(F'''Torus: {surface_area_torus(20, 10) = }''')
    print(F'''Equilateral Triangle: {area_reg_polygon(3, 10) = }''')
    print(F'''Square: {area_reg_polygon(4, 10) = }''')
    print(F'''Reqular Pentagon: {area_reg_polygon(5, 10) = }''')






