/** * Warshall's algorithm for transitive closure computation. */ #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) { // Oh no! A cycle. graph[index (k, i)] = 2; #ifdef DEBUG if (DEBUGL (5)) { graph_display (graph, nodes); } #endif return 0; } graph[index (k, i)] = 1; } k++; } } j++; } i++; } return 1; }