From 7783527a5d5c04264aa2e6df11a60a50423857d0 Mon Sep 17 00:00:00 2001 From: Karryanna Date: Tue, 30 Jun 2015 15:03:25 +0200 Subject: [PATCH] Labelling: Evolution parameters can be set in config file --- labeller.c | 67 ++++++++++++++++++++++++++++++++++-------------------- labeller.h | 2 ++ leo.c | 3 +++ map.cf | 40 ++++++++++++++++++++++++++++++++ 4 files changed, 87 insertions(+), 25 deletions(-) diff --git a/labeller.c b/labeller.c index a709ccd..61dd53e 100644 --- a/labeller.c +++ b/labeller.c @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -61,39 +62,14 @@ int num_nodes; int num_edges = 0; int dbg_num_hits = 0; -int conf_pop_size = 50; -int conf_fit_size = 1; - -int conf_penalty_bound = 0; -int conf_stagnation_bound = 0; -int conf_iteration_limit = 10; - -int conf_term_cond = TERM_COND_ITERATIONS; - -double conf_breed_pop_size = 0.45; -double conf_breed_rbest = 0.3; - int breed_pop_size; int breed_rbest_size; -bool conf_mutate_children = 1; -double conf_mutate_children_prob = 0.6; - -double conf_mutate_pop_size = 0.45; -double conf_mutate_rbest = 0.2; - -double conf_mutate_move_bound = 0.1; -double conf_mutate_regen_bound = 0.0; -double conf_mutate_chvar_bound = 0.1; - int mutate_pop_size; int mutate_rbest_size; -double conf_elite_pop_size = 0.1; int elite_pop_size; -double conf_max_section_length = 80; -double conf_max_section_overlay = 10; int old_best = INT_MAX; int iteration = 0; @@ -114,6 +90,42 @@ uns num_map_parts_row; uns num_map_parts_col; uns num_map_parts; +int conf_pop_size = 200, conf_fit_size = 1, conf_term_cond = TERM_COND_ITERATIONS; + +double conf_penalty_bound = 100, conf_stagnation_bound = 10; +int conf_iteration_limit = 200; + +double conf_breed_pop_size = 0.45, conf_breed_rbest = 1, + conf_mutate_children, conf_mutate_children_prob = 0.6, + conf_mutate_pop_size = 0.45, conf_mutate_rbest = 1, + conf_mutate_move_bound = 0.1, conf_mutate_regen_bound = 0.05, conf_mutate_chvar_bound = 0.1, + conf_elite_pop_size = 0.1; + +double conf_max_section_length = 80, conf_max_section_overlay = 10; + +static struct cf_section evolution_cf = { + CF_ITEMS { + CF_INT("PopSize", &conf_pop_size), + CF_INT("FitSize", &conf_fit_size), + CF_INT("TermCond", &conf_term_cond), + CF_DOUBLE("PenaltyBound", &conf_penalty_bound), + CF_DOUBLE("StagnationBound", &conf_stagnation_bound), + CF_INT("IterationLimit", &conf_iteration_limit), + CF_DOUBLE("BreedPopSize", &conf_breed_pop_size), + CF_DOUBLE("BreedNumBest", &conf_breed_rbest), + CF_DOUBLE("MutateChild", &conf_mutate_children_prob), + CF_DOUBLE("MutatePopSize", &conf_mutate_pop_size), + CF_DOUBLE("MutateNumBest", &conf_mutate_rbest), + CF_DOUBLE("MutateMoveBound", &conf_mutate_move_bound), + CF_DOUBLE("MutateRegenBound", &conf_mutate_regen_bound), + CF_DOUBLE("MutateChvarBound", &conf_mutate_chvar_bound), + CF_DOUBLE("ElitePopSize", &conf_elite_pop_size), + CF_DOUBLE("MaxSectionLenght", &conf_max_section_length), + CF_DOUBLE("MaxSectionOverlay", &conf_max_section_overlay), + CF_END + } +}; + void compute_sizes(void); void make_population(void); @@ -239,6 +251,11 @@ void dump_label(struct symbol *sym) } } +void labeller_conf(void) +{ + cf_declare_section("Evolution", &evolution_cf, 0); +} + void labeller_init(void) { GARY_INIT(requests_point, 0); diff --git a/labeller.h b/labeller.h index 4fe0d92..8a48631 100644 --- a/labeller.h +++ b/labeller.h @@ -32,6 +32,7 @@ enum request_type enum term_cond { + TERM_COND_UNDEF, TERM_COND_PENALTY, TERM_COND_STAGNATION, TERM_COND_ITERATIONS, @@ -186,6 +187,7 @@ struct individual int penalty; }; +void labeller_conf(void); void labeller_init(void); void labeller_cleanup(void); diff --git a/leo.c b/leo.c index 5888fec..003a2c5 100644 --- a/leo.c +++ b/leo.c @@ -117,6 +117,9 @@ int main(int argc UNUSED, char **argv) // HACKING cf_def_file = argv[1]; cf_declare_section("Debug", &debug_cf, 0); + + labeller_conf(); + opt_parse(&options, argv+2); // TILL HERE diff --git a/map.cf b/map.cf index 809f77f..145ea65 100644 --- a/map.cf +++ b/map.cf @@ -81,3 +81,43 @@ Debug { # Dump planning and drawing of symbols DumpSymbols 0 } + +Evolution { + # Number of individuals in each generation + PopSize 50 + + # Enhance number of individuals created by elitisc to fit population size + FitSize 1 + + # Terminating condition + # 1 -- penalty reached, 2 -- stagnation, 3 -- iteration limit + TermCond 3 + PenaltyBound 100 + StagnationBound 10 + IterationLimit 200 + + # Create that part of generation by breeding + BreedPopSize 0.45 + # Use that part of best individuals for parent selection + BreedNumBest 0.9 + # Probability of children mutation + MutateChild 0.6 + + # Create that part of generation by mutation + MutatePopSize 0.45 + # Use that part of best individuals for individual selection + MutateNumBest 0.9 + # Probability of moving label + MutateMoveBound 0.1 + # Probability of regeneration label coordinates + MutateRegenBound 0.05 + # Probability of changing label variant + MutateChvarBound 0.1 + + ElitePopSize 0.1 + + # Maximal length of line section in milimeters + MaxSectionLenght 80 + # Section's length may exceed limit by at most [mm] + MaxSectionOverlay 10 +} -- 2.39.2