public class MatchingBipartite_HungarianAlgorithm extends MatchingBipartite
This implementation is done according to: Grosche, Ziegler, Ziegler and Zeidler, Teubner-Taschenbuch der Mathematik, Teil II, pp. 219 ff 7th edition, B.G. Teubner Verlagsgesellschaft Leipzig, 1995 It assumes a squared score matrix and tries to find the matching that optimizes the score. The scores should all be positive and per default the algorithm minimizes the overall score. Anyway, the operator can be configured so as to interprete the scores inversely, i.e. searching for the matching that maximizes the sum of scores.
Note, that this implementation is not well-suited for large matrices. The implementation is greedy, so do not expect too much in case of a large number of elements to be matched...
Modifier and Type | Class and Description |
---|---|
static class |
MatchingBipartite_HungarianAlgorithm.ScoreInterpretation
Matrix scores interpretation.
|
Modifier and Type | Field and Description |
---|---|
protected byte[][] |
chainMarkers
Helper matrix for exchange chain extraction: 0 = unselected, 1 = selected.
|
protected boolean[] |
colMarkers
Array containing column marks.
|
protected byte[][] |
elementMarkers
Matrix for elements markers: 0 = no mark, 1 = starred, 2 = primed
|
protected boolean |
junitTest
Internal flag for interrupting recursive calls in unit testing.
|
protected MatchingBipartite_HungarianAlgorithm.ScoreInterpretation |
matrixScore
Score interpretation.
|
protected int |
matrixSize
Number of rows and columns, respectively.
|
protected boolean[] |
rowMarkers
Array containing row marks.
|
protected double |
stageThreeMin
Helper to make matrix minimum in stage three externally accessible.
|
protected double[][] |
workingMatrix
Local copy of matrix modified during calculations.
|
resultMatrix, scoreMatrix
Modifier | Constructor and Description |
---|---|
protected |
MatchingBipartite_HungarianAlgorithm()
Default constructor.
|
|
MatchingBipartite_HungarianAlgorithm(double[][] smatrix,
MatchingBipartite_HungarianAlgorithm.ScoreInterpretation o)
Default constructor with parameters.
|
Modifier and Type | Method and Description |
---|---|
protected void |
calcMatching_mainTest()
Checks whether a valid solution has been found.
|
protected void |
calcMatching_stageOne()
Implements stage one: searching for new candidate matches.
|
protected void |
calcMatching_stageThree()
Implements stage three: decrease scores to generate new zero entries.
|
protected void |
calcMatching_stageTwo(int r,
int c)
Implements stage two: extracting exchange chain.
|
protected void |
calcMatching()
Function calculating actual matching, to be implemented by subclasses.
|
protected void |
init()
Initializes the operator, i.e. allocates memory.
|
protected void |
prepareMatching()
Preprocess the matrix.
|
void |
validateCustom() |
getMatching, operate
readResolve
addOperatorExecutionProgressEventListener, addParameter, addParameter, addParameterUnconditioned, fieldContained, fireOperatorExecutionProgressEvent, getALDPortHashAccessKey, getConstructionMode, getDocumentation, getHidingMode, getInactiveParameterNames, getInInoutNames, getInInoutNames, getInNames, getInOutNames, getMissingRequiredInputs, getName, getNumParameters, getOutInoutNames, getOutNames, getParameter, getParameterDescriptor, getParameterDescriptorUnconditioned, getParameterNames, getParameterUnconditioned, getSupplementalNames, getVerbose, getVersion, handleOperatorExecutionProgressEvent, hasInOutParameters, hasParameter, isAnnotatedParameter, isConfigured, print, print, print, printInterface, printInterface, readHistory, reinitializeParameterDescriptors, removeOperatorExecutionProgressEventListener, removeParameter, runOp, runOp, runOp, setConstructionMode, setConstructionMode, setConstructionMode, setHidingMode, setName, setParameter, setParameterUnconditioned, setVerbose, toStringVerbose, unconfiguredItems, validate, validateGeneric, writeHistory, writeHistory, writeHistory
protected boolean[] rowMarkers
protected boolean[] colMarkers
protected byte[][] elementMarkers
protected double[][] workingMatrix
protected int matrixSize
protected byte[][] chainMarkers
protected boolean junitTest
protected double stageThreeMin
@Parameter(label="scoreInterpretation", required=true, type=INPUT, description="How to interpret the scores.") protected MatchingBipartite_HungarianAlgorithm.ScoreInterpretation matrixScore
protected MatchingBipartite_HungarianAlgorithm() throws de.unihalle.informatik.Alida.exceptions.ALDOperatorException
de.unihalle.informatik.Alida.exceptions.ALDOperatorException
public MatchingBipartite_HungarianAlgorithm(double[][] smatrix, MatchingBipartite_HungarianAlgorithm.ScoreInterpretation o) throws de.unihalle.informatik.Alida.exceptions.ALDOperatorException
The rows of the matrix should refer to one set of elements, and the cols to the second one. Matrix elements then give the matching scores for all pairs of possible matchings. Note that for this technique the score matrix needs to be square, otherwise an exception is thrown. Also it is assumed that all scores are larger than or equal to zero.
smatrix
- Square matrix with pairwise scores.de.unihalle.informatik.Alida.exceptions.ALDOperatorException
public void validateCustom() throws de.unihalle.informatik.Alida.exceptions.ALDOperatorException
validateCustom
in class de.unihalle.informatik.Alida.operator.ALDOperator
de.unihalle.informatik.Alida.exceptions.ALDOperatorException
protected void calcMatching()
MatchingBipartite
calcMatching
in class MatchingBipartite
protected void init()
protected void prepareMatching()
The method first inverts all entries if large scores are better. Subsequently zeros are starred in the matrix, preferably so that each row and each column contains exactly one star. If this is possible a solution has already been found.
protected void calcMatching_mainTest()
protected void calcMatching_stageOne()
protected void calcMatching_stageTwo(int r, int c)
protected void calcMatching_stageThree()
Copyright © 2010–2020 Martin Luther University Halle-Wittenberg, Institute of Computer Science, Pattern Recognition and Bioinformatics. All rights reserved.