|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectalgorithm.matching.HungarianAlgorithm
public class HungarianAlgorithm
An implementation of the classic hungarian algorithm for the assignment problem. Copyright 2007 Gary Baker (GPL v3)
| Field Summary | |
|---|---|
private static org.apache.log4j.Logger |
logger
logger instance |
| Constructor Summary | |
|---|---|
HungarianAlgorithm()
|
|
| Method Summary | |
|---|---|
private boolean |
allAreCovered(int[] coveredCols)
Test if all columns are covered. |
MatchList |
computeAssignments(double[][] input,
Config config)
Compute the assignments for the given cost matrix. |
private void |
coverColumnsOfStarredZeroes(int[] starsByCol,
int[] coveredCols)
just marke the columns covered for any coluimn containing a starred zero |
private void |
incrementSetOfStarredZeroes(int[] unpairedZeroPrime,
int[] starsByRow,
int[] starsByCol,
int[] primesByRow)
|
private void |
initStars(float[][] costMatrix,
int[] starsByRow,
int[] starsByCol)
init starred zeroes for each column find the first zero if there is no other starred zero in that row then star the zero, cover the column and row and go onto the next column |
private void |
makeMoreZeroes(float[][] matrix,
int[] coveredRows,
int[] coveredCols)
|
private static double[][] |
prepareMatrix(double[][] weight_origin,
Config config)
prepare the stored weight function so that it can be used by hungarian algorithm. |
private int[] |
primeSomeUncoveredZero(float[][] matrix,
int[] primesByRow,
int[] coveredRows,
int[] coveredCols)
finds some uncovered zero and primes it |
private void |
reduceMatrix(float[][] matrix)
the first step of the hungarian algorithm is to find the smallest element in each row and subtract it's values from all elements in that row |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
private static org.apache.log4j.Logger logger
| Constructor Detail |
|---|
public HungarianAlgorithm()
| Method Detail |
|---|
public MatchList computeAssignments(double[][] input,
Config config)
throws InvalidWeightFunctionGivenException
MatchingAlgorithm
computeAssignments in interface MatchingAlgorithminput - the cost matrixconfig - the configuration parameters for this algorithm
InvalidWeightFunctionGivenException
private static double[][] prepareMatrix(double[][] weight_origin,
Config config)
throws InvalidWeightFunctionGivenException
InvalidWeightFunctionGivenExceptionprivate boolean allAreCovered(int[] coveredCols)
coveredCols - the covered columns
private void reduceMatrix(float[][] matrix)
private void initStars(float[][] costMatrix,
int[] starsByRow,
int[] starsByCol)
costMatrix - starsByRow - starsByCol -
private void coverColumnsOfStarredZeroes(int[] starsByCol,
int[] coveredCols)
starsByCol - coveredCols -
private int[] primeSomeUncoveredZero(float[][] matrix,
int[] primesByRow,
int[] coveredRows,
int[] coveredCols)
matrix - the cost matrixprimesByRow - the primed rowscoveredRows - the primes columnscoveredCols - all covered columns
private void incrementSetOfStarredZeroes(int[] unpairedZeroPrime,
int[] starsByRow,
int[] starsByCol,
int[] primesByRow)
unpairedZeroPrime - starsByRow - starsByCol - primesByRow -
private void makeMoreZeroes(float[][] matrix,
int[] coveredRows,
int[] coveredCols)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||