






import argparse
import copy






def 						a    (		lowerCamelCase_       ):






				'''simple docstring'''
				lowercase__     				=    {}

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

				return dict_of_neighbours






def 						a    (		lowerCamelCase_	,     lowerCamelCase_       ):






				'''simple docstring'''

				with open(snake_case__       ) as f:
								lowercase__     				=    f.read(1       )
				lowercase__     				=    start_node

				lowercase__     				=    []

				lowercase__     				=    start_node

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

								first_solution.append(snake_case__       )
								lowercase__     				=    distance_of_first_solution + int(snake_case__       )
								lowercase__     				=    best_node

				first_solution.append(snake_case__       )

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

				lowercase__     				=    (
				    distance_of_first_solution
				    + int(dict_of_neighbours[first_solution[-2]][position][1]       )
				    - 1_0000
				)
				return first_solution, distance_of_first_solution






def 						a    (		lowerCamelCase_	,     lowerCamelCase_       ):






				'''simple docstring'''
				lowercase__     				=    []

				for n in solution[1:-1]:
								lowercase__     				=    solution.index(snake_case__       )
								for kn in solution[1:-1]:
												lowercase__     				=    solution.index(snake_case__       )
												if n == kn:
																continue

												lowercase__     				=    copy.deepcopy(snake_case__       )
												lowercase__     				=    kn
												lowercase__     				=    n

												lowercase__     				=    0

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

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

				lowercase__     				=    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 						a    (		lowerCamelCase_	,     lowerCamelCase_	,     lowerCamelCase_	,     lowerCamelCase_	,     lowerCamelCase_       ):






				'''simple docstring'''
				lowercase__     				=    1
				lowercase__     				=    first_solution
				lowercase__     				=    []
				lowercase__     				=    distance_of_first_solution
				lowercase__     				=    solution

				while count <= iters:
								lowercase__     				=    find_neighborhood(snake_case__	,     snake_case__       )
								lowercase__     				=    0
								lowercase__     				=    neighborhood[index_of_best_solution]
								lowercase__     				=    len(snake_case__       ) - 1

								lowercase__     				=    False
								while not found:
												lowercase__     				=    0
												while i < len(snake_case__       ):
																if best_solution[i] != solution[i]:
																				lowercase__     				=    best_solution[i]
																				lowercase__     				=    solution[i]
																				break
																lowercase__     				=    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__     				=    True
																lowercase__     				=    best_solution[:-1]
																lowercase__     				=    neighborhood[index_of_best_solution][best_cost_index]
																if cost < best_cost:
																				lowercase__     				=    cost
																				lowercase__     				=    solution
												else:
																lowercase__     				=    index_of_best_solution + 1
																lowercase__     				=    neighborhood[index_of_best_solution]

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

								lowercase__     				=    count + 1

				return best_solution_ever, best_cost






def 						a    (		lowerCamelCase_=None       ):






				'''simple docstring'''
				lowercase__     				=    generate_neighbours(args.File       )

				lowercase__				,		lowercase__     				=    generate_first_solution(
				    args.File	,     snake_case__       )

				lowercase__				,		lowercase__     				=    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__":
							A__			:    int         =				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())












import json
from typing import List, Optional, Tuple

from tokenizers import normalizers

from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import logging
from .tokenization_bert import BertTokenizer


A__			:    Dict         =				logging.get_logger(__name__)

A__			:    Dict         =				{'vocab_file': 'vocab.txt', 'tokenizer_file': 'tokenizer.json'}

