





'''simple docstring'''






import argparse
import copy






def   __A    (				a_    :	Union[str, Any]						):
		lowerCAmelCase  :     int       						= {}

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

		return dict_of_neighbours






def   __A    (				a_    :	Optional[Any]   ,a_    :	Optional[Any]						):

		with open(a_						) as f:
				lowerCAmelCase  :     str       						= f.read(1						)
		lowerCAmelCase  :     Optional[int]       						= start_node

		lowerCAmelCase  :     Tuple       						= []

		lowerCAmelCase  :     List[Any]       						= start_node

		lowerCAmelCase  :     Dict       						= 0
		while visiting not in first_solution:
				lowerCAmelCase  :     str       						= 1_0_0_0_0
				for k in dict_of_neighbours[visiting]:
						if int(k[1]						) < int(a_						) and k[0] not in first_solution:
								lowerCAmelCase  :     Dict       						= k[1]
								lowerCAmelCase  :     Optional[int]       						= k[0]

				first_solution.append(a_						)
				lowerCAmelCase  :     Tuple       						= distance_of_first_solution + int(a_						)
				lowerCAmelCase  :     List[str]       						= best_node

		first_solution.append(a_						)

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

		lowerCAmelCase  :     Any       						= (
		    distance_of_first_solution
		    + int(dict_of_neighbours[first_solution[-2]][position][1]						)
		    - 1_0_0_0_0
		)
		return first_solution, distance_of_first_solution






def   __A    (				a_    :	int   ,a_    :	Optional[Any]						):
		lowerCAmelCase  :     int       						= []

		for n in solution[1:-1]:
				lowerCAmelCase  :     Tuple       						= solution.index(a_						)
				for kn in solution[1:-1]:
						lowerCAmelCase  :     Dict       						= solution.index(a_						)
						if n == kn:
								continue

						lowerCAmelCase  :     Optional[int]       						= copy.deepcopy(a_						)
						lowerCAmelCase  :     List[str]       						= kn
						lowerCAmelCase  :     Optional[Any]       						= n

						lowerCAmelCase  :     Optional[Any]       						= 0

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

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

		lowerCAmelCase  :     List[Any]       						= 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   __A    (				a_    :	Union[str, Any]   ,a_    :	Optional[int]   ,a_    :	Dict   ,a_    :	Any   ,a_    :	List[str]						):
		lowerCAmelCase  :     Tuple       						= 1
		lowerCAmelCase  :     Optional[Any]       						= first_solution
		lowerCAmelCase  :     Union[str, Any]       						= []
		lowerCAmelCase  :     int       						= distance_of_first_solution
		lowerCAmelCase  :     List[str]       						= solution

		while count <= iters:
				lowerCAmelCase  :     Optional[int]       						= find_neighborhood(a_   ,a_						)
				lowerCAmelCase  :     List[Any]       						= 0
				lowerCAmelCase  :     Optional[int]       						= neighborhood[index_of_best_solution]
				lowerCAmelCase  :     int       						= len(a_						) - 1

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

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

				lowerCAmelCase  :     int       						= count + 1

		return best_solution_ever, best_cost






def   __A    (				a_    :	Union[str, Any]=None						):
		lowerCAmelCase  :     List[str]       						= generate_neighbours(args.File						)

		lowerCAmelCase						,		lowerCAmelCase  :     List[Any]       						= generate_first_solution(
		    args.File   ,a_						)

		lowerCAmelCase						,		lowerCAmelCase  :     Dict       						= tabu_search(
		    a_   ,a_   ,a_   ,args.Iterations   ,args.Size   ,)

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


if __name__ == "__main__":
					lowerCAmelCase									=   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 math

import tensorflow as tf
from packaging import version






def   __A    (				a_    :	List[Any]						):
		lowerCAmelCase  :     Any       						= tf.convert_to_tensor(a_						)
		lowerCAmelCase  :     List[Any]       						= 0.5 * (1.0 + tf.math.erf(x / tf.cast(tf.sqrt(2.0						)   ,x.dtype						)						))

		return x * cdf






def   __A    (				a_    :	int						):
		lowerCAmelCase  :     Dict       						= tf.convert_to_tensor(a_						)
		lowerCAmelCase  :     int       						= tf.cast(math.pi   ,x.dtype						)
		lowerCAmelCase  :     Dict       						= tf.cast(0.0_4_4_7_1_5   ,x.dtype						)
		lowerCAmelCase  :     Dict       						= 0.5 * (1.0 + tf.tanh(tf.sqrt(2.0 / pi						) * (x + coeff * tf.pow(a_   ,3						))						))

		return x * cdf






def   __A    (				a_    :	Union[str, Any]						):
		lowerCAmelCase  :     Any       						= tf.convert_to_tensor(a_						)

		return x * tf.tanh(tf.math.softplus(a_						)						)






def   __A    (				a_    :	List[str]						):
		lowerCAmelCase  :     Dict       						= tf.convert_to_tensor(a_						)
		lowerCAmelCase  :     Any       						= tf.cast(0.0_4_4_7_1_5   ,x.dtype						)
		lowerCAmelCase  :     Optional[int]       						= tf.cast(0.7_9_7_8_8_4_5_6_0_8   ,x.dtype						)

		return 0.5 * x * (1.0 + tf.tanh(x * coeffa * (1.0 + coeffa * x * x)						))






def   __A    (				a_    :	Union[str, Any]						):
		lowerCAmelCase  :     Optional[int]       						= tf.convert_to_tensor(a_						)
		lowerCAmelCase  :     List[Any]       						= tf.cast(1.7_0_2   ,x.dtype						)
		return x * tf.math.sigmoid(coeff * x						)






def   __A    (				a_    :	List[Any]						):
		return tf.clip_by_value(_gelu(a_						)   ,-1_0   ,1_0						)






def   __A    (				a_    :	List[Any]   ,a_    :	List[Any]=-1						):
		lowerCAmelCase						,		lowerCAmelCase  :     Optional[int]       						= tf.split(a_   ,2   ,axis=a_						)
		return a * tf.math.sigmoid(a_						)


if version.parse(tf.version.VERSION) >= version.parse("""2.4"""):






					def   __A    (				a_    :	Optional[Any]						):
							return tf.keras.activations.gelu(a_   ,approximate=a_						)

					lowerCAmelCase									=   tf.keras.activations.gelu

					lowerCAmelCase									=   approximate_gelu_wrap
else:
					lowerCAmelCase									=   _gelu
					lowerCAmelCase									=   _gelu_new


lowerCAmelCase									=   {
    """gelu""": gelu,
    """gelu_10""": gelu_aa,
    """gelu_fast""": gelu_fast,
    """gelu_new""": gelu_new,
    """glu""": glu,
    """mish""": mish,
    """quick_gelu""": quick_gelu,
    """relu""": tf.keras.activations.relu,
    """sigmoid""": tf.keras.activations.sigmoid,
    """silu""": tf.keras.activations.swish,
    """swish""": tf.keras.activations.swish,
    """tanh""": tf.keras.activations.tanh,
}






def   __A    (				a_    :	int						):
		if activation_string in ACTaFN:
				return ACTaFN[activation_string]
		else:
				raise KeyError(f'''function {activation_string} not found in ACT2FN mapping {list(ACTaFN.keys()						)}'''						)



