

'''simple docstring'''

import argparse
import copy

def 					__UpperCamelCase				(						lowercase__    :	Any			):






     '''simple docstring'''





     __lowercase      		={}

     with open(lowercase__			) 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 					__UpperCamelCase				(						lowercase__    :	Union[str, Any],       lowercase__    :	List[Any]			):






     '''simple docstring'''





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

     __lowercase      		=[]

     __lowercase      		=start_node

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

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

     first_solution.append(lowercase__			)

     __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_00_00
     )
     return first_solution, distance_of_first_solution

def 					__UpperCamelCase				(						lowercase__    :	Optional[Any],       lowercase__    :	int			):






     '''simple docstring'''





     __lowercase      		=[]

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

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

               __lowercase      		=0

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

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

def 					__UpperCamelCase				(						lowercase__    :	int,       lowercase__    :	Tuple,       lowercase__    :	Tuple,       lowercase__    :	List[Any],       lowercase__    :	Optional[Any]			):






     '''simple docstring'''





     __lowercase      		=1
     __lowercase      		=first_solution
     __lowercase      		=[]
     __lowercase      		=distance_of_first_solution
     __lowercase      		=solution

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

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

          __lowercase      		=count + 1

     return best_solution_ever, best_cost

def 					__UpperCamelCase				(						lowercase__    :	Dict=None			):






     '''simple docstring'''





     __lowercase      		=generate_neighbours(args.File			)

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

     __lowercase		,  __lowercase      		=tabu_search(
         lowercase__,       lowercase__,       lowercase__,       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())





'''simple docstring'''

from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_flax_available,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
    is_vision_available,
)


UpperCAmelCase					 =	{
    '''configuration_owlvit''': [
        '''OWLVIT_PRETRAINED_CONFIG_ARCHIVE_MAP''',
        '''OwlViTConfig''',
        '''OwlViTOnnxConfig''',
        '''OwlViTTextConfig''',
        '''OwlViTVisionConfig''',
    ],
    '''processing_owlvit''': ['''OwlViTProcessor'''],
}


try:
       if not is_vision_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       UpperCAmelCase					 =	['''OwlViTFeatureExtractor''']
       UpperCAmelCase					 =	['''OwlViTImageProcessor''']

try:
       if not is_torch_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       UpperCAmelCase					 =	[
           '''OWLVIT_PRETRAINED_MODEL_ARCHIVE_LIST''',
           '''OwlViTModel''',
           '''OwlViTPreTrainedModel''',
           '''OwlViTTextModel''',
           '''OwlViTVisionModel''',
           '''OwlViTForObjectDetection''',
       ]

if TYPE_CHECKING:
       from .configuration_owlvit import (
           OWLVIT_PRETRAINED_CONFIG_ARCHIVE_MAP,
           OwlViTConfig,
           OwlViTOnnxConfig,
           OwlViTTextConfig,
           OwlViTVisionConfig,
       )
       from .processing_owlvit import OwlViTProcessor

       try:
              if not is_vision_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .feature_extraction_owlvit import OwlViTFeatureExtractor
              from .image_processing_owlvit import OwlViTImageProcessor

       try:
              if not is_torch_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .modeling_owlvit import (
                  OWLVIT_PRETRAINED_MODEL_ARCHIVE_LIST,
                  OwlViTForObjectDetection,
                  OwlViTModel,
                  OwlViTPreTrainedModel,
                  OwlViTTextModel,
                  OwlViTVisionModel,
              )

else:
       import sys

       UpperCAmelCase					 =	_LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)


