2005-12-27 11:19:45 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*@file cost.c
|
|
|
|
*
|
|
|
|
* Determine cost of a given semitrace in sys
|
|
|
|
* Constructed for Arachne results, unreliable otherwise.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#include "switches.h"
|
|
|
|
|
|
|
|
//************************************************************************
|
|
|
|
// Private methods
|
|
|
|
//************************************************************************
|
|
|
|
|
2006-01-02 21:06:08 +00:00
|
|
|
//! determine whether a run is a so-called self-initiator
|
2006-01-02 16:07:56 +00:00
|
|
|
int
|
|
|
|
selfInitiator (const System sys, const int run)
|
2005-12-27 11:19:45 +00:00
|
|
|
{
|
|
|
|
int self_initiator;
|
|
|
|
|
|
|
|
self_initiator = false;
|
|
|
|
if (sys->runs[run].role->initiator)
|
|
|
|
{
|
|
|
|
// An initiator
|
|
|
|
Termlist agents;
|
|
|
|
Termlist seen;
|
|
|
|
|
|
|
|
agents = sys->runs[run].agents;
|
|
|
|
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
|
|
|
|
{
|
|
|
|
termlistAdd (seen, agent);
|
|
|
|
}
|
|
|
|
agents = agents->next;
|
|
|
|
}
|
|
|
|
termlistDelete (seen);
|
|
|
|
}
|
|
|
|
return self_initiator;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Count the number of any self-initiators
|
2006-01-02 16:07:56 +00:00
|
|
|
int
|
|
|
|
selfInitiators (const System sys)
|
2005-12-27 11:19:45 +00:00
|
|
|
{
|
|
|
|
int count;
|
|
|
|
int run;
|
|
|
|
|
|
|
|
count = 0;
|
|
|
|
run = 0;
|
|
|
|
while (run < sys->maxruns)
|
|
|
|
{
|
|
|
|
if (selfInitiator (sys, run))
|
|
|
|
{
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
run++;
|
|
|
|
}
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
//************************************************************************
|
|
|
|
// Public methods
|
|
|
|
//************************************************************************
|
|
|
|
|
|
|
|
//! Determine cost of an attack
|
|
|
|
/*
|
|
|
|
* This should also work on uncompleted semitraces, and should be monotonous
|
|
|
|
* (i.e. further iterations should increase the cost only) so that it can be
|
|
|
|
* used for branch and bound.
|
|
|
|
*
|
|
|
|
* A lower value (closer to 0) is a more feasible attack.
|
|
|
|
*/
|
2006-01-02 16:07:56 +00:00
|
|
|
int
|
|
|
|
attackCost (const System sys)
|
2005-12-27 11:19:45 +00:00
|
|
|
{
|
|
|
|
int cost;
|
|
|
|
|
|
|
|
cost = 0;
|
|
|
|
|
2006-01-02 16:07:56 +00:00
|
|
|
cost += get_semitrace_length ();
|
|
|
|
cost += 5 * selfInitiators (sys);
|
2005-12-27 11:19:45 +00:00
|
|
|
|
|
|
|
return cost;
|
|
|
|
}
|