- Graph closure fixed.

This commit is contained in:
ccremers 2004-10-28 15:37:13 +00:00
parent 0ec70b9de0
commit aaa0d415f9

View File

@ -58,34 +58,34 @@ graph_display (int *graph, int nodes)
int int
warshall (int *graph, int nodes) warshall (int *graph, int nodes)
{ {
int i; int k;
int index (const int i, const int j) int index (const int x, const int y)
{ {
return (i * nodes + j); return (x * nodes + y);
} }
k = 0;
while (k < nodes)
{
int i;
i = 0; i = 0;
while (i < nodes) while (i < nodes)
{
if (graph[index (i, k)] == 1)
{ {
int j; int j;
j = 0; j = 0;
while (j < nodes) while (j < nodes)
{
if (graph[index (j, i)] == 1)
{
int k;
k = 0;
while (k < nodes)
{ {
if (graph[index (k, j)] == 1) if (graph[index (k, j)] == 1)
{ {
if (k == i) if (i == j)
{ {
// Oh no! A cycle. // Oh no! A cycle.
graph[index (k, i)] = 2; graph[index (i, j)] = 2;
#ifdef DEBUG #ifdef DEBUG
if (DEBUGL (5)) if (DEBUGL (5))
{ {
@ -94,15 +94,15 @@ warshall (int *graph, int nodes)
#endif #endif
return 0; return 0;
} }
graph[index (k, i)] = 1; graph[index (i, j)] = 1;
}
k++;
}
} }
j++; j++;
} }
}
i++; i++;
} }
k++;
}
return 1; return 1;
} }