A__			:    Optional[int]         =				{
    'vocab_file': {
        'bert-base-uncased': 'https://huggingface.co/bert-base-uncased/resolve/main/vocab.txt',
        'bert-large-uncased': 'https://huggingface.co/bert-large-uncased/resolve/main/vocab.txt',
        'bert-base-cased': 'https://huggingface.co/bert-base-cased/resolve/main/vocab.txt',
        'bert-large-cased': 'https://huggingface.co/bert-large-cased/resolve/main/vocab.txt',
        'bert-base-multilingual-uncased': (
            'https://huggingface.co/bert-base-multilingual-uncased/resolve/main/vocab.txt'
        ),
        'bert-base-multilingual-cased': 'https://huggingface.co/bert-base-multilingual-cased/resolve/main/vocab.txt',
        'bert-base-chinese': 'https://huggingface.co/bert-base-chinese/resolve/main/vocab.txt',
        'bert-base-german-cased': 'https://huggingface.co/bert-base-german-cased/resolve/main/vocab.txt',
        'bert-large-uncased-whole-word-masking': (
            'https://huggingface.co/bert-large-uncased-whole-word-masking/resolve/main/vocab.txt'
        ),
        'bert-large-cased-whole-word-masking': (
            'https://huggingface.co/bert-large-cased-whole-word-masking/resolve/main/vocab.txt'
        ),
        'bert-large-uncased-whole-word-masking-finetuned-squad': (
            'https://huggingface.co/bert-large-uncased-whole-word-masking-finetuned-squad/resolve/main/vocab.txt'
        ),
        'bert-large-cased-whole-word-masking-finetuned-squad': (
            'https://huggingface.co/bert-large-cased-whole-word-masking-finetuned-squad/resolve/main/vocab.txt'
        ),
        'bert-base-cased-finetuned-mrpc': (
            'https://huggingface.co/bert-base-cased-finetuned-mrpc/resolve/main/vocab.txt'
        ),
        'bert-base-german-dbmdz-cased': 'https://huggingface.co/bert-base-german-dbmdz-cased/resolve/main/vocab.txt',
        'bert-base-german-dbmdz-uncased': (
            'https://huggingface.co/bert-base-german-dbmdz-uncased/resolve/main/vocab.txt'
        ),
        'TurkuNLP/bert-base-finnish-cased-v1': (
            'https://huggingface.co/TurkuNLP/bert-base-finnish-cased-v1/resolve/main/vocab.txt'
        ),
        'TurkuNLP/bert-base-finnish-uncased-v1': (
            'https://huggingface.co/TurkuNLP/bert-base-finnish-uncased-v1/resolve/main/vocab.txt'
        ),
        'wietsedv/bert-base-dutch-cased': (
            'https://huggingface.co/wietsedv/bert-base-dutch-cased/resolve/main/vocab.txt'
        ),
    },
    'tokenizer_file': {
        'bert-base-uncased': 'https://huggingface.co/bert-base-uncased/resolve/main/tokenizer.json',
        'bert-large-uncased': 'https://huggingface.co/bert-large-uncased/resolve/main/tokenizer.json',
        'bert-base-cased': 'https://huggingface.co/bert-base-cased/resolve/main/tokenizer.json',
        'bert-large-cased': 'https://huggingface.co/bert-large-cased/resolve/main/tokenizer.json',
        'bert-base-multilingual-uncased': (
            'https://huggingface.co/bert-base-multilingual-uncased/resolve/main/tokenizer.json'
        ),
        'bert-base-multilingual-cased': (
            'https://huggingface.co/bert-base-multilingual-cased/resolve/main/tokenizer.json'
        ),
        'bert-base-chinese': 'https://huggingface.co/bert-base-chinese/resolve/main/tokenizer.json',
        'bert-base-german-cased': 'https://huggingface.co/bert-base-german-cased/resolve/main/tokenizer.json',
        'bert-large-uncased-whole-word-masking': (
            'https://huggingface.co/bert-large-uncased-whole-word-masking/resolve/main/tokenizer.json'
        ),
        'bert-large-cased-whole-word-masking': (
            'https://huggingface.co/bert-large-cased-whole-word-masking/resolve/main/tokenizer.json'
        ),
        'bert-large-uncased-whole-word-masking-finetuned-squad': (
            'https://huggingface.co/bert-large-uncased-whole-word-masking-finetuned-squad/resolve/main/tokenizer.json'
        ),
        'bert-large-cased-whole-word-masking-finetuned-squad': (
            'https://huggingface.co/bert-large-cased-whole-word-masking-finetuned-squad/resolve/main/tokenizer.json'
        ),
        'bert-base-cased-finetuned-mrpc': (
            'https://huggingface.co/bert-base-cased-finetuned-mrpc/resolve/main/tokenizer.json'
        ),
        'bert-base-german-dbmdz-cased': (
            'https://huggingface.co/bert-base-german-dbmdz-cased/resolve/main/tokenizer.json'
        ),
        'bert-base-german-dbmdz-uncased': (
            'https://huggingface.co/bert-base-german-dbmdz-uncased/resolve/main/tokenizer.json'
        ),
        'TurkuNLP/bert-base-finnish-cased-v1': (
            'https://huggingface.co/TurkuNLP/bert-base-finnish-cased-v1/resolve/main/tokenizer.json'
        ),
        'TurkuNLP/bert-base-finnish-uncased-v1': (
            'https://huggingface.co/TurkuNLP/bert-base-finnish-uncased-v1/resolve/main/tokenizer.json'
        ),
        'wietsedv/bert-base-dutch-cased': (
            'https://huggingface.co/wietsedv/bert-base-dutch-cased/resolve/main/tokenizer.json'
        ),
    },
}

A__			:    List[str]         =				{
    'bert-base-uncased': 5_12,
    'bert-large-uncased': 5_12,
    'bert-base-cased': 5_12,
    'bert-large-cased': 5_12,
    'bert-base-multilingual-uncased': 5_12,
    'bert-base-multilingual-cased': 5_12,
    'bert-base-chinese': 5_12,
    'bert-base-german-cased': 5_12,
    'bert-large-uncased-whole-word-masking': 5_12,
    'bert-large-cased-whole-word-masking': 5_12,
    'bert-large-uncased-whole-word-masking-finetuned-squad': 5_12,
    'bert-large-cased-whole-word-masking-finetuned-squad': 5_12,
    'bert-base-cased-finetuned-mrpc': 5_12,
    'bert-base-german-dbmdz-cased': 5_12,
    'bert-base-german-dbmdz-uncased': 5_12,
    'TurkuNLP/bert-base-finnish-cased-v1': 5_12,
    'TurkuNLP/bert-base-finnish-uncased-v1': 5_12,
    'wietsedv/bert-base-dutch-cased': 5_12,
}

