src/sn-evolution2.c: Calculate mutation probability at runtime.
authorFlorian Forster <octo@leeloo.lan.home.verplant.org>
Wed, 11 Mar 2009 12:08:59 +0000 (13:08 +0100)
committerFlorian Forster <octo@leeloo.lan.home.verplant.org>
Wed, 11 Mar 2009 12:08:59 +0000 (13:08 +0100)
src/Makefile
src/sn-evolution2.c

index 4b1e438..3cbbcd2 100644 (file)
@@ -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
index 07c33a2..c40e53d 100644 (file)
@@ -39,6 +39,8 @@
 #include <assert.h>
 #include <limits.h>
 
+#include <math.h>
+
 #include <pthread.h>
 
 #include <population.h>
@@ -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);