def _fast_get_cost (swap, route, solution, current_cost, dists):
    """
    Fastest way to get the cost of a solution after a 2-opt swap.
    NOTE: This works only if the matrix of distances is symmetric.

    :param swap: The ids of positions swapped.
    :param route: The route to optimize.
    :param solution: The nodes in the order in which they are visited.
    :param current_cost: The cost of the current solution.
    :param dists: The matrix of distances.
    :return: The cost after swapping the positions indicated in swap.
    """
    sol = [route.source] + solution + [route.depot]
    i, j = swap
    A, B, C, D = sol[i].id, sol[i + 1].id, sol[j].id, sol[j + 1].id
    return current_cost - dists[A, B] - dists[C, D] + dists[A, C] + dists[B, D]