


'''simple docstring'''
import argparse
import copy


def       _lowercase							(					UpperCamelCase__							:       Optional[Any]      ):
 __A	:		Dict	  =      {}

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

 return dict_of_neighbours


def       _lowercase							(					UpperCamelCase__							:       Dict,					UpperCamelCase__							:       Union[str, Any]      ):

 with open(UpperCamelCase__      ) as f:
  __A	:		Union[str, Any]	  =      f.read(1      )
 __A	:		Dict	  =      start_node

 __A	:		List[str]	  =      []

 __A	:		str	  =      start_node

 __A	:		Optional[int]	  =      0
 while visiting not in first_solution:
  __A	:		List[Any]	  =      10000
  for k in dict_of_neighbours[visiting]:
   if int(k[1]      ) < int(UpperCamelCase__      ) and k[0] not in first_solution:
    __A	:		int	  =      k[1]
    __A	:		int	  =      k[0]

  first_solution.append(UpperCamelCase__      )
  __A	:		Union[str, Any]	  =      distance_of_first_solution + int(UpperCamelCase__      )
  __A	:		Dict	  =      best_node

 first_solution.append(UpperCamelCase__      )

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

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


def       _lowercase							(					UpperCamelCase__							:       str,					UpperCamelCase__							:       Any      ):
 __A	:		Tuple	  =      []

 for n in solution[1:-1]:
  __A	:		Any	  =      solution.index(UpperCamelCase__      )
  for kn in solution[1:-1]:
   __A	:		Optional[Any]	  =      solution.index(UpperCamelCase__      )
   if n == kn:
    continue

   __A	:		str	  =      copy.deepcopy(UpperCamelCase__      )
   __A	:		List[str]	  =      kn
   __A	:		Optional[int]	  =      n

   __A	:		List[Any]	  =      0

   for k in _tmp[:-1]:
    __A	:		int	  =      _tmp[_tmp.index(UpperCamelCase__      ) + 1]
    for i in dict_of_neighbours[k]:
     if i[0] == next_node:
      __A	:		Union[str, Any]	  =      distance + int(i[1]      )
   _tmp.append(UpperCamelCase__      )

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

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

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


def       _lowercase							(					UpperCamelCase__							:       Dict,					UpperCamelCase__							:       Optional[Any],					UpperCamelCase__							:       List[Any],					UpperCamelCase__							:       List[str],					UpperCamelCase__							:       Tuple      ):
 __A	:		int	  =      1
 __A	:		int	  =      first_solution
 __A	:		Dict	  =      []
 __A	:		int	  =      distance_of_first_solution
 __A	:		Optional[int]	  =      solution

 while count <= iters:
  __A	:		int	  =      find_neighborhood(UpperCamelCase__,					UpperCamelCase__      )
  __A	:		Tuple	  =      0
  __A	:		Tuple	  =      neighborhood[index_of_best_solution]
  __A	:		Optional[Any]	  =      len(UpperCamelCase__      ) - 1

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

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

  __A	:		List[Any]	  =      count + 1

 return best_solution_ever, best_cost


def       _lowercase							(					UpperCamelCase__							:       Tuple=None      ):
 __A	:		List[str]	  =      generate_neighbours(args.File      )

 __A  ,__A	:		Dict	  =      generate_first_solution(
     args.File,					UpperCamelCase__      )

 __A  ,__A	:		Any	  =      tabu_search(
     UpperCamelCase__,					UpperCamelCase__,					UpperCamelCase__,					args.Iterations,					args.Size,					)

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


if __name__ == "__main__":
 UpperCAmelCase_			:  Any										=   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 collections import OrderedDict
from typing import Mapping

from packaging import version

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


UpperCAmelCase_			:  int										=   logging.get_logger(__name__)

UpperCAmelCase_			:  List[Any]										=   {
    'facebook/deit-base-distilled-patch16-224': (
        'https://huggingface.co/facebook/deit-base-patch16-224/resolve/main/config.json'
    ),
    # See all DeiT models at https://huggingface.co/models?filter=deit
}

class     _lowerCamelCase       (     snake_case_					):




 '''simple docstring'''
 __lowercase					:		Union[str, Any]     				=    '''deit'''


 def __init__(   self   ,   __lowercase=768   ,   __lowercase=12   ,   __lowercase=12   ,   __lowercase=3_072   ,   __lowercase="gelu"   ,   __lowercase=0.0   ,   __lowercase=0.0   ,   __lowercase=0.0_2   ,   __lowercase=1E-12   ,   __lowercase=224   ,   __lowercase=16   ,   __lowercase=3   ,   __lowercase=True   ,   __lowercase=16   ,   **__lowercase   ,   ):

  """simple docstring"""







  super().__init__(**__lowercase    )

  __A	:		Union[str, Any]	  =      hidden_size
  __A	:		int	  =      num_hidden_layers
  __A	:		str	  =      num_attention_heads
  __A	:		Optional[int]	  =      intermediate_size
  __A	:		List[str]	  =      hidden_act
  __A	:		str	  =      hidden_dropout_prob
  __A	:		str	  =      attention_probs_dropout_prob
  __A	:		int	  =      initializer_range
  __A	:		Tuple	  =      layer_norm_eps
  __A	:		List[Any]	  =      image_size
  __A	:		Dict	  =      patch_size
  __A	:		Optional[Any]	  =      num_channels
  __A	:		List[Any]	  =      qkv_bias
  __A	:		str	  =      encoder_stride


class     _lowerCamelCase       (     snake_case_					):




 '''simple docstring'''
 __lowercase					:		Optional[int]     				=    version.parse('''1.11'''					)


 @property
 def 			snake_case__ (   self    ):

  """simple docstring"""







  return OrderedDict(
      [
          ('pixel_values', {0: 'batch', 1: 'num_channels', 2: 'height', 3: 'width'}),
      ]    )







 @property
 def 			snake_case__ (   self    ):

  """simple docstring"""







  return 1E-4






