public class HungarianAlgorithm
extends java.lang.Object
Constructor and Description |
---|
HungarianAlgorithm(double[][] costMatrix)
Construct an instance of the algorithm.
|
Modifier and Type | Method and Description |
---|---|
protected void |
computeInitialFeasibleSolution()
Compute an initial feasible solution by assigning zero labels to the
workers and by assigning to each job a label equal to the minimum cost
among its incident edges.
|
int[] |
execute()
Execute the algorithm.
|
protected void |
executePhase()
Execute a single phase of the algorithm.
|
protected int |
fetchUnmatchedWorker() |
protected void |
greedyMatch()
Find a valid matching by greedily selecting among zero-cost matchings.
|
protected void |
initializePhase(int w)
Initialize the next phase of the algorithm by clearing the committed
workers and jobs sets and by initializing the slack arrays to the values
corresponding to the specified root worker.
|
protected void |
match(int w,
int j)
Helper method to record a matching between worker w and job j.
|
protected void |
reduce()
Reduce the cost matrix by subtracting the smallest element of each row from
all elements of the row as well as the smallest element of each column from
all elements of the column.
|
protected void |
updateLabeling(double slack)
Update labels with the specified slack by adding the slack value for
committed workers and by subtracting the slack value for committed jobs.
|
public HungarianAlgorithm(double[][] costMatrix)
costMatrix
- the cost matrix, where matrix[i][j] holds the cost of assigning
worker i to job j, for all i, j. The cost matrix must not be
irregular in the sense that all rows must be the same length.protected void computeInitialFeasibleSolution()
public int[] execute()
protected void executePhase()
The runtime of a single phase of the algorithm is O(n^2), where n is the dimension of the internal square cost matrix, since each edge is visited at most once and since increasing the labeling is accomplished in time O(n) by maintaining the minimum slack values among non-committed jobs. When a phase completes, the matching will have increased in size.
protected int fetchUnmatchedWorker()
dim
if none.protected void greedyMatch()
protected void initializePhase(int w)
w
- the worker at which to root the next phase.protected void match(int w, int j)
protected void reduce()
protected void updateLabeling(double slack)