- 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.
This commit is contained in:
parent
b44676db2b
commit
2680a2ca7a
@ -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");
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
* Warshall's algorithm for transitive closure computation.
|
||||
*/
|
||||
|
||||
#include <limits.h>
|
||||
#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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user