


"""simple docstring"""



import unittest

from diffusers.pipelines.pipeline_utils import is_safetensors_compatible
class 					__magic_name__		(			unittest.TestCase     ):






       def  __snake_case						(   self  :    List[Any]				):

              '''simple docstring'''






              lowercase		:Tuple       							=				[
                  '''safety_checker/pytorch_model.bin''',
                  '''safety_checker/model.safetensors''',
                  '''vae/diffusion_pytorch_model.bin''',
                  '''vae/diffusion_pytorch_model.safetensors''',
                  '''text_encoder/pytorch_model.bin''',
                  '''text_encoder/model.safetensors''',
                  '''unet/diffusion_pytorch_model.bin''',
                  '''unet/diffusion_pytorch_model.safetensors''',
              ]
              self.assertTrue(is_safetensors_compatible(snake_case__				)				)






       def  __snake_case						(   self  :    Union[str, Any]				):

              '''simple docstring'''






              lowercase		:Tuple       							=				[
                  '''unet/diffusion_pytorch_model.bin''',
                  '''unet/diffusion_pytorch_model.safetensors''',
              ]
              self.assertTrue(is_safetensors_compatible(snake_case__				)				)






       def  __snake_case						(   self  :    List[Any]				):

              '''simple docstring'''






              lowercase		:List[Any]       							=				[
                  '''safety_checker/pytorch_model.bin''',
                  '''safety_checker/model.safetensors''',
                  '''vae/diffusion_pytorch_model.bin''',
                  '''vae/diffusion_pytorch_model.safetensors''',
                  '''text_encoder/pytorch_model.bin''',
                  '''text_encoder/model.safetensors''',
                  '''unet/diffusion_pytorch_model.bin''',
                  # Removed: 'unet/diffusion_pytorch_model.safetensors',
              ]
              self.assertFalse(is_safetensors_compatible(snake_case__				)				)






       def  __snake_case						(   self  :    Dict				):

              '''simple docstring'''






              lowercase		:Union[str, Any]       							=				[
                  '''text_encoder/pytorch_model.bin''',
                  '''text_encoder/model.safetensors''',
              ]
              self.assertTrue(is_safetensors_compatible(snake_case__				)				)






       def  __snake_case						(   self  :    List[str]				):

              '''simple docstring'''






              lowercase		:str       							=				[
                  '''safety_checker/pytorch_model.bin''',
                  '''safety_checker/model.safetensors''',
                  '''vae/diffusion_pytorch_model.bin''',
                  '''vae/diffusion_pytorch_model.safetensors''',
                  '''text_encoder/pytorch_model.bin''',
                  # Removed: 'text_encoder/model.safetensors',
                  '''unet/diffusion_pytorch_model.bin''',
                  '''unet/diffusion_pytorch_model.safetensors''',
              ]
              self.assertFalse(is_safetensors_compatible(snake_case__				)				)






       def  __snake_case						(   self  :    Any				):

              '''simple docstring'''






              lowercase		:Optional[Any]       							=				[
                  '''safety_checker/pytorch_model.fp16.bin''',
                  '''safety_checker/model.fp16.safetensors''',
                  '''vae/diffusion_pytorch_model.fp16.bin''',
                  '''vae/diffusion_pytorch_model.fp16.safetensors''',
                  '''text_encoder/pytorch_model.fp16.bin''',
                  '''text_encoder/model.fp16.safetensors''',
                  '''unet/diffusion_pytorch_model.fp16.bin''',
                  '''unet/diffusion_pytorch_model.fp16.safetensors''',
              ]
              lowercase		:Dict       							=				'''fp16'''
              self.assertTrue(is_safetensors_compatible(snake_case__  ,     variant=snake_case__				)				)






       def  __snake_case						(   self  :    List[Any]				):

              '''simple docstring'''






              lowercase		:Dict       							=				[
                  '''unet/diffusion_pytorch_model.fp16.bin''',
                  '''unet/diffusion_pytorch_model.fp16.safetensors''',
              ]
              lowercase		:Optional[int]       							=				'''fp16'''
              self.assertTrue(is_safetensors_compatible(snake_case__  ,     variant=snake_case__				)				)






       def  __snake_case						(   self  :    int				):

              '''simple docstring'''






              lowercase		:Tuple       							=				[
                  '''unet/diffusion_pytorch_model.bin''',
                  '''unet/diffusion_pytorch_model.safetensors''',
              ]
              lowercase		:Optional[Any]       							=				'''fp16'''
              self.assertTrue(is_safetensors_compatible(snake_case__  ,     variant=snake_case__				)				)






       def  __snake_case						(   self  :    List[Any]				):

              '''simple docstring'''






              lowercase		:Tuple       							=				[
                  '''safety_checker/pytorch_model.fp16.bin''',
                  '''safety_checker/model.fp16.safetensors''',
                  '''vae/diffusion_pytorch_model.fp16.bin''',
                  '''vae/diffusion_pytorch_model.fp16.safetensors''',
                  '''text_encoder/pytorch_model.fp16.bin''',
                  '''text_encoder/model.fp16.safetensors''',
                  '''unet/diffusion_pytorch_model.fp16.bin''',
                  # Removed: 'unet/diffusion_pytorch_model.fp16.safetensors',
              ]
              lowercase		:List[Any]       							=				'''fp16'''
              self.assertFalse(is_safetensors_compatible(snake_case__  ,     variant=snake_case__				)				)






       def  __snake_case						(   self  :    Union[str, Any]				):

              '''simple docstring'''






              lowercase		:Tuple       							=				[
                  '''text_encoder/pytorch_model.fp16.bin''',
                  '''text_encoder/model.fp16.safetensors''',
              ]
              lowercase		:Dict       							=				'''fp16'''
              self.assertTrue(is_safetensors_compatible(snake_case__  ,     variant=snake_case__				)				)






       def  __snake_case						(   self  :    Dict				):

              '''simple docstring'''






              lowercase		:List[str]       							=				[
                  '''text_encoder/pytorch_model.bin''',
                  '''text_encoder/model.safetensors''',
              ]
              lowercase		:List[Any]       							=				'''fp16'''
              self.assertTrue(is_safetensors_compatible(snake_case__  ,     variant=snake_case__				)				)







       def  __snake_case						(   self  :    str				):

              '''simple docstring'''






              lowercase		:List[str]       							=				[
                  '''safety_checker/pytorch_model.fp16.bin''',
                  '''safety_checker/model.fp16.safetensors''',
                  '''vae/diffusion_pytorch_model.fp16.bin''',
                  '''vae/diffusion_pytorch_model.fp16.safetensors''',
                  '''text_encoder/pytorch_model.fp16.bin''',
                  # 'text_encoder/model.fp16.safetensors',
                  '''unet/diffusion_pytorch_model.fp16.bin''',
                  '''unet/diffusion_pytorch_model.fp16.safetensors''',
              ]
              lowercase		:str       							=				'''fp16'''
              self.assertFalse(is_safetensors_compatible(snake_case__  ,     variant=snake_case__				)				)





