/** * Warshall's algorithm for transitive closure computation. */ #include #include "warshall.h" #include "debug.h" void graph_fill (int *graph, int nodes, int value) { int node; node = 0; while (node < (nodes * nodes)) { graph[node] = value; node++; } } //! Show a graph void graph_display (int *graph, int nodes) { int i; int index (const int i, const int j) { return (i * nodes + j); } i = 0; while (i < nodes) { int j; j = 0; while (j < nodes) { eprintf ("%i ", graph[index (i, j)]); j++; } eprintf ("\n"); i++; } } //! Apply warshall's algorithm to determine the closure of a graph /** * If j 0) { // There are still unassigned nodes int n; n = 0; while (n < nodes) { if (ranks[n] == INT_MAX) { // Does this node have incoming stuff from stuff with equal rank or higher? int refn; refn = 0; while (refn < nodes) { if (ranks[refn] >= rank && graph[graph_index(refn, n)] != 0) refn = nodes+1; else refn++; } if (refn == nodes) { ranks[n] = rank; todo--; } } n++; } rank++; } return rank; }