-/**
- * Do the assignment.
- */
-int hungarian_solve(hungarian_problem_t* p, int *assignment, int *final_cost) {
- int i, j, m, n, k, l, s, t, q, unmatched, cost;
- int *col_mate;
- int *row_mate;
- int *parent_row;
- int *unchosen_row;
- int *row_dec;
- int *col_inc;
- int *slack;
- int *slack_row;
-
- cost = 0;
- m = p->num_rows;
- n = p->num_cols;
-
- col_mate = xcalloc(p->num_rows, sizeof(col_mate[0]));
- unchosen_row = xcalloc(p->num_rows, sizeof(unchosen_row[0]));
- row_dec = xcalloc(p->num_rows, sizeof(row_dec[0]));
- slack_row = xcalloc(p->num_rows, sizeof(slack_row[0]));
-
- row_mate = xcalloc(p->num_cols, sizeof(row_mate[0]));
- parent_row = xcalloc(p->num_cols, sizeof(parent_row[0]));
- col_inc = xcalloc(p->num_cols, sizeof(col_inc[0]));
- slack = xcalloc(p->num_cols, sizeof(slack[0]));
-
- memset(assignment, -1, m * sizeof(assignment[0]));
+int hungarian_solve(hungarian_problem_t* p, unsigned *assignment,
+ unsigned *final_cost, unsigned cost_threshold)
+{
+ unsigned res_cost = 0;
+ unsigned num_rows = p->num_rows;
+ unsigned num_cols = p->num_cols;
+ unsigned *cost = p->cost;
+ unsigned *col_mate = XMALLOCNZ(unsigned, num_rows);
+ unsigned *row_mate = XMALLOCNZ(unsigned, num_cols);
+ unsigned *parent_row = XMALLOCNZ(unsigned, num_cols);
+ unsigned *unchosen_row = XMALLOCNZ(unsigned, num_rows);
+ int *row_dec = XMALLOCNZ(int, num_rows);
+ int *col_inc = XMALLOCNZ(int, num_cols);
+ int *slack = XMALLOCNZ(int, num_cols);
+ unsigned *slack_row = XMALLOCNZ(unsigned, num_rows);
+ unsigned r;
+ unsigned c;
+ unsigned t;
+ unsigned unmatched;
+
+ memset(assignment, -1, num_rows * sizeof(assignment[0]));