def _get_cost (route, solution, dists):
    """
    This method is used to calculate the total distance
    associated to a route, once the sequence of its nodes
    has been changed using the 2-OPT algorithm.

    :param route: The interested route.
    :param solution: The nodesin the order in which they are visited.
    :param dists: The matrix of distances between nodes.
    :return: The total distance.
    """
    cnode, cost = route.source.id, 0
    for node in solution:
        cost += dists[cnode, node.id]
        cnode = node.id
    cost += dists[cnode, route.depot.id]
    return cost