From: Florian Forster Date: Thu, 12 Mar 2009 17:12:56 +0000 (+0100) Subject: src/sn-evolution2.c: Implement the -I option. X-Git-Tag: v1.0.0~74 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=875eadb2a3bce31926fd9bba447a7583db7b7dac;p=sort-networks.git src/sn-evolution2.c: Implement the -I option. It loads a pre-generated network and uses it as initial population. --- diff --git a/src/sn-evolution2.c b/src/sn-evolution2.c index c40e53d..62a0969 100644 --- a/src/sn-evolution2.c +++ b/src/sn-evolution2.c @@ -60,6 +60,7 @@ static int inputs_num = -1; static int comparators_num = -1; +static char *initial_input_file = NULL; static char *best_output_file = NULL; static int stats_interval = 0; @@ -83,6 +84,7 @@ static void exit_usage (const char *name) "Valid options are:\n" " -i Number of inputs\n" " -c Number of comparators\n" + " -I Initial input file\n" " -o Write the current best solution to \n" " -p Size of the population (default: 128)\n" " -P Send individuals to (may be repeated)\n" @@ -96,7 +98,7 @@ int read_options (int argc, char **argv) { int option; - while ((option = getopt (argc, argv, "i:c:o:p:P:s:t:h")) != -1) + while ((option = getopt (argc, argv, "i:c:I:o:p:P:s:t:h")) != -1) { switch (option) { @@ -118,6 +120,14 @@ int read_options (int argc, char **argv) break; } + case 'I': + { + if (initial_input_file != NULL) + free (initial_input_file); + initial_input_file = strdup (optarg); + break; + } + case 'o': { if (best_output_file != NULL) @@ -495,6 +505,30 @@ int main (int argc, char **argv) population_start_listen_thread (population, NULL, NULL); + if (initial_input_file != NULL) + { + sn_network_t *n; + + n = sn_network_read_file (initial_input_file); + if (n == NULL) + { + fprintf (stderr, "Cannot read network from `%s'.\n", + initial_input_file); + exit (EXIT_FAILURE); + } + + if (n->inputs_num != inputs_num) + { + fprintf (stderr, "Network `%s' has %i inputs, but %i were configured " + "on the command line.\n", + initial_input_file, n->inputs_num, inputs_num); + exit (EXIT_FAILURE); + } + + population_insert (population, n); + sn_network_destroy (n); + } + else /* if (initial_input_file == NULL) */ { sn_network_t *n; int i;