



"""simple docstring"""

import json
from typing import List, Optional, Tuple

from tokenizers import pre_tokenizers, processors

from ...tokenization_utils_base import AddedToken, BatchEncoding
from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import logging
from .tokenization_bart import BartTokenizer


a_			   =					logging.get_logger(__name__)


a_			   =					{'''vocab_file''': '''vocab.json''', '''merges_file''': '''merges.txt''', '''tokenizer_file''': '''tokenizer.json'''}

# See all BART models at https://huggingface.co/models?filter=bart
a_			   =					{
    '''vocab_file''': {
        '''facebook/bart-base''': '''https://huggingface.co/facebook/bart-base/resolve/main/vocab.json''',
        '''facebook/bart-large''': '''https://huggingface.co/facebook/bart-large/resolve/main/vocab.json''',
        '''facebook/bart-large-mnli''': '''https://huggingface.co/facebook/bart-large-mnli/resolve/main/vocab.json''',
        '''facebook/bart-large-cnn''': '''https://huggingface.co/facebook/bart-large-cnn/resolve/main/vocab.json''',
        '''facebook/bart-large-xsum''': '''https://huggingface.co/facebook/bart-large-xsum/resolve/main/vocab.json''',
        '''yjernite/bart_eli5''': '''https://huggingface.co/yjernite/bart_eli5/resolve/main/vocab.json''',
    },
    '''merges_file''': {
        '''facebook/bart-base''': '''https://huggingface.co/facebook/bart-base/resolve/main/merges.txt''',
        '''facebook/bart-large''': '''https://huggingface.co/facebook/bart-large/resolve/main/merges.txt''',
        '''facebook/bart-large-mnli''': '''https://huggingface.co/facebook/bart-large-mnli/resolve/main/merges.txt''',
        '''facebook/bart-large-cnn''': '''https://huggingface.co/facebook/bart-large-cnn/resolve/main/merges.txt''',
        '''facebook/bart-large-xsum''': '''https://huggingface.co/facebook/bart-large-xsum/resolve/main/merges.txt''',
        '''yjernite/bart_eli5''': '''https://huggingface.co/yjernite/bart_eli5/resolve/main/merges.txt''',
    },
    '''tokenizer_file''': {
        '''facebook/bart-base''': '''https://huggingface.co/facebook/bart-base/resolve/main/tokenizer.json''',
        '''facebook/bart-large''': '''https://huggingface.co/facebook/bart-large/resolve/main/tokenizer.json''',
        '''facebook/bart-large-mnli''': '''https://huggingface.co/facebook/bart-large-mnli/resolve/main/tokenizer.json''',
        '''facebook/bart-large-cnn''': '''https://huggingface.co/facebook/bart-large-cnn/resolve/main/tokenizer.json''',
        '''facebook/bart-large-xsum''': '''https://huggingface.co/facebook/bart-large-xsum/resolve/main/tokenizer.json''',
        '''yjernite/bart_eli5''': '''https://huggingface.co/yjernite/bart_eli5/resolve/main/tokenizer.json''',
    },
}

a_			   =					{
    '''facebook/bart-base''': 1024,
    '''facebook/bart-large''': 1024,
    '''facebook/bart-large-mnli''': 1024,
    '''facebook/bart-large-cnn''': 1024,
    '''facebook/bart-large-xsum''': 1024,
    '''yjernite/bart_eli5''': 1024,
}







