




import argparse
import copy




def 		lowerCAmelCase_ (						lowerCamelCase ):
				__magic_name__						:						Tuple										={}

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

				return dict_of_neighbours




def 		lowerCAmelCase_ (						lowerCamelCase						,  lowerCamelCase ):

				with open(lowerCamelCase ) as f:
								__magic_name__						:						Optional[int]										=f.read(1 )
				__magic_name__						:						Any										=start_node

				__magic_name__						:						Union[str, Any]										=[]

				__magic_name__						:						Dict										=start_node

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

								first_solution.append(lowerCamelCase )
								__magic_name__						:						Optional[Any]										=distance_of_first_solution + int(lowerCamelCase )
								__magic_name__						:						Tuple										=best_node

				first_solution.append(lowerCamelCase )

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

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




def 		lowerCAmelCase_ (						lowerCamelCase						,  lowerCamelCase ):
				__magic_name__						:						Union[str, Any]										=[]

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

												__magic_name__						:						str										=copy.deepcopy(lowerCamelCase )
												__magic_name__						:						List[str]										=kn
												__magic_name__						:						List[str]										=n

												__magic_name__						:						List[Any]										=0

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

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

				__magic_name__						:						List[str]										=len(neighborhood_of_solution[0] ) - 1

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




def 		lowerCAmelCase_ (						lowerCamelCase						,  lowerCamelCase						,  lowerCamelCase						,  lowerCamelCase						,  lowerCamelCase ):
				__magic_name__						:						List[str]										=1
				__magic_name__						:						List[str]										=first_solution
				__magic_name__						:						int										=[]
				__magic_name__						:						Dict										=distance_of_first_solution
				__magic_name__						:						Union[str, Any]										=solution

				while count <= iters:
								__magic_name__						:						Dict										=find_neighborhood(lowerCamelCase						,  lowerCamelCase )
								__magic_name__						:						Any										=0
								__magic_name__						:						Any										=neighborhood[index_of_best_solution]
								__magic_name__						:						Optional[Any]										=len(lowerCamelCase ) - 1

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

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

								__magic_name__						:						Optional[int]										=count + 1

				return best_solution_ever, best_cost




def 		lowerCAmelCase_ (						lowerCamelCase=None ):
				__magic_name__						:						int										=generate_neighbours(args.File )

				__magic_name__					,			__magic_name__						:						str										=generate_first_solution(
				    args.File						,  lowerCamelCase )

				__magic_name__					,			__magic_name__						:						List[Any]										=tabu_search(
				    lowerCamelCase						,  lowerCamelCase						,  lowerCamelCase						,  args.Iterations						,  args.Size						,  )

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


if __name__ == "__main__":
							UpperCAmelCase_		:					List[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())





'''simple docstring'''






import unittest

from diffusers.pipelines.pipeline_utils import is_safetensors_compatible







class lowercase_       (		unittest.TestCase			):







   """simple docstring"""

   def 	__UpperCAmelCase   (      self      :			Optional[Any]     )  ->			Dict:
        _A    		=  [
            '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(UpperCamelCase__     )     )
   def 	__UpperCAmelCase   (      self      :			Union[str, Any]     )  ->			Optional[Any]:
        _A    		=  [
            'unet/diffusion_pytorch_model.bin',
            'unet/diffusion_pytorch_model.safetensors',
        ]
        self.assertTrue(is_safetensors_compatible(UpperCamelCase__     )     )
   def 	__UpperCAmelCase   (      self      :			str     )  ->			Union[str, Any]:
        _A    		=  [
            '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(UpperCamelCase__     )     )
   def 	__UpperCAmelCase   (      self      :			int     )  ->			Dict:
        _A    		=  [
            'text_encoder/pytorch_model.bin',
            'text_encoder/model.safetensors',
        ]
        self.assertTrue(is_safetensors_compatible(UpperCamelCase__     )     )
   def 	__UpperCAmelCase   (      self      :			Union[str, Any]     )  ->			str:
        _A    		=  [
            '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(UpperCamelCase__     )     )
   def 	__UpperCAmelCase   (      self      :			str     )  ->			Dict:
        _A    		=  [
            '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',
        ]
        _A    		=  'fp16'
        self.assertTrue(is_safetensors_compatible(UpperCamelCase__, variant=UpperCamelCase__     )     )
   def 	__UpperCAmelCase   (      self      :			Optional[int]     )  ->			List[str]:
        _A    		=  [
            'unet/diffusion_pytorch_model.fp16.bin',
            'unet/diffusion_pytorch_model.fp16.safetensors',
        ]
        _A    		=  'fp16'
        self.assertTrue(is_safetensors_compatible(UpperCamelCase__, variant=UpperCamelCase__     )     )
   def 	__UpperCAmelCase   (      self      :			List[str]     )  ->			List[str]:
        # pass variant but use the non-variant filenames
        _A    		=  [
            'unet/diffusion_pytorch_model.bin',
            'unet/diffusion_pytorch_model.safetensors',
        ]
        _A    		=  'fp16'
        self.assertTrue(is_safetensors_compatible(UpperCamelCase__, variant=UpperCamelCase__     )     )
   def 	__UpperCAmelCase   (      self      :			List[Any]     )  ->			Optional[Any]:
        _A    		=  [
            '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',
        ]
        _A    		=  'fp16'
        self.assertFalse(is_safetensors_compatible(UpperCamelCase__, variant=UpperCamelCase__     )     )
   def 	__UpperCAmelCase   (      self      :			Dict     )  ->			Union[str, Any]:
        _A    		=  [
            'text_encoder/pytorch_model.fp16.bin',
            'text_encoder/model.fp16.safetensors',
        ]
        _A    		=  'fp16'
        self.assertTrue(is_safetensors_compatible(UpperCamelCase__, variant=UpperCamelCase__     )     )
   def 	__UpperCAmelCase   (      self      :			Tuple     )  ->			str:
        # pass variant but use the non-variant filenames
        _A    		=  [
            'text_encoder/pytorch_model.bin',
            'text_encoder/model.safetensors',
        ]
        _A    		=  'fp16'
        self.assertTrue(is_safetensors_compatible(UpperCamelCase__, variant=UpperCamelCase__     )     )

   def 	__UpperCAmelCase   (      self      :			List[Any]     )  ->			int:
        _A    		=  [
            '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',
        ]
        _A    		=  'fp16'
        self.assertFalse(is_safetensors_compatible(UpperCamelCase__, variant=UpperCamelCase__     )     )



