


'''simple docstring'''

import argparse
import copy

def _SCREAMING_SNAKE_CASE (A			)			->			List[str]:






       """simple docstring"""







       lowercase__      =					{}

       with open(A			) 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 _SCREAMING_SNAKE_CASE (A    ,					A			)			->			Optional[int]:






       """simple docstring"""







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

       lowercase__      =					[]

       lowercase__      =					start_node

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

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

       first_solution.append(A			)

       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]			)
           - 10_000
       )
       return first_solution, distance_of_first_solution

def _SCREAMING_SNAKE_CASE (A    ,					A			)			->			Optional[Any]:






       """simple docstring"""







       lowercase__      =					[]

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

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

                     lowercase__      =					0

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

                     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 A			: x[index_of_last_item_in_the_list]			)
       return neighborhood_of_solution

def _SCREAMING_SNAKE_CASE (A    ,					A    ,					A    ,					A    ,					A			)			->			Tuple:






       """simple docstring"""







       lowercase__      =					1
       lowercase__      =					first_solution
       lowercase__      =					[]
       lowercase__      =					distance_of_first_solution
       lowercase__      =					solution

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

              lowercase__      =					False
              while not found:
                     lowercase__      =					0
                     while i < len(A			):
                            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(A			) >= size:
                     tabu_list.pop(0			)

              lowercase__      =					count + 1

       return best_solution_ever, best_cost

def _SCREAMING_SNAKE_CASE (A=None			)			->			Tuple:






       """simple docstring"""







       lowercase__      =					generate_neighbours(args.File			)

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

       lowercase__     ,lowercase__      =					tabu_search(
           A    ,					A    ,					A    ,					args.Iterations    ,					args.Size    ,					)

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


if __name__ == "__main__":
 lowerCamelCase				:  Tuple    		=      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 transformers import RoFormerTokenizer, RoFormerTokenizerFast
from transformers.testing_utils import require_rjieba, require_tokenizers

from ...test_tokenization_common import TokenizerTesterMixin
@require_rjieba
@require_tokenizers
class     __lowerCAmelCase		(lowercase_    ,	unittest.TestCase	):





      '''simple docstring'''






      lowerCAmelCase__   :	str       =				RoFormerTokenizer
      lowerCAmelCase__   :	Dict       =				RoFormerTokenizerFast
      lowerCAmelCase__   :	List[str]       =				True
      lowerCAmelCase__   :	List[str]       =				True



      def  UpperCamelCase__						(self       :       Dict					):

             '''simple docstring'''







             super().setUp()



      def  UpperCamelCase__						(self       :       List[str]  ,		**UpperCamelCase       :       Dict					):

             '''simple docstring'''







             return self.tokenizer_class.from_pretrained('''junnyu/roformer_chinese_base'''  ,		**UpperCamelCase					)



      def  UpperCamelCase__						(self       :       List[str]  ,		**UpperCamelCase       :       int					):

             '''simple docstring'''







             return self.rust_tokenizer_class.from_pretrained('''junnyu/roformer_chinese_base'''  ,		**UpperCamelCase					)



      def  UpperCamelCase__						(self       :       List[str]					):

             '''simple docstring'''







             lowercase__      =					'''永和服装饰品有限公司,今天天气非常好'''
             lowercase__      =					'''永和 服装 饰品 有限公司 , 今 天 天 气 非常 好'''
             return input_text, output_text



      def  UpperCamelCase__						(self       :       int					):

             '''simple docstring'''







             lowercase__      =					self.get_tokenizer()
             lowercase__     ,lowercase__      =					self.get_chinese_input_output_texts()
             lowercase__      =					tokenizer.tokenize(UpperCamelCase					)

             self.assertListEqual(UpperCamelCase  ,		output_text.split()					)

             lowercase__      =					tokens + [tokenizer.unk_token]
             lowercase__      =					[22943, 21332, 34431, 45904, 117, 306, 1231, 1231, 2653, 33994, 1266, 100]
             self.assertListEqual(tokenizer.convert_tokens_to_ids(UpperCamelCase					)  ,		UpperCamelCase					)



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

             '''simple docstring'''







             lowercase__      =					self.get_rust_tokenizer()
             lowercase__     ,lowercase__      =					self.get_chinese_input_output_texts()
             lowercase__      =					tokenizer.tokenize(UpperCamelCase					)
             self.assertListEqual(UpperCamelCase  ,		output_text.split()					)
             lowercase__      =					tokens + [tokenizer.unk_token]
             lowercase__      =					[22943, 21332, 34431, 45904, 117, 306, 1231, 1231, 2653, 33994, 1266, 100]
             self.assertListEqual(tokenizer.convert_tokens_to_ids(UpperCamelCase					)  ,		UpperCamelCase					)



      def  UpperCamelCase__						(self       :       str					):

             '''simple docstring'''







             pass



      def  UpperCamelCase__						(self       :       Any					):

             '''simple docstring'''







             pass






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

             '''simple docstring'''







             pass




