From 2680a2ca7a27f04a6462c2dae82199684cdf1738 Mon Sep 17 00:00:00 2001 From: ccremers Date: Mon, 25 Oct 2004 14:28:53 +0000 Subject: [PATCH] - Added rank calculation and output. If the subgraphs are removed, this will allow for better positioning of the graphs. It also helps a lot for latex output. In fact, latex output is fairly trivial now. --- src/arachne.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/warshall.c | 55 ++++++++++++++++++++++++++++++++++++++++++++ src/warshall.h | 3 ++- 3 files changed, 119 insertions(+), 1 deletion(-) diff --git a/src/arachne.c b/src/arachne.c index 68ef899..c3e13b0 100644 --- a/src/arachne.c +++ b/src/arachne.c @@ -17,6 +17,7 @@ #include "states.h" #include "mgu.h" #include "arachne.h" +#include "memory.h" #include "error.h" #include "claim.h" #include "debug.h" @@ -681,6 +682,8 @@ dotSemiState () static int attack_number = 0; int run; Protocol p; + int *ranks; + int maxrank; void node (const int run, const int index) { @@ -717,6 +720,9 @@ dotSemiState () goal_graph_create (); // create graph warshall (graph, nodes); // determine closure + ranks = memAlloc (nodes * sizeof(int)); + maxrank = graph_ranks (graph, ranks, nodes); // determine ranks + #ifdef DEBUG // For debugging purposes, we also display an ASCII version of some stuff in the comments printSemiState (); @@ -941,6 +947,62 @@ dotSemiState () run++; } + // Third, all ranking info + { + int myrank; + +#ifdef DEBUG + { + int n; + + eprintf ("/* ranks: %i\n", maxrank); + n = 0; + while (n < nodes) + { + eprintf ("%i ", ranks[n]); + n++; + } + eprintf ("\n*/\n\n"); + } +#endif + myrank = 0; + while (myrank < maxrank) + { + int count; + int run; + int run1; + int ev1; + + count = 0; + run = 0; + while (run < sys->maxruns) + { + int ev; + + ev = 0; + while (ev < sys->runs[run].step) + { + if (myrank == ranks[node_number (run,ev)]) + { + if (count == 0) + // For now, disabled + eprintf ("//\t{ rank = same; "); + count++; + eprintf ("r%ii%i; ",run,ev); + } + ev++; + } + run++; + } + if (count > 0) + eprintf ("}\t\t// rank %i\n", myrank); + myrank++; + } + } + + // clean memory + memFree (ranks, nodes * sizeof(int)); // ranks + // close graph eprintf ("};\n\n"); } diff --git a/src/warshall.c b/src/warshall.c index 0a6eb60..a375409 100644 --- a/src/warshall.c +++ b/src/warshall.c @@ -2,6 +2,7 @@ * Warshall's algorithm for transitive closure computation. */ +#include #include "warshall.h" #include "debug.h" @@ -104,3 +105,57 @@ warshall (int *graph, int nodes) } return 1; } + + +//! Determine ranks for all nodes +/** + * Some crude algorithm I sketched on the blackboard. + */ +int graph_ranks (int *graph, int *ranks, int nodes) +{ + int i; + int todo; + int rank; + + i = 0; + while (i < nodes) + { + ranks[i] = INT_MAX; + i++; + } + + todo = nodes; + rank = 0; + while (todo > 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; +} diff --git a/src/warshall.h b/src/warshall.h index cacd517..d4f963b 100644 --- a/src/warshall.h +++ b/src/warshall.h @@ -1,4 +1,5 @@ - +// Header file for warshall.c void graph_fill (int *graph, int nodes, int value); int warshall (int *graph, int nodes); +int graph_ranks (int *graph, int *ranks, int nodes);