- Code refactoring.

This commit is contained in:
ccremers
2006-03-28 14:45:02 +00:00
parent b224344b59
commit 5fe55d35cf
4 changed files with 68 additions and 81 deletions

View File

@@ -1398,3 +1398,62 @@ eventRoledef (const System sys, const int run, const int ev)
{
return roledef_shift (sys->runs[run].start, ev);
}
//! determine whether a run is a so-called self-initiator
/**
* Alice starting a run with Bob, Charlie, Bob is also counted as self-initiation.
*/
int
selfInitiator (const System sys, const int run)
{
int self_initiator;
self_initiator = false;
if (sys->runs[run].role->initiator)
{
// An initiator
Termlist agents;
Termlist seen;
agents = sys->runs[run].rho;
seen = NULL;
while (agents != NULL)
{
Term agent;
agent = agents->term;
if (inTermlist (seen, agent))
{
// This agent was already in the seen list
self_initiator = true;
}
else
{
seen = termlistAdd (seen, agent);
}
agents = agents->next;
}
termlistDelete (seen);
}
return self_initiator;
}
//! Count the number of any self-initiators
int
selfInitiators (const System sys)
{
int count;
int run;
count = 0;
run = 0;
while (run < sys->maxruns)
{
if (selfInitiator (sys, run))
{
count++;
}
run++;
}
return count;
}