


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

def 				_snake_case      (   __snake_case							:      Tuple   ):




   """simple docstring"""







   _lowerCamelCase	:					str   =		{}

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

   return dict_of_neighbours

def 				_snake_case      (   __snake_case							:      List[Any]						, __snake_case							:      int   ):




   """simple docstring"""







   with open(__snake_case   ) as f:
      _lowerCamelCase	:					str   =		f.read(1   )
   _lowerCamelCase	:					Dict   =		start_node

   _lowerCamelCase	:					Tuple   =		[]

   _lowerCamelCase	:					int   =		start_node

   _lowerCamelCase	:					Tuple   =		0
   while visiting not in first_solution:
      _lowerCamelCase	:					int   =		10000
      for k in dict_of_neighbours[visiting]:
         if int(k[1]   ) < int(__snake_case   ) and k[0] not in first_solution:
            _lowerCamelCase	:					List[Any]   =		k[1]
            _lowerCamelCase	:					Any   =		k[0]

      first_solution.append(__snake_case   )
      _lowerCamelCase	:					Optional[int]   =		distance_of_first_solution + int(__snake_case   )
      _lowerCamelCase	:					Any   =		best_node

   first_solution.append(__snake_case   )

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

   _lowerCamelCase	:					str   =		(
       distance_of_first_solution
       + int(dict_of_neighbours[first_solution[-2]][position][1]   )
       - 10000
   )
   return first_solution, distance_of_first_solution

def 				_snake_case      (   __snake_case							:      List[Any]						, __snake_case							:      Optional[Any]   ):




   """simple docstring"""







   _lowerCamelCase	:					str   =		[]

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

         _lowerCamelCase	:					Optional[int]   =		copy.deepcopy(__snake_case   )
         _lowerCamelCase	:					Any   =		kn
         _lowerCamelCase	:					str   =		n

         _lowerCamelCase	:					List[str]   =		0

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

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

   _lowerCamelCase	:					List[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 				_snake_case      (   __snake_case							:      List[str]						, __snake_case							:      Optional[Any]						, __snake_case							:      Optional[Any]						, __snake_case							:      Dict						, __snake_case							:      List[Any]   ):




   """simple docstring"""







   _lowerCamelCase	:					Any   =		1
   _lowerCamelCase	:					str   =		first_solution
   _lowerCamelCase	:					int   =		[]
   _lowerCamelCase	:					str   =		distance_of_first_solution
   _lowerCamelCase	:					int   =		solution

   while count <= iters:
      _lowerCamelCase	:					Optional[Any]   =		find_neighborhood(__snake_case						, __snake_case   )
      _lowerCamelCase	:					Tuple   =		0
      _lowerCamelCase	:					List[Any]   =		neighborhood[index_of_best_solution]
      _lowerCamelCase	:					List[str]   =		len(__snake_case   ) - 1

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

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

      _lowerCamelCase	:					Any   =		count + 1

   return best_solution_ever, best_cost

def 				_snake_case      (   __snake_case							:      Any=None   ):




   """simple docstring"""







   _lowerCamelCase	:					Dict   =		generate_neighbours(args.File   )

   _lowerCamelCase   ,    _lowerCamelCase	:					Any   =		generate_first_solution(
       args.File						, __snake_case   )

   _lowerCamelCase   ,    _lowerCamelCase	:					List[str]   =		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__":
 UpperCAmelCase				=						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 collections import defaultdict

def 				_snake_case      (   __snake_case							:      str						, __snake_case							:      str   ):




   """simple docstring"""







   _lowerCamelCase	:					Tuple   =		first_str.lower().strip()
   _lowerCamelCase	:					int   =		second_str.lower().strip()

   # Remove whitespace
   _lowerCamelCase	:					Any   =		first_str.replace(""" """						, """"""   )
   _lowerCamelCase	:					List[str]   =		second_str.replace(""" """						, """"""   )

   # Strings of different lengths are not anagrams
   if len(__snake_case   ) != len(__snake_case   ):
      return False

   # Default values for count should be 0
   _lowerCamelCase	:					defaultdict[str, int]   =		defaultdict(__snake_case   )

   # For each character in input strings,
   # increment count in the corresponding
   for i in range(len(__snake_case   )   ):
      count[first_str[i]] += 1
      count[second_str[i]] -= 1

   return all(_count == 0 for _count in count.values()   )


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

 testmod()
 UpperCAmelCase				=						input("""Enter the first string """).strip()
 UpperCAmelCase				=						input("""Enter the second string """).strip()

 UpperCAmelCase				=						check_anagrams(input_a, input_b)
 print(f'''{input_a} and {input_b} are {"" if status else "not "}anagrams.''')