class    __lowercase     (					_UpperCAmelCase):







						"""simple docstring"""







						_A		:							Optional[Any]							       =		VOCAB_FILES_NAMES
						_A		:							Optional[Any]							       =		PRETRAINED_VOCAB_FILES_MAP
						_A		:							Optional[int]							       =		PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
						_A		:							List[Any]							       =		["""input_ids""", """attention_mask"""]
						_A		:							List[str]							       =		BartTokenizer







						def __init__(self   ,		lowercase__=None   ,		lowercase__=None   ,		lowercase__=None   ,		lowercase__="replace"   ,		lowercase__="<s>"   ,		lowercase__="</s>"   ,		lowercase__="</s>"   ,		lowercase__="<s>"   ,		lowercase__="<unk>"   ,		lowercase__="<pad>"   ,		lowercase__="<mask>"   ,		lowercase__=False   ,		lowercase__=True   ,		**lowercase__   ,		):
											super().__init__(
											    lowercase__   ,		lowercase__   ,		tokenizer_file=lowercase__   ,		errors=lowercase__   ,		bos_token=lowercase__   ,		eos_token=lowercase__   ,		sep_token=lowercase__   ,		cls_token=lowercase__   ,		unk_token=lowercase__   ,		pad_token=lowercase__   ,		mask_token=lowercase__   ,		add_prefix_space=lowercase__   ,		trim_offsets=lowercase__   ,		**lowercase__   ,		)

											snake_case_					:		int 					=					json.loads(self.backend_tokenizer.pre_tokenizer.__getstate__()       )
											if pre_tok_state.get("""add_prefix_space"""   ,		lowercase__       ) != add_prefix_space:
																snake_case_					:		List[str] 					=					getattr(lowercase__   ,		pre_tok_state.pop("""type"""       )       )
																snake_case_					:		int 					=					add_prefix_space
																snake_case_					:		List[Any] 					=					pre_tok_class(**lowercase__       )

											snake_case_					:		List[str] 					=					add_prefix_space

											# the pre_tokenizer is already updated in the GPT2TokenizerFast `__init__`
											snake_case_					:		int 					=					"""post_processor"""
											snake_case_					:		Union[str, Any] 					=					getattr(self.backend_tokenizer   ,		lowercase__   ,		lowercase__       )
											if tokenizer_component_instance:
																snake_case_					:		List[Any] 					=					json.loads(tokenizer_component_instance.__getstate__()       )

																# The lists 'sep' and 'cls' must be cased in tuples for the object `post_processor_class`
																if "sep" in state:
																					snake_case_					:		int 					=					tuple(state["""sep"""]       )
																if "cls" in state:
																					snake_case_					:		List[Any] 					=					tuple(state["""cls"""]       )

																snake_case_					:		str 					=					False

																if state.get("""add_prefix_space"""   ,		lowercase__       ) != add_prefix_space:
																					snake_case_					:		Optional[int] 					=					add_prefix_space
																					snake_case_					:		int 					=					True

																if state.get("""trim_offsets"""   ,		lowercase__       ) != trim_offsets:
																					snake_case_					:		int 					=					trim_offsets
																					snake_case_					:		int 					=					True

																if changes_to_apply:
																					snake_case_					:		int 					=					getattr(lowercase__   ,		state.pop("""type"""       )       )
																					snake_case_					:		List[str] 					=					component_class(**lowercase__       )
																					setattr(self.backend_tokenizer   ,		lowercase__   ,		lowercase__       )







						@property
						def 						__UpperCamelCase							(self       ):
											if self._mask_token is None:
																if self.verbose:
																					logger.error("""Using mask_token, but it is not set yet."""       )
																return None
											return str(self._mask_token       )







						@mask_token.setter
						def 						__UpperCamelCase							(self   ,		lowercase__       ):
											snake_case_					:		Optional[Any] 					=					AddedToken(lowercase__   ,		lstrip=lowercase__   ,		rstrip=lowercase__       ) if isinstance(lowercase__   ,		lowercase__       ) else value
											snake_case_					:		Tuple 					=					value







						def 						__UpperCamelCase							(self   ,		*lowercase__   ,		**lowercase__       ):
											snake_case_					:		Union[str, Any] 					=					kwargs.get("""is_split_into_words"""   ,		lowercase__       )

											if is_split_into_words and not self.add_prefix_space:
																raise ValueError(
																    f'You need to instantiate {self.__class__.__name__} with add_prefix_space=True '
																    """to use it with pretokenized inputs."""       )

											return super()._batch_encode_plus(*lowercase__   ,		**lowercase__       )







						def 						__UpperCamelCase							(self   ,		*lowercase__   ,		**lowercase__       ):
											snake_case_					:		Dict 					=					kwargs.get("""is_split_into_words"""   ,		lowercase__       )

											if is_split_into_words and not self.add_prefix_space:
																raise ValueError(
																    f'You need to instantiate {self.__class__.__name__} with add_prefix_space=True '
																    """to use it with pretokenized inputs."""       )

											return super()._encode_plus(*lowercase__   ,		**lowercase__       )







						def 						__UpperCamelCase							(self   ,		lowercase__   ,		lowercase__ = None       ):
											snake_case_					:		Optional[Any] 					=					self._tokenizer.model.save(lowercase__   ,		name=lowercase__       )
											return tuple(lowercase__       )







						def 						__UpperCamelCase							(self   ,		lowercase__   ,		lowercase__=None       ):
											snake_case_					:		int 					=					[self.bos_token_id] + token_ids_a + [self.eos_token_id]
											if token_ids_a is None:
																return output

											return output + [self.eos_token_id] + token_ids_a + [self.eos_token_id]







						def 						__UpperCamelCase							(self   ,		lowercase__   ,		lowercase__ = None       ):
											snake_case_					:		Optional[Any] 					=					[self.sep_token_id]
											snake_case_					:		List[Any] 					=					[self.cls_token_id]

											if token_ids_a is None:
																return len(cls + token_ids_a + sep       ) * [0]
											return len(cls + token_ids_a + sep + sep + token_ids_a + sep       ) * [0]









"""simple docstring"""

import argparse
import copy







