1 /********************************************************************
2 ********************************************************************
4 ** libhungarian by Cyrill Stachniss, 2004
6 ** Added and adapted to libFirm by Christian Wuerdig, 2006
8 ** Solving the Minimum Assignment Problem using the
11 ** ** This file may be freely copied and distributed! **
13 ** Parts of the used code was originally provided by the
14 ** "Stanford GraphGase", but I made changes to this code.
15 ** As asked by the copyright node of the "Stanford GraphGase",
16 ** I hereby proclaim that this file are *NOT* part of the
17 ** "Stanford GraphGase" distrubition!
19 ** This file is distributed in the hope that it will be useful,
20 ** but WITHOUT ANY WARRANTY; without even the implied
21 ** warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
24 ********************************************************************
25 ********************************************************************/
32 #define HUNGARIAN_MODE_MINIMIZE_COST 0
33 #define HUNGARIAN_MODE_MAXIMIZE_UTIL 1
35 typedef struct _hungarian_problem_t hungarian_problem_t;
38 * This method initialize the hungarian_problem structure and init
39 * the cost matrix (missing lines or columns are filled with 0).
41 * @param rows Number of rows in the given matrix
42 * @param cols Number of cols in the given matrix
43 * @param width Element width for matrix dumping
44 * @return The problem object.
46 hungarian_problem_t *hungarian_new(int rows, int cols, int width);
49 * Adds an edge from left to right with some costs.
51 void hungarian_add(hungarian_problem_t *p, int left, int right, int cost);
54 * Removes the edge from left to right.
56 void hungarian_remv(hungarian_problem_t *p, int left, int right);
59 * Prepares the cost matrix, dependend on the given mode.
61 * @param p The hungarian object
62 * @param mode HUNGARIAN_MODE_MAXIMIZE_UTIL or HUNGARIAN_MODE_MINIMIZE_COST (default)
64 void hungarian_prepare_cost_matrix(hungarian_problem_t *p, int mode);
67 * Destroys the hungarian object.
69 void hungarian_free(hungarian_problem_t *p);
72 * This method computes the optimal assignment.
73 * @param p The hungarian object
74 * @param assignment The final assignment
75 * @return Negative value if solution is invalid, 0 otherwise
77 int hungarian_solve(hungarian_problem_t *p, int *assignment);
80 * Print the cost matrix.
81 * @param p The hungarian object
83 void hungarian_print_costmatrix(hungarian_problem_t *p);
85 #endif /* _HUNGARIAN_H_ */