X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fsn-evolution2.c;h=c40e53daa863b551e134d9305ce1a3a3c2ac1cde;hb=bb1bcddb8be079e5033bccef1dfeba8b53227bb5;hp=07c33a2e4c789dcbfadec41756f537a38d861c6b;hpb=1449a1da915823283ac33c6a3a8a7c5a057677ef;p=sort-networks.git 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);