-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmatrix.go
More file actions
29 lines (25 loc) · 739 Bytes
/
Copy pathmatrix.go
File metadata and controls
29 lines (25 loc) · 739 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package ap
// Matrix representation of an assignment. If u is assigned to v, then M[u][v]
// is true. Each row and each column has exactly one true element.
type Matrix [][]bool
// Cycles converts a permutation matrix to a cyclic representation.
func (m Matrix) Cycles() Cycles {
return m.Permutation().Cycles()
}
// Inverse inverts a permutation matrix, changing its direction.
func (m Matrix) Inverse() Matrix {
return m.Permutation().Inverse().Matrix()
}
// Permutation converts a matrix assignment representation into a permutation.
func (m Matrix) Permutation() Permutation {
p := make(Permutation, len(m))
for u, mu := range m {
for v, assigned := range mu {
if assigned {
p[u] = v
break
}
}
}
return p
}