is this function only related to TSP? could it be used for other algorithms? if so, relocate it.