Skip to content

Commit ec1a95c

Browse files
committed
Add public methods to generate StronglyConnectedComponents and DulmageMendelsohn from SymbolicColumnStorage.
1 parent 3f1a625 commit ec1a95c

File tree

2 files changed

+32
-11
lines changed

2 files changed

+32
-11
lines changed

CSparse/Ordering/DulmageMendelsohn.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,23 @@ public int Singletons
105105
/// <returns>Dulmage-Mendelsohn analysis</returns>
106106
public static DulmageMendelsohn Generate<T>(CompressedColumnStorage<T> matrix, int seed = 0)
107107
where T : struct, IEquatable<T>, IFormattable
108+
{
109+
return Generate(SymbolicColumnStorage.Create(matrix), seed);
110+
}
111+
112+
/// <summary>
113+
/// Compute coarse and then fine Dulmage-Mendelsohn decomposition. seed
114+
/// optionally selects a randomized algorithm.
115+
/// </summary>
116+
/// <param name="A">The matrix represented by <see cref="SymbolicColumnStorage"/>.</param>
117+
/// <param name="seed">0: natural, -1: reverse, random order otherwise</param>
118+
/// <returns>Dulmage-Mendelsohn analysis</returns>
119+
public static DulmageMendelsohn Generate(SymbolicColumnStorage A, int seed = 0)
108120
{
109121
int i, j, k, cnz, nc, nb1, nb2;
110122
int[] Cp, ps, rs;
111123
bool ok;
112124

113-
// We are not interested in the actual matrix values.
114-
var A = SymbolicColumnStorage.Create(matrix);
115-
116125
// Maximum matching
117126
int m = A.RowCount;
118127
int n = A.ColumnCount;
@@ -147,7 +156,7 @@ public static DulmageMendelsohn Generate<T>(CompressedColumnStorage<T> matrix, i
147156
// Fine decomposition
148157
int[] pinv = Permutation.Invert(p); // pinv=p'
149158

150-
var C = SymbolicColumnStorage.Create(matrix);
159+
var C = A.Clone();
151160
A.Permute(pinv, q, C); // C=A(p,q) (it will hold A(R2,C2))
152161

153162
Cp = C.ColumnPointers;

CSparse/Ordering/StronglyConnectedComponents.cs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,31 @@ private StronglyConnectedComponents(int m, int n)
4848
public static StronglyConnectedComponents Generate<T>(CompressedColumnStorage<T> matrix)
4949
where T : struct, IEquatable<T>, IFormattable
5050
{
51-
return Generate(SymbolicColumnStorage.Create(matrix, false), matrix.ColumnCount);
51+
return Generate(SymbolicColumnStorage.Create(matrix, false));
5252
}
53-
53+
5454
/// <summary>
55-
/// Find strongly connected components of A.
55+
/// Compute strongly connected components of A.
5656
/// </summary>
57-
/// <param name="A"></param>
58-
/// <param name="n"></param>
59-
/// <returns></returns>
60-
internal static StronglyConnectedComponents Generate(SymbolicColumnStorage A, int n)
57+
/// <param name="A">The matrix represented by <see cref="SymbolicColumnStorage"/>.</param>
58+
/// <returns>Strongly connected components</returns>
59+
public static StronglyConnectedComponents Generate(SymbolicColumnStorage A)
60+
{
61+
return Generate(A, A.ColumnCount);
62+
}
63+
64+
/// <summary>
65+
/// Compute strongly connected components of A.
66+
/// </summary>
67+
/// <param name="A">The matrix represented by <see cref="SymbolicColumnStorage"/>.</param>
68+
/// <param name="size">The size of the matrix.</param>
69+
/// <returns>Strongly connected components</returns>
70+
public static StronglyConnectedComponents Generate(SymbolicColumnStorage A, int size)
6171
{
6272
// matrix A temporarily modified, then restored
6373

74+
int n = size;
75+
6476
int i, k, b, nb = 0, top;
6577
int[] xi, p, r, Ap, ATp;
6678

0 commit comments

Comments
 (0)