Questions tagged [hungarian-algorithm]

The Hungarian algorithm is a combinatorial optimization algorithm that solves the assignment problem, that of finding a maximum weight matching in a bipartite graph, in polynomial time.

A description of the algorithm can be found in this Wikipedia article.

103 questions
33
votes
8 answers

Hungarian Algorithm: finding minimum number of lines to cover zeroes?

I am trying to implement the Hungarian Algorithm but I am stuck on the step 5. Basically, given a n X n matrix of numbers, how can I find minimum number of vertical+horizontal lines such that the zeroes in the matrix are covered? Before someone…
pathikrit
  • 32,469
  • 37
  • 142
  • 221
14
votes
3 answers

Hungarian Algorithm: How to cover 0 elements with minimum lines?

I am trying to implement the Hungarian algorithm in Java. I have an NxN cost matrix. I am following this guide step by step. So I have the costMatrix[N][N] and 2 arrays to track covered rows and covered cols - rowCover[N], rowColumn[N] (1 means…
Ayrton Senna
  • 3,735
  • 5
  • 34
  • 52
10
votes
1 answer

How to solve an assignment problem (like Hungarian/linear_sum_assignment) with an edge case in PySpark UDF

I have an assignment problem, and I wanted to ask the SO community the best way to go about implementing this for my spark dataframe (utilizing spark 3.1+). I will first describe the problem and then move to implementation. Here is the problem: I…
10
votes
3 answers

Hungarian algorithm: multiple jobs per worker

Is there an extension of the Hungarian algorithm that caters for the assignment of multiple jobs per worker? In its simplest form, the algorithm assigns a single job to a single worker. My application is a profit maximization problem, with 3…
8
votes
1 answer

Hungarian Algorithm - Wikipedia method doesn't work for this example

I'm trying to implement a Hungarian Algorithm in C. I have the matrix: 35 0 0 0 0 30 0 5 55 5 0 10 0 45 30 45 And I'm up to the stage where I have to find the minimum amount of lines to cover all zeroes (making as many assignments as…
TerryA
  • 58,805
  • 11
  • 114
  • 143
8
votes
4 answers

Minimizing the distance of pairing points

My problem is as follows: Given a number of 2n points, I can calculate the distance between all points and get a symmetrical matrix. Can you create n pairs of points, so that the sum of the distance of all pairs is minimal? EDIT: Every point has…
the
  • 361
  • 3
  • 9
8
votes
2 answers

Can I use the Hungarian algorithm to find max cost?

The Hungarian algorithm solves the assignment problem in polynomial time. Given workers and tasks, and an n×n matrix containing the cost of assigning each worker to a task, it can find the cost minimizing assignment. I want to find the choice for…
codersofthedark
  • 9,183
  • 8
  • 45
  • 70
8
votes
1 answer

Hungarian algorithm: I'm having trouble with assigning as many jobs to workers as possible

I have created an implementation of the Hungarian algorithm in C++. This implementation works very well for many cases. However there are some cases that my algorithm does not work at all because I believe(and it's true) that my implementation of…
ksm001
  • 3,772
  • 10
  • 36
  • 57
7
votes
2 answers

Hungarian Algorithm for non square matrix

I'm trying to implement the Hungarian algorithm. Everything is fine except for when the matrix isn't square. All the methods I've searched are saying that I should make it square by adding dummy rows/columns, and filling the dummy row/column with…
Sarah K
  • 71
  • 1
  • 2
7
votes
1 answer

Hungarian algorithm with multiple assignments

Let's say we're given N jobs and K workers to do those jobs. But for some jobs we need 2 employees, while for some we need just one. Also the employees can't do all jobs. For example worker 1 can do jobs 1,2 and 5, while not jobs 3 and 4. Also if we…
Stefan4024
  • 694
  • 1
  • 10
  • 21
7
votes
4 answers

Job assignment with NO cost, would Hungarian method work?

So I have a job assignment problem that doesn't have the traditional cost the Hungarian method requires. For example: I have 3 workers - A, B and C I have 5 jobs - 1, 2, 3, 4 and 5 Each worker has a list of jobs he can perform, like so: worker A…
sap
  • 1,188
  • 1
  • 14
  • 25
5
votes
0 answers

"Snapping" the Results of t-sne to a Regular Grid - Scalability Issues

I'm trying to use t-sne to arrange images based on their visual similarity, similar to this cool example for emojies (source): but the output of t-sne is just a "point cloud", while my goal is to display the images in a regular, near-square, dense…
5
votes
1 answer

Given 2d matrix find minimum sum of elements such that element is chosen one from each row and column?

Find minimum sum of elements of n*n 2D matrix such that I have to choose one and only one element from each row and column ? Eg 4 12 6 6 If I choose 4 from row 1 I cannot choose 12 from row 1 also from column 1 , I can only choose 6 from row…
user3529205
  • 175
  • 3
  • 12
5
votes
1 answer

Hungarian algorithm with unequal number of workers and tasks

I have a problem bugging me for a while now. We have "workers" w_0, w_1 ... w_n, and tasks t_0, t_1, ... t_m, and durations D_ij such that w_i can complete t_j in that number of hours. Each worker also has a maximum m_0,m_1... m_n number of hours…
Zoltan Ersek
  • 755
  • 9
  • 28
5
votes
0 answers

Matching students to courses with course limit (Hungarian, Max Flow, Min-Cost-Flow, ...)

I am currently writing a program which maps students to courses. Currently, I am using a SAT-Solver, but I am trying to implement a polynomial time / non greedy algorithm which solves the following sub-problem: There are students (50-150) There are…
1
2 3 4 5 6 7