void test01 ( void ) /******************************************************************************/ /* Purpose: TEST01 tests RCONT. Licensing: This code is distributed under the GNU LGPL license. Modified: 10 November 2010 Author: John Burkardt */ { # define NROW 5 # define NCOL 5 int i; int ifault; int key; int matrix[NROW*NCOL]; int ncolt[NCOL] = { 2, 2, 2, 2, 1 }; int nrowt[NROW] = { 3, 2, 2, 1, 1 }; int nsubt[NCOL]; int test; int test_num = 10; printf ( "\n" ); printf ( "TEST01\n" ); printf ( " RCONT constructs a random matrix with\n" ); printf ( " given row and column sums.\n" ); i4vec_print ( NROW, nrowt, " The rowsum vector:" ); i4vec_print ( NCOL, ncolt, " The columnsum vector: " ); key = 0; for ( test = 1; test <= test_num; test++ ) { rcont ( NROW, NCOL, nrowt, ncolt, nsubt, matrix, &key, &ifault ); if ( ifault != 0 ) { printf ( "\n" ); printf ( " RCONT returned IFAULT = %d\n", ifault ); return; } i4mat_print ( NROW, NCOL, matrix, " The rowcolsum matrix:" ); } return; # undef NROW # undef NCOL }
void test01 ( void ) /******************************************************************************/ /* Purpose: TEST01 tests I4MAT_FLOYD. Licensing: This code is distributed under the GNU LGPL license. Modified: 20 July 2011 Author: John Burkardt */ { # define N 6 int a[N*N] = { 0, -1, -1, -1, -1, -1, 2, 0, -1, -1, -1, 5, 5, 7, 0, -1, 2, -1, -1, 1, 4, 0, -1, 2, -1, -1, -1, 3, 0, 4, -1, 8, -1, -1, 3, 0 }; int huge; int i; int j; int n = N; printf ( "\n" ); printf ( "TEST01\n" ); printf ( " I4MAT_FLOYO uses Floyd's algorithm to find the\n" ); printf ( " shortest distance between all pairs of nodes\n" ); printf ( " in a directed graph, starting from the initial array\n" ); printf ( " of direct node-to-node distances.\n" ); printf ( "\n" ); printf ( " In the initial direct distance array, if\n" ); printf ( " A(I,J) = -1,\n" ); printf ( " this indicates there is NO directed link from\n" ); printf ( " node I to node J. In that case, the value of\n" ); printf ( " of A(I,J) is essentially \"infinity\".\n" ); i4mat_print ( n, n, a, " Initial direct distance array:" ); huge = i4_huge ( ) / 2; for ( j = 0; j < n; j++ ) { for ( i = 0; i < n; i++ ) { if ( a[i+j*n] == - 1 ) { a[i+j*n] = huge; } } } i4mat_floyd ( n, a ); for ( j = 0; j < n; j++ ) { for ( i = 0; i < n; i++ ) { if ( a[i+j*n] == huge ) { a[i+j*n] = - 1; } } } printf ( "\n" ); printf ( " In the final shortest distance array, if\n" ); printf ( " A(I,J) = -1,\n" ); printf ( " this indicates there is NO directed path from\n" ); printf ( " node I to node J.\n" ); i4mat_print ( n, n, a, " Final shortest distance array:" ); return; # undef N }