def calculate_mileage(distance_matrix, route):
    """Calculate total mileage travelled using the given route.

    :param distance_matrix: distance matrix, i.e. a matrix M such that M[i,j]
     is a distance between i-th and j-th location. It is assumed that this matrix
     is symmetric.
    :type distance_matrix: numpy.ndarray
    :param route: sequence of locations visited in TSP solution. For instance,
     if the solution is to start in 1, then go to 0, go to 2 and come back to 1,
     this parameter should be [1, 0, 2].
    :type route: sequence of ints
    :returns: mileage of the route, i.e. total distance travelled, in whatever units
     distance_matrix is specified.
    :rtype: number
    """
    mileage = 0
    for i in range(len(route)-1):
        mileage += distance_matrix[route[i], route[i+1]]
    return mileage