python_data_scien/algorithmic_thinking2/project3/alg_project3_solution.py
def closest_pair_strip(cluster_list, mid, width):
    """
    Compute the distance between the closest pair of clusters in a list (fast)

    Input: cluster_list is list of clusters SORTED such that horizontal positions of their
    centers are in ascending order
    
    Output: tuple of the form (dist, idx1, idx2) where the centers of the clusters
    cluster_list[idx1] and cluster_list[idx2] have minimum distance dist.       
    """
    s_list = []
    for idx in range(len(cluster_list)):
        if abs(cluster_list[idx].horiz_center()-mid) < width:
            s_list.append(idx)
    s_list.sort(key = lambda idx: cluster_list[idx].vert_center())
    #cluster_list.sort(key = lambda cluster: cluster.vert_center())
    len_k = len(s_list)
    result_tuple = (float('inf'),-1,-1)
    for idx_u in range(0,len_k-2+1):
        for idx_v in range(idx_u+1,min(idx_u+3,len_k-1)+1):
            idx_i = s_list[idx_u]
            idx_j = s_list[idx_v]
            temp_tuple = pair_distance(cluster_list,idx_i,idx_j)
            #cluster_dist = cluster_list[idx_i].distance(cluster_list[idx_j])
            if temp_tuple[0] < result_tuple[0]:
                result_tuple = temp_tuple
    return result_tuple

    Compute the distance between the closest pair of clusters in a list (fast)

    Input: cluster_list is list of clusters SORTED such that horizontal positions of their
    centers are in ascending order
    
    Output: tuple of the form (dist, idx1, idx2) where the centers of the clusters
    cluster_list[idx1] and cluster_list[idx2] have minimum distance dist.       
    
Compute the distance between the closest pair of clusters in a list (fast)
Input: cluster_list is list of clusters SORTED such that horizontal positions of their
centers are in ascending order

tuple of the form (dist, idx1, idx2) where the centers of the clusters
cluster_list[idx1] and cluster_list[idx2] have minimum distance dist.
Compute the distance between the closest pair of clusters in a list ( fast ) Input : cluster_list is list of clusters SORTED such that horizontal positions of their centers are in ascending order tuple of the form ( dist idx1 idx2 ) where the centers of the clusters cluster_list [ idx1 ] and cluster_list [ idx2 ] have minimum distance dist .
def closest_pair_strip(cluster_list, mid, width):
    s_list = []
    for idx in range(len(cluster_list)):
        if abs(cluster_list[idx].horiz_center()-mid) < width:
            s_list.append(idx)
    s_list.sort(key = lambda idx: cluster_list[idx].vert_center())
    len_k = len(s_list)
    result_tuple = (float('inf'),-1,-1)
    for idx_u in range(0,len_k-2+1):
        for idx_v in range(idx_u+1,min(idx_u+3,len_k-1)+1):
            idx_i = s_list[idx_u]
            idx_j = s_list[idx_v]
            temp_tuple = pair_distance(cluster_list,idx_i,idx_j)
            if temp_tuple[0] < result_tuple[0]:
                result_tuple = temp_tuple
    return result_tuple
def closest_pair_strip ( cluster_list , mid , width ) : s_list = [ ] for idx in range ( len ( cluster_list ) ) : if abs ( cluster_list [ idx ] . horiz_center ( ) - mid ) < width : s_list . append ( idx ) s_list . sort ( key = lambda idx : cluster_list [ idx ] . vert_center ( ) ) len_k = len ( s_list ) result_tuple = ( float ( 'inf' ) , - 1 , - 1 ) for idx_u in range ( 0 , len_k - 2 + 1 ) : for idx_v in range ( idx_u + 1 , min ( idx_u + 3 , len_k - 1 ) + 1 ) : idx_i = s_list [ idx_u ] idx_j = s_list [ idx_v ] temp_tuple = pair_distance ( cluster_list , idx_i , idx_j ) if temp_tuple [ 0 ] < result_tuple [ 0 ] : result_tuple = temp_tuple return result_tuple
Compute the distance between the closest pair of clusters in a list (fast)
Input: cluster_list is list of clusters SORTED such that horizontal positions of their
centers are in ascending order
Compute the distance between the closest pair of clusters in a list ( fast ) Input : cluster_list is list of clusters SORTED such that horizontal positions of their centers are in ascending order
"""
    Compute the distance between the closest pair of clusters in a list (fast)

    Input: cluster_list is list of clusters SORTED such that horizontal positions of their
    centers are in ascending order
    
    Output: tuple of the form (dist, idx1, idx2) where the centers of the clusters
    cluster_list[idx1] and cluster_list[idx2] have minimum distance dist.       
    """ #cluster_list.sort(key = lambda cluster: cluster.vert_center())
 #cluster_dist = cluster_list[idx_i].distance(cluster_list[idx_j])

cluster_list
mid
width