path: root/linear-assignment.h
diff options
authorJohannes Schindelin <>2018-08-13 11:33:00 (GMT)
committerJunio C Hamano <>2018-08-13 17:44:50 (GMT)
commit22d87333e5ee8871a9d42a15834ad91168a95928 (patch)
treef5a3502d94a981851b4e35b00bf84826555e7b4b /linear-assignment.h
parent1d89318c48d233d52f1db230cf622935ac3c69fa (diff)
linear-assignment: a function to solve least-cost assignment problems
The problem solved by the code introduced in this commit goes like this: given two sets of items, and a cost matrix which says how much it "costs" to assign any given item of the first set to any given item of the second, assign all items (except when the sets have different size) in the cheapest way. We use the Jonker-Volgenant algorithm to solve the assignment problem to answer questions such as: given two different versions of a topic branch (or iterations of a patch series), what is the best pairing of commits/patches between the different versions? Signed-off-by: Johannes Schindelin <> Signed-off-by: Junio C Hamano <>
Diffstat (limited to 'linear-assignment.h')
1 files changed, 22 insertions, 0 deletions
diff --git a/linear-assignment.h b/linear-assignment.h
new file mode 100644
index 0000000..1dfea76
--- /dev/null
+++ b/linear-assignment.h
@@ -0,0 +1,22 @@
+ * Compute an assignment of columns -> rows (and vice versa) such that every
+ * column is assigned to at most one row (and vice versa) minimizing the
+ * overall cost.
+ *
+ * The parameter `cost` is the cost matrix: the cost to assign column j to row
+ * i is `cost[j + column_count * i].
+ *
+ * The arrays column2row and row2column will be populated with the respective
+ * assignments (-1 for unassigned, which can happen only if column_count !=
+ * row_count).
+ */
+void compute_assignment(int column_count, int row_count, int *cost,
+ int *column2row, int *row2column);
+/* The maximal cost in the cost matrix (to prevent integer overflows). */
+#define COST_MAX (1<<16)