def construct_comp_matrix(vec: np.ndarray, sorted_idx: np.ndarray) -> np.ndarray:
    """
    const_comp_mat construct the comparison matrix from a row-vector vec.

    Parameters
    ----------
    vec : np.ndarray
        The vector of scores for the population on a single objective
    sorted_idx : np.ndarray
        The indices which would sort `vec`

    Returns
    -------
    np.ndarray
        The comparison matrix indicating whether each member in the population dominates the other member for the
        objective in `vec`
    """
    n = vec.shape[0]
    c = np.zeros(shape=(n, n), dtype=np.int32)

    # the elements of the b(0)-th row in C are all set to 1
    c[sorted_idx[0], :] = 1

    for i in range(1, n):
        if vec[sorted_idx[i]] == vec[sorted_idx[i - 1]]:
            # the rows in C corresponding to the same elements in w are identical
            c[sorted_idx[i]] = c[sorted_idx[i - 1]]
        else:
            c[sorted_idx[i], sorted_idx[i:]] = 1

    return c

    const_comp_mat construct the comparison matrix from a row-vector vec.

    Parameters
    ----------
    vec : np.ndarray
        The vector of scores for the population on a single objective
    sorted_idx : np.ndarray
        The indices which would sort `vec`

    Returns
    -------
    np.ndarray
        The comparison matrix indicating whether each member in the population dominates the other member for the
        objective in `vec`
    
pymoo/util/nds/dominance_degree_non_dominated_sort.py