public static void triang_test( ) //****************************************************************************80 // // Purpose: // // TRIANG_TEST tests TRIANG. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 05 January 2007 // // Author: // // John Burkardt // { const int N = 10; int[] a = { 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1 }; int[] p = new int[N]; Console.WriteLine(""); Console.WriteLine("TRIANG_TEST"); Console.WriteLine(" TRIANG relabels elements for a partial ordering,"); typeMethods.i4mat_print(N, N, a, " The input matrix:"); Triang.triang(N, a, ref p); Permutation.perm0_print(N, p, " The new ordering:"); typeMethods.i4mat_2perm0(N, N, a, p, p); typeMethods.i4mat_print(N, N, a, " The reordered matrix:"); }
public static void moebius_matrix(int n, int[] a, ref int[] mu) //****************************************************************************80 // // Purpose: // // MOEBIUS_MATRIX finds the Moebius matrix from a covering relation. // // Discussion: // // This routine can be called with A and MU being the same matrix. // The routine will correctly compute the Moebius matrix, which // will, in this case, overwrite the input matrix. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 29 May 2003 // // Author: // // Original FORTRAN77 version by Albert Nijenhuis, Herbert Wilf. // C++ version by John Burkardt. // // Reference: // // Albert Nijenhuis, Herbert Wilf, // Combinatorial Algorithms for Computers and Calculators, // Second Edition, // Academic Press, 1978, // ISBN: 0-12-519260-6, // LC: QA164.N54. // // Parameters: // // Input, int N, number of elements in the partially ordered set. // // Input, int A[N*N]. A(I,J) = 1 if I is covered by J, // 0 otherwise. // // Output, int MU[N*N], the Moebius matrix as computed by the routine. // { int i; int j; int[] p1 = new int[n]; // // Compute a reordering of the elements of the partially ordered matrix. // Triang.triang(n, a, ref p1); // // Copy the matrix. // for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { mu[i + j * n] = a[i + j * n]; } } // // Apply the reordering to MU. // typeMethods.i4mat_2perm0(n, n, mu, p1, p1); // // Negate the (strict) upper triangular elements of MU. // for (i = 0; i < n - 1; i++) { for (j = i + 1; j < n; j++) { mu[i + j * n] = -mu[i + j * n]; } } // // Compute the inverse of MU. // typeMethods.i4mat_u1_inverse(n, mu, ref mu); // // All nonzero elements are reset to 1. // for (i = 0; i < n; i++) { for (j = i; j < n; j++) { if (mu[i + j * n] != 0) { mu[i + j * n] = 1; } } } // // Invert the matrix again. // typeMethods.i4mat_u1_inverse(n, mu, ref mu); // // Compute the inverse permutation. // int[] p2 = Permutation.perm0_inverse(n, p1); // // Unpermute the rows and columns of MU. // typeMethods.i4mat_2perm0(n, n, mu, p2, p2); }