def 							SCREAMING_SNAKE_CASE__      (		SCREAMING_SNAKE_CASE__ :  Any			):



					"""simple docstring"""





					snake_case_					:		List[Any] 					=					{}

					with open(SCREAMING_SNAKE_CASE__			) as f:
										for line in f:
															if line.split()[0] not in dict_of_neighbours:
																				snake_case_					:		int 					=					[]
																				_list.append([line.split()[1], line.split()[2]]			)
																				snake_case_					:		Optional[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:
																				snake_case_					:		str 					=					[]
																				_list.append([line.split()[0], line.split()[2]]			)
																				snake_case_					:		Optional[Any] 					=					_list
															else:
																				dict_of_neighbours[line.split()[1]].append(
																				    [line.split()[0], line.split()[2]]			)

					return dict_of_neighbours







def 							SCREAMING_SNAKE_CASE__      (		SCREAMING_SNAKE_CASE__ :  List[Any]				,    SCREAMING_SNAKE_CASE__ :  str			):



					"""simple docstring"""





					with open(SCREAMING_SNAKE_CASE__			) as f:
										snake_case_					:		Optional[Any] 					=					f.read(1			)
					snake_case_					:		Union[str, Any] 					=					start_node

					snake_case_					:		Dict 					=					[]

					snake_case_					:		Union[str, Any] 					=					start_node

					snake_case_					:		Tuple 					=					0
					while visiting not in first_solution:
										snake_case_					:		int 					=					1_0_0_0_0
										for k in dict_of_neighbours[visiting]:
															if int(k[1]			) < int(SCREAMING_SNAKE_CASE__			) and k[0] not in first_solution:
																				snake_case_					:		Union[str, Any] 					=					k[1]
																				snake_case_					:		Any 					=					k[0]

										first_solution.append(SCREAMING_SNAKE_CASE__			)
										snake_case_					:		Tuple 					=					distance_of_first_solution + int(SCREAMING_SNAKE_CASE__			)
										snake_case_					:		List[str] 					=					best_node

					first_solution.append(SCREAMING_SNAKE_CASE__			)

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

					snake_case_					:		int 					=					(
					    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 							SCREAMING_SNAKE_CASE__      (		SCREAMING_SNAKE_CASE__ :  Union[str, Any]				,    SCREAMING_SNAKE_CASE__ :  Optional[int]			):



					"""simple docstring"""





					snake_case_					:		Union[str, Any] 					=					[]

					for n in solution[1:-1]:
										snake_case_					:		str 					=					solution.index(SCREAMING_SNAKE_CASE__			)
										for kn in solution[1:-1]:
															snake_case_					:		Tuple 					=					solution.index(SCREAMING_SNAKE_CASE__			)
															if n == kn:
																				continue

															snake_case_					:		Optional[Any] 					=					copy.deepcopy(SCREAMING_SNAKE_CASE__			)
															snake_case_					:		int 					=					kn
															snake_case_					:		Dict 					=					n

															snake_case_					:		Optional[int] 					=					0

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

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

					snake_case_					:		Optional[Any] 					=					len(neighborhood_of_solution[0]			) - 1

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







def 							SCREAMING_SNAKE_CASE__      (		SCREAMING_SNAKE_CASE__ :  List[str]				,    SCREAMING_SNAKE_CASE__ :  Dict				,    SCREAMING_SNAKE_CASE__ :  List[Any]				,    SCREAMING_SNAKE_CASE__ :  str				,    SCREAMING_SNAKE_CASE__ :  List[Any]			):



					"""simple docstring"""





					snake_case_					:		Dict 					=					1
					snake_case_					:		List[Any] 					=					first_solution
					snake_case_					:		List[Any] 					=					[]
					snake_case_					:		Optional[Any] 					=					distance_of_first_solution
					snake_case_					:		Dict 					=					solution

					while count <= iters:
										snake_case_					:		List[str] 					=					find_neighborhood(SCREAMING_SNAKE_CASE__				,    SCREAMING_SNAKE_CASE__			)
										snake_case_					:		List[Any] 					=					0
										snake_case_					:		List[Any] 					=					neighborhood[index_of_best_solution]
										snake_case_					:		Union[str, Any] 					=					len(SCREAMING_SNAKE_CASE__			) - 1

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

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

										snake_case_					:		List[str] 					=					count + 1

					return best_solution_ever, best_cost







def 							SCREAMING_SNAKE_CASE__      (		SCREAMING_SNAKE_CASE__ :  Optional[Any]=None			):



					"""simple docstring"""





					snake_case_					:		Tuple 					=					generate_neighbours(args.File			)

					snake_case_					,			snake_case_					:		Optional[Any] 					=					generate_first_solution(
					    args.File				,    SCREAMING_SNAKE_CASE__			)

					snake_case_					,			snake_case_					:		Dict 					=					tabu_search(
					    SCREAMING_SNAKE_CASE__				,    SCREAMING_SNAKE_CASE__				,    SCREAMING_SNAKE_CASE__				,    args.Iterations				,    args.Size				,    )

					print(f'Best solution: {best_sol}, with total distance: {best_cost}.'			)


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




