From: Florian Forster Date: Tue, 1 Feb 2011 07:43:10 +0000 (+0100) Subject: sn-evolution: Add the "-m" option. X-Git-Tag: v1.1.0~9 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=7113bfbc96eb65431bad9d9985ba04a18f4912cb;p=sort-networks.git sn-evolution: Add the "-m" option. --- diff --git a/src/sn-evolution.c b/src/sn-evolution.c index 72bd141..9f63506 100644 --- a/src/sn-evolution.c +++ b/src/sn-evolution.c @@ -33,6 +33,7 @@ #include #include #include +#include #include #include @@ -65,6 +66,13 @@ static int stats_interval = 0; static int max_population_size = 128; static population_t *population; +static enum +{ + MERGER_ODDEVEN, + MERGER_BITONIC, + MERGER_RANDOM +} selected_merger = MERGER_ODDEVEN; + static int evolution_threads_num = 4; static int do_loop = 0; @@ -84,6 +92,8 @@ static void exit_usage (const char *name) " -p Size of the population (default: 128)\n" " -P Send individuals to (may be repeated)\n" " -t Number of threads (default: 4)\n" + " -m Specify the merging network to use.\n" + " Available: \"oddeven\", \"bitonic\", \"random\"\n" "\n", name); exit (1); @@ -93,7 +103,7 @@ int read_options (int argc, char **argv) { int option; - while ((option = getopt (argc, argv, "i:o:p:P:s:t:h")) != -1) + while ((option = getopt (argc, argv, "i:o:p:P:s:t:m:h")) != -1) { switch (option) { @@ -153,6 +163,19 @@ int read_options (int argc, char **argv) break; } + case 'm': + { + if (strcasecmp ("oddeven", optarg) == 0) + selected_merger = MERGER_ODDEVEN; + else if (strcasecmp ("bitonic", optarg) == 0) + selected_merger = MERGER_BITONIC; + else if (strcasecmp ("random", optarg) == 0) + selected_merger = MERGER_RANDOM; + else + fprintf (stderr, "Not a valid merging strategy: \"%s\"\n", optarg); + break; + } + case 'h': default: exit_usage (argv[0]); @@ -230,7 +253,12 @@ static int create_offspring (void) assert (p1 != NULL); /* combine the two parents */ - n = sn_network_combine (p0, p1); + if ((selected_merger == MERGER_ODDEVEN) + || ((selected_merger == MERGER_RANDOM) + && (sn_bounded_random (0, 1) == 0))) + n = sn_network_combine_odd_even_merge (p0, p1); + else + n = sn_network_combine_bitonic_merge (p0, p1); sn_network_destroy (p0); sn_network_destroy (p1);