"""simple docstring"""



import argparse
import copy






def       lowerCamelCase					(a_						:Union[str, Any])     ->							Tuple:
       lowercase		:Dict       							=				{}

       with open(a_) as f:
              for line in f:
                     if line.split()[0] not in dict_of_neighbours:
                            lowercase		:List[str]       							=				[]
                            _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		:List[Any]       							=				[]
                            _list.append([line.split()[0], line.split()[2]])
                            lowercase		:Dict       							=				_list
                     else:
                            dict_of_neighbours[line.split()[1]].append(
                                [line.split()[0], line.split()[2]])

       return dict_of_neighbours






def       lowerCamelCase					(a_						:Any				,				a_						:Dict)     ->							Any:

       with open(a_) as f:
              lowercase		:Any       							=				f.read(1)
       lowercase		:Any       							=				start_node

       lowercase		:Any       							=				[]

       lowercase		:Union[str, Any]       							=				start_node

       lowercase		:int       							=				0
       while visiting not in first_solution:
              lowercase		:int       							=				1_0000
              for k in dict_of_neighbours[visiting]:
                     if int(k[1]) < int(a_) and k[0] not in first_solution:
                            lowercase		:str       							=				k[1]
                            lowercase		:str       							=				k[0]

              first_solution.append(a_)
              lowercase		:int       							=				distance_of_first_solution + int(a_)
              lowercase		:Dict       							=				best_node

       first_solution.append(a_)

       lowercase		:int       							=				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_0000
       )
       return first_solution, distance_of_first_solution






def       lowerCamelCase					(a_						:List[str]				,				a_						:str)     ->							str:
       lowercase		:Any       							=				[]

       for n in solution[1:-1]:
              lowercase		:int       							=				solution.index(a_)
              for kn in solution[1:-1]:
                     lowercase		:Union[str, Any]       							=				solution.index(a_)
                     if n == kn:
                            continue

                     lowercase		:int       							=				copy.deepcopy(a_)
                     lowercase		:str       							=				kn
                     lowercase		:List[Any]       							=				n

                     lowercase		:int       							=				0

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

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

       lowercase		:Dict       							=				len(neighborhood_of_solution[0]) - 1

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






def       lowerCamelCase					(a_						:int				,				a_						:Optional[int]				,				a_						:List[Any]				,				a_						:Any				,				a_						:Optional[Any])     ->							List[Any]:
       lowercase		:Union[str, Any]       							=				1
       lowercase		:str       							=				first_solution
       lowercase		:int       							=				[]
       lowercase		:int       							=				distance_of_first_solution
       lowercase		:List[str]       							=				solution

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

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

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

              lowercase		:int       							=				count + 1

       return best_solution_ever, best_cost






def       lowerCamelCase					(a_						:Tuple=None)     ->							Any:
       lowercase		:Tuple       							=				generate_neighbours(args.File)

       lowercase							,  lowercase		:List[str]       							=				generate_first_solution(
           args.File				,				a_)

       lowercase							,  lowercase		:Union[str, Any]       							=				tabu_search(
           a_				,				a_				,				a_				,				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())

