





'''simple docstring'''







import argparse
import copy





def 				lowerCamelCase_					(     SCREAMING_SNAKE_CASE__					:	List[Any]      )       ->		List[str]:
						UpperCAmelCase_	:					List[Any]     =     {}

						with open(SCREAMING_SNAKE_CASE__      ) as f:
												for line in f:
																		if line.split()[0] not in dict_of_neighbours:
																								UpperCAmelCase_	:					List[str]     =     []
																								_list.append([line.split()[1], line.split()[2]]      )
																								UpperCAmelCase_	:					str     =     _list
																		else:
																								dict_of_neighbours[line.split()[0]].append(
																								    [line.split()[1], line.split()[2]]      )
																		if line.split()[1] not in dict_of_neighbours:
																								UpperCAmelCase_	:					Optional[Any]     =     []
																								_list.append([line.split()[0], line.split()[2]]      )
																								UpperCAmelCase_	:					str     =     _list
																		else:
																								dict_of_neighbours[line.split()[1]].append(
																								    [line.split()[0], line.split()[2]]      )

						return dict_of_neighbours





def 				lowerCamelCase_					(     SCREAMING_SNAKE_CASE__					:	Any,	SCREAMING_SNAKE_CASE__					:	Optional[Any]      )       ->		Dict:






						with open(SCREAMING_SNAKE_CASE__      ) as f:
												UpperCAmelCase_	:					Tuple     =     f.read(1      )
						UpperCAmelCase_	:					int     =     start_node

						UpperCAmelCase_	:					Dict     =     []

						UpperCAmelCase_	:					Tuple     =     start_node

						UpperCAmelCase_	:					Optional[Any]     =     0
						while visiting not in first_solution:
												UpperCAmelCase_	:					Dict     =     10000
												for k in dict_of_neighbours[visiting]:
																		if int(k[1]      ) < int(SCREAMING_SNAKE_CASE__      ) and k[0] not in first_solution:
																								UpperCAmelCase_	:					Union[str, Any]     =     k[1]
																								UpperCAmelCase_	:					Any     =     k[0]

												first_solution.append(SCREAMING_SNAKE_CASE__      )
												UpperCAmelCase_	:					Dict     =     distance_of_first_solution + int(SCREAMING_SNAKE_CASE__      )
												UpperCAmelCase_	:					Tuple     =     best_node

						first_solution.append(SCREAMING_SNAKE_CASE__      )

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

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





def 				lowerCamelCase_					(     SCREAMING_SNAKE_CASE__					:	List[str],	SCREAMING_SNAKE_CASE__					:	Any      )       ->		Any:
						UpperCAmelCase_	:					Union[str, Any]     =     []

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

																		UpperCAmelCase_	:					Union[str, Any]     =     copy.deepcopy(SCREAMING_SNAKE_CASE__      )
																		UpperCAmelCase_	:					List[str]     =     kn
																		UpperCAmelCase_	:					Dict     =     n

																		UpperCAmelCase_	:					Tuple     =     0

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

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

						UpperCAmelCase_	:					Dict     =     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 				lowerCamelCase_					(     SCREAMING_SNAKE_CASE__					:	Optional[int],	SCREAMING_SNAKE_CASE__					:	Dict,	SCREAMING_SNAKE_CASE__					:	Any,	SCREAMING_SNAKE_CASE__					:	Optional[int],	SCREAMING_SNAKE_CASE__					:	Union[str, Any]      )       ->		Any:
						UpperCAmelCase_	:					Optional[Any]     =     1
						UpperCAmelCase_	:					Any     =     first_solution
						UpperCAmelCase_	:					Dict     =     []
						UpperCAmelCase_	:					str     =     distance_of_first_solution
						UpperCAmelCase_	:					Union[str, Any]     =     solution

						while count <= iters:
												UpperCAmelCase_	:					int     =     find_neighborhood(SCREAMING_SNAKE_CASE__,	SCREAMING_SNAKE_CASE__      )
												UpperCAmelCase_	:					int     =     0
												UpperCAmelCase_	:					List[Any]     =     neighborhood[index_of_best_solution]
												UpperCAmelCase_	:					Dict     =     len(SCREAMING_SNAKE_CASE__      ) - 1

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

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

												UpperCAmelCase_	:					Any     =     count + 1

						return best_solution_ever, best_cost





def 				lowerCamelCase_					(     SCREAMING_SNAKE_CASE__					:	List[str]=None      )       ->		str:
						UpperCAmelCase_	:					str     =     generate_neighbours(args.File      )

						UpperCAmelCase_  ,				UpperCAmelCase_	:					List[Any]     =     generate_first_solution(
						    args.File,	SCREAMING_SNAKE_CASE__      )

						UpperCAmelCase_  ,				UpperCAmelCase_	:					Any     =     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__":
					snake_case_   :				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())












# Copyright 2023 The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import TYPE_CHECKING

# rely on isort to merge the imports
from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available, is_vision_available


snake_case__					:							List[str]													=     {
    'configuration_vivit': ['VIVIT_PRETRAINED_CONFIG_ARCHIVE_MAP', 'VivitConfig'],
}
try:
       if not is_vision_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       snake_case__					:							Tuple													=     ['VivitImageProcessor']


try:
       if not is_torch_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       snake_case__					:							Any													=     [
           'VIVIT_PRETRAINED_MODEL_ARCHIVE_LIST',
           'VivitModel',
           'VivitPreTrainedModel',
           'VivitForVideoClassification',
       ]


if TYPE_CHECKING:
       from .configuration_vivit import VIVIT_PRETRAINED_CONFIG_ARCHIVE_MAP, VivitConfig

       try:
              if not is_vision_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .image_processing_vivit import VivitImageProcessor

       try:
              if not is_torch_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .modeling_vivit import (
                  VIVIT_PRETRAINED_MODEL_ARCHIVE_LIST,
                  VivitForVideoClassification,
                  VivitModel,
                  VivitPreTrainedModel,
              )


else:
       import sys

       snake_case__					:							List[str]													=     _LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)





