Added cost code to match compromise branch.

Includes some refactoring in cost.c.
This commit is contained in:
Cas Cremers 2011-04-26 11:49:05 +02:00
parent e23c79f59d
commit 8ec1908306
3 changed files with 26 additions and 15 deletions

View File

@ -48,6 +48,27 @@
* A lower value (closer to 0) is a more feasible attack. * A lower value (closer to 0) is a more feasible attack.
*/ */
int int
computeAttackCost (const System sys)
{
// Use nice heuristic cf. work of Gijs Hollestelle. Hand-picked parameters.
int cost;
cost = 0;
//cost += get_semitrace_length ();
cost += 10 * selfInitiators (sys);
cost += 7 * selfResponders (sys);
cost += 10 * sys->num_regular_runs;
cost += 3 * countInitiators (sys);
cost += 2 * countBindingsDone ();
cost += 1 * sys->num_intruder_runs;
return cost;
}
//! Compute attack cost in different pruning contexts.
int
attackCost (const System sys) attackCost (const System sys)
{ {
if (switches.prune == 0) if (switches.prune == 0)
@ -72,21 +93,7 @@ attackCost (const System sys)
} }
if (switches.prune == 2) if (switches.prune == 2)
{ {
// Use nice heuristic cf. work of Gijs Hollestelle. Hand-picked parameters. return computeAttackCost (sys);
int cost;
cost = 0;
//cost += get_semitrace_length ();
cost += 10 * selfInitiators (sys);
cost += 7 * selfResponders (sys);
cost += 10 * sys->num_regular_runs;
cost += 3 * countInitiators (sys);
cost += 2 * countBindingsDone ();
cost += 1 * sys->num_intruder_runs;
return cost;
} }
error ("Unknown pruning method (cost function not found)"); error ("Unknown pruning method (cost function not found)");
return 0; return 0;

View File

@ -20,6 +20,7 @@
#ifndef COST #ifndef COST
#define COST #define COST
int computeAttackCost (const System sys);
int attackCost (const System sys); int attackCost (const System sys);
#endif #endif

View File

@ -28,6 +28,7 @@
#include "debug.h" #include "debug.h"
#include "error.h" #include "error.h"
#include "specialterm.h" #include "specialterm.h"
#include "cost.h"
extern Protocol INTRUDER; // Pointers, to be set by the Init of arachne.c extern Protocol INTRUDER; // Pointers, to be set by the Init of arachne.c
extern Role I_M; // Same here. extern Role I_M; // Same here.
@ -1658,6 +1659,8 @@ dotSemiState (const System mysys)
termPrintRemap (sys->current_claim->rolename); termPrintRemap (sys->current_claim->rolename);
eprintf (", claim type "); eprintf (", claim type ");
termPrintRemap (sys->current_claim->type); termPrintRemap (sys->current_claim->type);
// For debugging:
eprintf (", cost %i", computeAttackCost (sys));
eprintf ("\";\n"); eprintf ("\";\n");
// Needed for the bindings later on: create graph // Needed for the bindings later on: create graph