- Code refactoring.
This commit is contained in:
59
src/system.c
59
src/system.c
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user