X-Git-Url: https://git.octo.it/?p=libpopulation.git;a=blobdiff_plain;f=src%2Flibpopulation.c;h=c27fd9bf7adf0306296605b4f1fa9e8fc27ec365;hp=fb99db12099958d63ede666d84bf4bcfa6b9aa19;hb=HEAD;hpb=e9979110419e14fc3d6317f82cc9ed3c1fd3c5ba diff --git a/src/libpopulation.c b/src/libpopulation.c index fb99db1..c27fd9b 100644 --- a/src/libpopulation.c +++ b/src/libpopulation.c @@ -107,6 +107,7 @@ struct population_s #define POPULATION_FLAG_LISTEN 0x01 #define POPULATION_FLAG_SHUTDOWN 0x02 +#define POPULATION_FLAG_EXPLORE 0x10 int flags; pthread_t listen_thread_id; @@ -489,6 +490,27 @@ int population_set_serialization (population_t *p, /* {{{ */ return (0); } /* }}} int population_set_serialization */ +int population_set_replacement_method (population_t *p, int method) /* {{{ */ +{ + int status = 0; + + if (p == NULL) + return (EINVAL); + + pthread_mutex_lock (&p->lock); + + if (method == POPULATION_REPLACEMENT_EXPLOIT) + p->flags &= ~POPULATION_FLAG_EXPLORE; + else if (method == POPULATION_REPLACEMENT_EXPLORE) + p->flags |= POPULATION_FLAG_EXPLORE; + else + status = EINVAL; + + pthread_mutex_unlock (&p->lock); + + return (0); +} /* }}} int population_set_replacement_method */ + int population_add_peer (population_t *p, const char *node, /* {{{ */ const char *port) { @@ -747,6 +769,10 @@ int population_insert (population_t *p, void *pi_orig) /* {{{ */ chance = (int) (((double) (chance_j + chance_pi)) * (rand() / (RAND_MAX + 1.0))); + + if (p->flags & POPULATION_FLAG_EXPLORE) + chance *= .5; + if (chance < chance_j) /* j looses ;) */ { void *temp0;