deploy/DeepStream/src/Lapjv.cpp
/** Column-reduction and reduction transfer for a dense cost matrix.
 */
Column-reduction and reduction transfer for a dense cost matrix.
Column - reduction and reduction transfer for a dense cost matrix .
int_t _ccrrt_dense(const uint_t n, cost_t *cost[],
                   int_t *free_rows, int_t *x, int_t *y, cost_t *v) {
    int_t   n_free_rows;
    boolean *unique;
    for (uint_t i = 0; i < n; i++) {
        x[i] = -1;
        v[i] = LARGE;
        y[i] = 0;
    }
    for (uint_t i = 0; i < n; i++) {
        for (uint_t j = 0; j < n; j++) {
            const cost_t c = cost[i][j];
            if (c < v[j]) {
                v[j] = c;
                y[j] = i;
            }
            PRINTF("i=%d, j=%d, c[i,j]=%f, v[j]=%f y[j]=%d\n", i, j, c, v[j], y[j]);
        }
    }
    PRINT_COST_ARRAY(v, n);
    PRINT_INDEX_ARRAY(y, n);
    NEW(unique, boolean, n);
    memset(unique, TRUE, n);
    {
        int_t j = n;
        do {
            j--;
            const int_t i = y[j];
            if (x[i] < 0) {
                x[i] = j;
            } else {
                unique[i] = FALSE;
                y[j]      = -1;
            }
        } while (j > 0);
    }
    n_free_rows = 0;
    for (uint_t i = 0; i < n; i++) {
        if (x[i] < 0) {
            free_rows[n_free_rows++] = i;
        } else if (unique[i]) {
            const int_t j   = x[i];
            cost_t      min = LARGE;
            for (uint_t j2  = 0; j2 < n; j2++) {
                if (j2 == (uint_t) j) {
                    continue;
                }
                const cost_t c = cost[i][j2] - v[j2];
                if (c < min) {
                    min = c;
                }
            }
            PRINTF("v[%d] = %f - %f\n", j, v[j], min);
            v[j] -= min;
        }
    }
    FREE(unique);
    return n_free_rows;
}
int_t _ccrrt_dense ( const uint_t n , cost_t * cost [ ] , int_t * free_rows , int_t * x , int_t * y , cost_t * v ) { int_t n_free_rows ; boolean * unique ; for ( uint_t i = 0 ; i < n ; i ++ ) { x [ i ] = -1 ; v [ i ] = LARGE ; y [ i ] = 0 ; } for ( uint_t i = 0 ; i < n ; i ++ ) { for ( uint_t j = 0 ; j < n ; j ++ ) { const cost_t c = cost [ i ] [ j ] ; if ( c < v [ j ] ) { v [ j ] = c ; y [ j ] = i ; } PRINTF ( " \n " , i , j , c , v [ j ] , y [ j ] ) ; } } PRINT_COST_ARRAY ( v , n ) ; PRINT_INDEX_ARRAY ( y , n ) ; NEW ( unique , boolean , n ) ; memset ( unique , TRUE , n ) ; { int_t j = n ; do { j -- ; const int_t i = y [ j ] ; if ( x [ i ] < 0 ) { x [ i ] = j ; } else { unique [ i ] = FALSE ; y [ j ] = -1 ; } } while ( j > 0 ) ; } n_free_rows = 0 ; for ( uint_t i = 0 ; i < n ; i ++ ) { if ( x [ i ] < 0 ) { free_rows [ n_free_rows ++ ] = i ; } else if ( unique [ i ] ) { const int_t j = x [ i ] ; cost_t min = LARGE ; for ( uint_t j2 = 0 ; j2 < n ; j2 ++ ) { if ( j2 == ( uint_t ) j ) { continue ; } const cost_t c = cost [ i ] [ j2 ] - v [ j2 ] ; if ( c < min ) { min = c ; } } PRINTF ( " \n " , j , v [ j ] , min ) ; v [ j ] -= min ; } } FREE ( unique ) ; return n_free_rows ; }
Column-reduction and reduction transfer for a dense cost matrix.
Column - reduction and reduction transfer for a dense cost matrix .