A__			:    Optional[int]         =				{
    'bert-base-uncased': {'do_lower_case': True},
    'bert-large-uncased': {'do_lower_case': True},
    'bert-base-cased': {'do_lower_case': False},
    'bert-large-cased': {'do_lower_case': False},
    'bert-base-multilingual-uncased': {'do_lower_case': True},
    'bert-base-multilingual-cased': {'do_lower_case': False},
    'bert-base-chinese': {'do_lower_case': False},
    'bert-base-german-cased': {'do_lower_case': False},
    'bert-large-uncased-whole-word-masking': {'do_lower_case': True},
    'bert-large-cased-whole-word-masking': {'do_lower_case': False},
    'bert-large-uncased-whole-word-masking-finetuned-squad': {'do_lower_case': True},
    'bert-large-cased-whole-word-masking-finetuned-squad': {'do_lower_case': False},
    'bert-base-cased-finetuned-mrpc': {'do_lower_case': False},
    'bert-base-german-dbmdz-cased': {'do_lower_case': False},
    'bert-base-german-dbmdz-uncased': {'do_lower_case': True},
    'TurkuNLP/bert-base-finnish-cased-v1': {'do_lower_case': False},
    'TurkuNLP/bert-base-finnish-uncased-v1': {'do_lower_case': True},
    'wietsedv/bert-base-dutch-cased': {'do_lower_case': False},
}
class    _UpperCAmelCase      ( A__			):

				"""simple docstring"""




				lowercase__       							= VOCAB_FILES_NAMES
				lowercase__       							= PRETRAINED_VOCAB_FILES_MAP
				lowercase__       							= PRETRAINED_INIT_CONFIGURATION
				lowercase__       							= PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
				lowercase__       							= BertTokenizer




				def __init__(  self		:					Any,						lowerCamelCase		:					Optional[Any]=None,						lowerCamelCase		:					Any=None,						lowerCamelCase		:					Tuple=True,						lowerCamelCase		:					Dict="[UNK]",						lowerCamelCase		:					Any="[SEP]",						lowerCamelCase		:					List[Any]="[PAD]",						lowerCamelCase		:					Optional[Any]="[CLS]",						lowerCamelCase		:					Dict="[MASK]",						lowerCamelCase		:					List[Any]=True,						lowerCamelCase		:					Tuple=None,						**lowerCamelCase		:					Dict,						):

								'''simple docstring'''
								super().__init__(
								    lowerCamelCase,						tokenizer_file=lowerCamelCase,						do_lower_case=lowerCamelCase,						unk_token=lowerCamelCase,						sep_token=lowerCamelCase,						pad_token=lowerCamelCase,						cls_token=lowerCamelCase,						mask_token=lowerCamelCase,						tokenize_chinese_chars=lowerCamelCase,						strip_accents=lowerCamelCase,						**lowerCamelCase,						)

								lowercase__     				=    json.loads(self.backend_tokenizer.normalizer.__getstate__()						)
								if (
								    normalizer_state.get('''lowercase''',						lowerCamelCase						) != do_lower_case
								    or normalizer_state.get('''strip_accents''',						lowerCamelCase						) != strip_accents
								    or normalizer_state.get('''handle_chinese_chars''',						lowerCamelCase						) != tokenize_chinese_chars
								):
												lowercase__     				=    getattr(lowerCamelCase,						normalizer_state.pop('''type'''						)						)
												lowercase__     				=    do_lower_case
												lowercase__     				=    strip_accents
												lowercase__     				=    tokenize_chinese_chars
												lowercase__     				=    normalizer_class(**lowerCamelCase						)

								lowercase__     				=    do_lower_case




				def        lowercase__     (  self		:					Any,						lowerCamelCase		:					List[Any],						lowerCamelCase		:					Dict=None						):

								'''simple docstring'''
								lowercase__     				=    [self.cls_token_id] + token_ids_a + [self.sep_token_id]

								if token_ids_a:
												output += token_ids_a + [self.sep_token_id]

								return output




				def        lowercase__     (  self		:					List[Any],						lowerCamelCase		:					List[int],						lowerCamelCase		:					Optional[List[int]] = None						):

								'''simple docstring'''
								lowercase__     				=    [self.sep_token_id]
								lowercase__     				=    [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						) * [0] + len(token_ids_a + sep						) * [1]




				def        lowercase__     (  self		:					Any,						lowerCamelCase		:					str,						lowerCamelCase		:					Optional[str] = None						):

								'''simple docstring'''
								lowercase__     				=    self._tokenizer.model.save(lowerCamelCase,						name=lowerCamelCase						)
								return tuple(lowerCamelCase						)




