From e1890ddc9f1e960e19fadfc2643d7d1ce7ad1e83 Mon Sep 17 00:00:00 2001 From: ccremers Date: Sun, 2 Apr 2006 12:07:25 +0000 Subject: [PATCH] - Improved cost function: now also avoids using initiators when possible. --- src/cost.c | 1 + src/system.c | 18 ++++++++++++++++++ src/system.h | 1 + 3 files changed, 20 insertions(+) diff --git a/src/cost.c b/src/cost.c index 7e78a34..38e6adf 100644 --- a/src/cost.c +++ b/src/cost.c @@ -35,6 +35,7 @@ attackCost (const System sys) cost += get_semitrace_length (); cost += 8 * selfInitiators (sys); cost += 4 * selfResponders (sys); + cost += 2 * countInitiators (sys); return cost; } diff --git a/src/system.c b/src/system.c index dedf3f7..99fc117 100644 --- a/src/system.c +++ b/src/system.c @@ -1399,6 +1399,24 @@ eventRoledef (const System sys, const int run, const int ev) return roledef_shift (sys->runs[run].start, ev); } +//! count the number of initiators +int +countInitiators (const System sys) +{ + int run; + int count; + + count = 0; + for (run = 0; run < sys->maxruns; run++) + { + if (sys->runs[run].role->initiator) + { + count++; + } + } + return count; +} + //! determine whether a run talks to itself int selfSession (const System sys, const int run) diff --git a/src/system.h b/src/system.h index 968435f..1288711 100644 --- a/src/system.h +++ b/src/system.h @@ -201,6 +201,7 @@ int iterateLocalToOther (const System sys, const int myrun, int (*callback) (Term t)); int firstOccurrence (const System sys, const int r, Term t, int evtype); Roledef eventRoledef (const System sys, const int run, const int ev); +int countInitiators (const System sys); int selfResponder (const System sys, const int run); int selfResponders (const System sys); int selfInitiator (const System sys, const int run);