From: Florian Forster Date: Wed, 11 Mar 2009 12:08:59 +0000 (+0100) Subject: src/sn-evolution2.c: Calculate mutation probability at runtime. X-Git-Tag: v1.0.0~77 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=bb1bcddb8be079e5033bccef1dfeba8b53227bb5;p=sort-networks.git src/sn-evolution2.c: Calculate mutation probability at runtime. --- diff --git a/src/Makefile b/src/Makefile index 4b1e438..3cbbcd2 100644 --- a/src/Makefile +++ b/src/Makefile @@ -3,12 +3,12 @@ CFLAGS = -Wall -Werror -std=c99 -O3 -pthread #CFLAGS = -Wall -Werror -std=c99 -O0 -g -pthread APPLICATIONS = sn-apply sn-batcher sn-check-bf sn-cut sn-cut-loop \ - sn-evolution sn-find-9 sn-merge \ + sn-evolution sn-evolution2 sn-find-9 sn-merge \ sn-normalize sn-oddevenmerge sn-show sn-tex -POPULATION_CFLAGS = -I/tmp/sifnfors/libpopulation/include +POPULATION_CFLAGS = -I/tmp/libpopulation/include -POPULATION_LDFLAGS = -L/tmp/sifnfors/libpopulation/lib -Wl,--rpath -Wl,/tmp/sifnfors/libpopulation/lib -lpopulation +POPULATION_LDFLAGS = -L/tmp/libpopulation/lib -Wl,--rpath -Wl,/tmp/libpopulation/lib -lpopulation all: $(APPLICATIONS) @@ -39,7 +39,7 @@ sn-evolution: LDFLAGS += $(POPULATION_LDFLAGS) sn-evolution: sn-evolution.c sn_network.o sn_stage.o sn_comparator.o sn_population.o sn_random.o sn-evolution2: CFLAGS += $(POPULATION_CFLAGS) -sn-evolution2: LDFLAGS += $(POPULATION_LDFLAGS) +sn-evolution2: LDFLAGS += $(POPULATION_LDFLAGS) -lm sn-evolution2: sn-evolution2.c sn_network.o sn_stage.o sn_comparator.o sn_population.o sn_random.o sn-find-9: sn-find-9.c sn_network.o sn_stage.o sn_comparator.o sn_random.o diff --git a/src/sn-evolution2.c b/src/sn-evolution2.c index 07c33a2..c40e53d 100644 --- a/src/sn-evolution2.c +++ b/src/sn-evolution2.c @@ -39,6 +39,8 @@ #include #include +#include + #include #include @@ -252,10 +254,23 @@ static sn_comparator_t get_random_comparator (void) /* {{{ */ static int mutate_network (sn_comparator_t *comparators, int comparators_num) { + static int old_comparators_num = -1; + static int cut_off = 1000000; + int i; + if (old_comparators_num != comparators_num) + { + double p; + + p = powl (0.5, (1.0 / ((double) comparators_num))); + cut_off = (int) (((double) 1000000) * p); + + old_comparators_num = comparators_num; + } + for (i = 0; i < comparators_num; i++) - if (sn_bounded_random (0, 1000000) >= 972655) + if (sn_bounded_random (0, 1000000) >= cut_off) comparators[i] = get_random_comparator (); return (0);