Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Munkres ¶
type Munkres struct {
// main
C [][]float64 // [nrow][ncol] cost matrix
Cori [][]float64 // [nrow][ncol] original cost matrix
Links []int // [nrow] will contain links/assignments after Run(), where j := o.Links[i] means that i is assigned to j. -1 means no assignment/link
Cost float64 // total cost after Run() and links are established
// auxiliary
M [][]MaskType // [nrow][ncol] mask matrix. If Mij==1, then Cij is a starred zero. If Mij==2, then Cij is a primed zero
// contains filtered or unexported fields
}
Munkres (Hungarian algorithm) method to solve the assignment problem
based on code by Bob Pilgrim from http://csclab.murraystate.edu/bob.pilgrim/445/munkres.html
Note: this method runs in O(n³), in the worst case; therefore is not efficient for large matrix
Example:
$ | Clean Sweep Wash
-------|--------------------
Fry | [2] 3 3
Leela | 3 [2] 3
Bender | 3 3 [2]
minimum cost = 6
Note: cost will be minimised
func (*Munkres) Run ¶
func (o *Munkres) Run()
Run runs the iterative algorithm
Output:
o.Links -- will contain assignments, where len(assignments) == nrow and
j := o.Links[i] means that i is assigned to j
-1 means no assignment/link
o.Cost -- will have the total cost by following links
func (*Munkres) SetCostMatrix ¶
SetCostMatrix sets cost matrix by copying from C to internal o.C
Note: costs must be positive
func (*Munkres) StrCostMatrix ¶
StrCostMatrix returns a representation of cost matrix with masks and covers
Click to show internal directories.
Click to hide internal directories.