deploy/DeepStream/src/Lapjv.cpp
/** Augmenting row reduction for a dense cost matrix.
 */
Augmenting row reduction for a dense cost matrix.
Augmenting row reduction for a dense cost matrix .
int_t _carr_dense(
        const uint_t n, cost_t *cost[],
        const uint_t n_free_rows,
        int_t *free_rows, int_t *x, int_t *y, cost_t *v) {
    uint_t current       = 0;
    int_t  new_free_rows = 0;
    uint_t rr_cnt        = 0;
    PRINT_INDEX_ARRAY(x, n);
    PRINT_INDEX_ARRAY(y, n);
    PRINT_COST_ARRAY(v, n);
    PRINT_INDEX_ARRAY(free_rows, n_free_rows);
    while (current < n_free_rows) {
        int_t   i0;
        int_t   j1, j2;
        cost_t  v1, v2, v1_new;
        boolean v1_lowers;
        rr_cnt++;
        PRINTF("current = %d rr_cnt = %d\n", current, rr_cnt);
        const int_t free_i = free_rows[current++];
        j1 = 0;
        v1 = cost[free_i][0] - v[0];
        j2 = -1;
        v2 = LARGE;
        for (uint_t j = 1; j < n; j++) {
            PRINTF("%d = %f %d = %f\n", j1, v1, j2, v2);
            const cost_t c = cost[free_i][j] - v[j];
            if (c < v2) {
                if (c >= v1) {
                    v2 = c;
                    j2 = j;
                } else {
                    v2 = v1;
                    v1 = c;
                    j2 = j1;
                    j1 = j;
                }
            }
        }
        i0            = y[j1];
        v1_new        = v[j1] - (v2 - v1);
        v1_lowers     = v1_new < v[j1];
        PRINTF("%d %d 1=%d,%f 2=%d,%f v1'=%f(%d,%g) \n", free_i, i0, j1, v1, j2, v2, v1_new, v1_lowers, v[j1] - v1_new);
        if (rr_cnt < current * n) {
            if (v1_lowers) {
                v[j1] = v1_new;
            } else if (i0 >= 0 && j2 >= 0) {
                j1 = j2;
                i0 = y[j2];
            }
            if (i0 >= 0) {
                if (v1_lowers) {
                    free_rows[--current] = i0;
                } else {
                    free_rows[new_free_rows++] = i0;
                }
            }
        } else {
            PRINTF("rr_cnt=%d >= %d (current=%d * n=%d)\n", rr_cnt, current * n, current, n);
            if (i0 >= 0) {
                free_rows[new_free_rows++] = i0;
            }
        }
        x[free_i]     = j1;
        y[j1]         = free_i;
    }
    return new_free_rows;
}
int_t _carr_dense ( const uint_t n , cost_t * cost [ ] , const uint_t n_free_rows , int_t * free_rows , int_t * x , int_t * y , cost_t * v ) { uint_t current = 0 ; int_t new_free_rows = 0 ; uint_t rr_cnt = 0 ; PRINT_INDEX_ARRAY ( x , n ) ; PRINT_INDEX_ARRAY ( y , n ) ; PRINT_COST_ARRAY ( v , n ) ; PRINT_INDEX_ARRAY ( free_rows , n_free_rows ) ; while ( current < n_free_rows ) { int_t i0 ; int_t j1 , j2 ; cost_t v1 , v2 , v1_new ; boolean v1_lowers ; rr_cnt ++ ; PRINTF ( " \n " , current , rr_cnt ) ; const int_t free_i = free_rows [ current ++ ] ; j1 = 0 ; v1 = cost [ free_i ] [ 0 ] - v [ 0 ] ; j2 = -1 ; v2 = LARGE ; for ( uint_t j = 1 ; j < n ; j ++ ) { PRINTF ( " \n " , j1 , v1 , j2 , v2 ) ; const cost_t c = cost [ free_i ] [ j ] - v [ j ] ; if ( c < v2 ) { if ( c >= v1 ) { v2 = c ; j2 = j ; } else { v2 = v1 ; v1 = c ; j2 = j1 ; j1 = j ; } } } i0 = y [ j1 ] ; v1_new = v [ j1 ] - ( v2 - v1 ) ; v1_lowers = v1_new < v [ j1 ] ; PRINTF ( " \n " , free_i , i0 , j1 , v1 , j2 , v2 , v1_new , v1_lowers , v [ j1 ] - v1_new ) ; if ( rr_cnt < current * n ) { if ( v1_lowers ) { v [ j1 ] = v1_new ; } else if ( i0 >= 0 && j2 >= 0 ) { j1 = j2 ; i0 = y [ j2 ] ; } if ( i0 >= 0 ) { if ( v1_lowers ) { free_rows [ -- current ] = i0 ; } else { free_rows [ new_free_rows ++ ] = i0 ; } } } else { PRINTF ( " \n " , rr_cnt , current * n , current , n ) ; if ( i0 >= 0 ) { free_rows [ new_free_rows ++ ] = i0 ; } } x [ free_i ] = j1 ; y [ j1 ] = free_i ; } return new_free_rows ; }
Augmenting row reduction for a dense cost matrix.
Augmenting row reduction for a dense cost matrix .