public void SparseMatrixConstructsProperlyWhenConstructedFromIntegralSparseMatrix() { var sparseInt = new SparseMatrixInt( new List <int> { 5, 8, 3, 6 }, new List <int> { 0, 0, 2, 3, 4 }, new List <int> { 0, 1, 2, 1 }, 4); var sparseDouble = new SparseMatrixDouble(sparseInt); Assert.Equal(new List <double> { 5, 8, 3, 6 }, sparseDouble.A); Assert.Equal(new List <int> { 0, 0, 2, 3, 4 }, sparseDouble.IA); Assert.Equal(new List <int> { 0, 1, 2, 1 }, sparseDouble.CA); Assert.Equal(4, sparseDouble.NumRows); Assert.Equal(4, sparseDouble.NumColumns); Assert.Equal(8, sparseDouble.MaxValue); }
public void SolveSparseGivesExpectedResultWhenMinimizing( int[,] dense, int[] expectedColumnAssignment, int[] expectedRowAssignment) { var cost = new SparseMatrixInt(dense); var solver = new PseudoflowSolver(); var solution = solver.Solve(cost); Assert.Equal(expectedColumnAssignment, solution.ColumnAssignment); Assert.Equal(expectedRowAssignment, solution.RowAssignment); }
public void TransposeCalculatesTransposeAndIsAnInvolution( List <int> A, List <int> IA, List <int> CA, int numColumns, List <int> At, List <int> IAt, List <int> CAt) { var matrix = new SparseMatrixInt(A, IA, CA, numColumns); var transpose = matrix.Transpose(); var doubleTranspose = transpose.Transpose(); Assert.Equal(At, transpose.A); Assert.Equal(IAt, transpose.IA); Assert.Equal(CAt, transpose.CA); Assert.Equal(A, doubleTranspose.A); Assert.Equal(IA, doubleTranspose.IA); Assert.Equal(CA, doubleTranspose.CA); }
public void SparseMatrixConstructsProperlyForDenseIntegralInput() { int[,] dense = { { 0, 0, 0, 0 }, { 5, 8, 0, 0 }, { 0, 0, 3, 0 }, { 0, 6, 0, 0 } }; var sparse = new SparseMatrixInt(dense, 0); Assert.Equal(new List <int> { 5, 8, 3, 6 }, sparse.A); Assert.Equal(new List <int> { 0, 0, 2, 3, 4 }, sparse.IA); Assert.Equal(new List <int> { 0, 1, 2, 1 }, sparse.CA); Assert.Equal(4, sparse.NumRows); Assert.Equal(4, sparse.NumColumns); Assert.Equal(8, sparse.MaxValue); }