]> mj.ucw.cz Git - leo.git/commitdiff
Labeller: Better format strings in printfs
authorKarryanna <karry@karryanna.cz>
Mon, 29 Jun 2015 15:10:23 +0000 (17:10 +0200)
committerKarryanna <karry@karryanna.cz>
Mon, 29 Jun 2015 15:10:23 +0000 (17:10 +0200)
labeller.c

index f9eb4a839fbec90b131b309839c2e0e54b2cb82c..90309743534add378158bfd5c4cce1710125f5fc 100644 (file)
@@ -46,9 +46,9 @@ int dbg_bfs = VERBOSITY_NONE;
 int dbg_map_parts = VERBOSITY_NONE;
 int dbg_movement = VERBOSITY_NONE;
 int dbg_init = VERBOSITY_NONE;
-int dbg_overlaps = VERBOSITY_NONE;
+int dbg_overlaps = VERBOSITY_GENERAL;
 int dbg_rank = VERBOSITY_NONE;
-int dbg_evolution = VERBOSITY_INDIVIDUAL;
+int dbg_evolution = VERBOSITY_POPULATION;
 int dbg_mutation = VERBOSITY_NONE;
 int dbg_breeding = VERBOSITY_NONE;
 
@@ -64,33 +64,33 @@ int conf_fit_size = 1;
 
 int conf_penalty_bound = 0;
 int conf_stagnation_bound = 0;
-int conf_iteration_limit = 100;
+int conf_iteration_limit = 10;
 
 int conf_term_cond = TERM_COND_ITERATIONS;
 
-double conf_breed_pop_size = 0.4;
-double conf_breed_rbest = 0.2;
+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 = 1.0;
+double conf_mutate_children_prob = 0.6;
 
-double conf_mutate_pop_size = 0.4;
+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.0;
+double conf_mutate_chvar_bound = 0.1;
 
 int mutate_pop_size;
 int mutate_rbest_size;
 
-double conf_elite_pop_size = 0.2;
+double conf_elite_pop_size = 0.1;
 int elite_pop_size;
 
-double conf_max_section_length = 100;
+double conf_max_section_length = 80;
 double conf_max_section_overlay = 10;
 
 int old_best = INT_MAX;
@@ -188,6 +188,10 @@ void dump_linelabel_requests(void);
 void dump_individual(struct individual *individual);
 void dump_label(struct symbol *sym);
 void dump_penalties(struct individual **population);
+void dump_placements(struct individual *individual);
+void dump_placement_links(struct placement *p);
+void dump_part_links(struct map_part *part);
+void dump_links(struct individual *individual);
 
 int randint(int min, int max);
 int flip(int a, int b);
@@ -422,7 +426,7 @@ void make_graph(void)
   struct mempool *mp_edges = mp_new(BLOCK_SIZE);
 
   if (dbg_graph >= VERBOSITY_GENERAL)
-    printf("Extracting nodes, will iterate over %lld ways\n", GARY_SIZE(buffer_line));
+    printf("Extracting nodes, will iterate over %zu ways\n", GARY_SIZE(buffer_line));
   for (uns i=0; i<GARY_SIZE(buffer_line); i++)
   {
     struct osm_way *way = (struct osm_way *) buffer_line[i].line->s.o;
@@ -512,7 +516,7 @@ void dump_graph(void)
 void label_graph(void)
 {
   if (dbg_graph >= VERBOSITY_GENERAL)
-    printf("There are %u line labels requested\n", GARY_SIZE(buffer_linelabel));
+    printf("There are %zu line labels requested\n", GARY_SIZE(buffer_linelabel));
   for (uns i=0; i<GARY_SIZE(buffer_linelabel); i++)
   {
     if (buffer_linelabel[i].label->type == SYMBOLIZER_TEXT)
@@ -530,7 +534,7 @@ void label_graph(void)
       else
       {
         if (dbg_graph >= VERBOSITY_ALL)
-          printf("Searching among %u edges\n", GARY_SIZE(n->edges));
+          printf("Searching among %zu edges\n", GARY_SIZE(n->edges));
         for (uns j=0; j<GARY_SIZE(n->edges); j++)
         {
           if (n->edges[j]->id == buffer_linelabel[i].way->o.id)
@@ -617,14 +621,14 @@ void bfs(uns longline)
   if (dbg_bfs >= VERBOSITY_INDIVIDUAL)
   {
     printf("BFS called for longline %u\n", longline);
-    printf("%d longlines exist\n", GARY_SIZE(longlines));
+    printf("%zu longlines exist\n", GARY_SIZE(longlines));
   }
 
   for (uns i=0; i<GARY_SIZE(bfs_queue); i++)
   {
     struct graph_edge *cur = bfs_queue[i];
     if (dbg_bfs >= VERBOSITY_PLACEMENT)
-      printf("Exploring new edge %d; %d remaining\n", cur->num, GARY_SIZE(bfs_queue));
+      printf("Exploring new edge %d; %zu remaining\n", cur->num, GARY_SIZE(bfs_queue));
 
     cur->visited = longline;
 
@@ -672,7 +676,7 @@ void bfs_wrapper(void)
         if (dbg_bfs >= VERBOSITY_INDIVIDUAL)
         {
           printf("Running new BFS\n");
-          printf("Creating longline %u\n", GARY_SIZE(longlines)-1);
+          printf("Creating longline %zu\n", GARY_SIZE(longlines)-1);
         }
 
         GARY_RESIZE(bfs_queue, 0);
@@ -684,7 +688,7 @@ void bfs_wrapper(void)
         if (dbg_bfs >= VERBOSITY_INDIVIDUAL)
         {
           printf("Joined %d edges\n", dbg_num_hits); dbg_num_hits = 0;
-          printf("Planned %u edges\n", GARY_SIZE(bfs_queue));
+          printf("Planned %zu edges\n", GARY_SIZE(bfs_queue));
         }
       }
     }
@@ -919,15 +923,15 @@ void dump_linelabel_requests(void)
       continue;
     }
 
-    printf("Request for linelabel, %d sections\n", GARY_SIZE(requests_line[i].sections));
+    printf("Request for linelabel, %zu sections\n", GARY_SIZE(requests_line[i].sections));
     dump_label(requests_line[i].sections[0].segments[0].label);
     for (uns j=0; j<GARY_SIZE(requests_line[i].sections); j++)
     {
-      printf("%d section, %d segments\n", j, GARY_SIZE(requests_line[i].sections[j].segments));
+      printf("%u section, %zu segments [%d]\n", j, GARY_SIZE(requests_line[i].sections[j].segments), requests_line[i].sections[j].request.ind);
       for (uns k=0; k<GARY_SIZE(requests_line[i].sections[j].segments); k++)
       {
         struct request_segment *rs = &requests_line[i].sections[j].segments[k];
-        printf("[%.2f; %.2f] -- [%.2f; %.2f]\n", rs->x1, rs->y1, rs->x2, rs->y2);
+        printf("[%.2f; %.2f] -- [%.2f; %.2f]\t\t[%d]\n", rs->x1, rs->y1, rs->x2, rs->y2, rs->request.ind);
       }
     }
     printf("\n");
@@ -1035,12 +1039,29 @@ void dump_individual(struct individual *individual)
   printf("\nTotal penalty: %d\n", individual->penalty);
 }
 
+void dump_placements(struct individual *individual)
+{
+  printf("*** Individual placements dump\n");
+
+  for (uns i=0; i<GARY_SIZE(individual->placements); i++)
+  {
+    struct placement *p = &individual->placements[i];
+    printf("Placement %d:\tPlacet at [%.2f; %.2f] using variant %d\n", p->ind, p->x, p->y, p->variant_used);
+  }
+}
+
 void plan_individual(struct individual *individual)
 {
   for (uns i=0; i<GARY_SIZE(individual->placements); i++)
   {
     struct symbol *s = NULL;
     z_index_t zindex = 0;
+    /**
+    if (individual->placements[i].variant_used < 0)
+    {
+      printf("Skipping placement of request %d\n", individual->placements[i].request->ind);
+    }
+    **/
     if (individual->placements[i].variant_used < 0) continue;
     switch (individual->placements[i].request->type)
     {
@@ -1067,7 +1088,7 @@ void plan_individual(struct individual *individual)
     }
 
   if (dbg_plan >= VERBOSITY_PLACEMENT)
-    printf("Will plan symbol at [%.2f; %.2f] on %u\n", individual->placements[i].x, individual->placements[i].y, zindex);
+    printf("Will plan symbol of request %d at [%.2f; %.2f] on %u\n", individual->placements[i].request->ind, individual->placements[i].x, individual->placements[i].y, zindex);
 
     if (s) switch (s->type)
     {
@@ -1106,6 +1127,41 @@ void dump_penalties(struct individual **population)
   }
 }
 
+void dump_placement_links(struct placement *p)
+{
+  struct map_placement *mp = p->map_links;
+
+  while (mp)
+  {
+    printf(" %d", mp->part->ind);
+    mp = mp->next_in_placement;
+  }
+
+  printf("\n");
+}
+
+void dump_part_links(struct map_part *part)
+{
+  struct map_placement *mp = part->placement->next_in_map;
+
+  while (mp)
+  {
+    printf(" %d", mp->placement->ind);
+    mp = mp->next_in_map;
+  }
+
+  printf("\n");
+}
+
+void dump_links(struct individual *individual)
+{
+  printf("Dumping links in individual\n");
+  for (uns i=0; i<GARY_SIZE(individual->placements); i++)
+  {
+    dump_placement_links(&individual->placements[i]);
+  }
+}
+
 void compute_sizes(void)
 {
   page_width_int = floor(page_width);
@@ -1157,11 +1213,14 @@ void compute_sizes(void)
 
 void labeller_label(void)
 {
+//srandom(29011992);
   make_graph();
   label_graph();
   bfs_wrapper();
   make_segments();
 
+  printf("Will deal with %d requests\n", num_requests);
+
   GARY_INIT(population1, conf_pop_size);
   GARY_INIT(population2, conf_pop_size);
   make_population();
@@ -1192,6 +1251,12 @@ void labeller_label(void)
 
     rank_population();
 
+    if (dbg_evolution >= VERBOSITY_INDIVIDUAL)
+    {
+      printf("Penalties before sort\n");
+      dump_penalties(population1);
+    }
+
     if (dbg_evolution >= VERBOSITY_GENERAL)
       printf("Sorting population\n");
     qsort(population1, conf_pop_size, sizeof(struct individual *), cmp_individual);
@@ -1427,6 +1492,10 @@ void elite(void)
 {
   for (int i=0; i<elite_pop_size; i++)
   {
+    if (dbg_evolution >= VERBOSITY_INDIVIDUAL)
+    {
+      printf("Iteration %d: Copying individual #%d from pop 1 to #%d in pop 2\n", iteration, i, pop2_ind);
+    }
     population2[pop2_ind] = ep_alloc(ep_individuals);
     copy_individual(population1[i], population2[pop2_ind++]);
   }
@@ -1487,8 +1556,11 @@ int get_overlap(struct placement *p)
   planned[p->request->ind] = 1;
   GARY_INIT(others, 0);
 
+//printf("Iterating over parts of placement %d (at [%.2f; %.2f] / %d)\n", p->ind, p->x, p->y, p->variant_used);
   for (uns i=0; i<GARY_SIZE(parts); i++)
   {
+  //printf("%d:\t", parts[i]->ind);
+  //dump_part_links(parts[i]);
     struct map_placement *mp = parts[i]->placement->next_in_map;
     while (mp)
     {
@@ -1513,7 +1585,10 @@ int get_overlap(struct placement *p)
   GARY_FREE(others);
 
   if (dbg_overlaps >= VERBOSITY_PLACEMENT)
-    printf("Placement of request %d add %d to overlaps\n", p->request->ind, overlap);
+  {
+    printf("Placement %d (of request %d) add %d to overlaps", p->ind, p->request->ind, overlap);
+    dump_placement_links(p);
+  }
 
   if (p->x < 0) overlap += 0 - p->x;
   if (p->x + p->request->variants[p->variant_used].width > page_width_int)
@@ -1535,6 +1610,8 @@ int individual_overlap(struct individual *individual)
     overlap += get_overlap(&individual->placements[i]);
   }
 
+//  printf("Total overlap is %d\n", overlap);
+
   return overlap;
 }
 
@@ -1733,12 +1810,12 @@ struct map_part **get_map_parts(struct placement *p)
     {
       struct map_part **m = GARY_PUSH(buffer);
       if (dbg_map_parts >= VERBOSITY_ALL)
-        printf("Asking for %d of %u\n", y * num_map_parts_row + x, GARY_SIZE(p->individual->map));
+        printf("Asking for %d of %zu\n", y * num_map_parts_row + x, GARY_SIZE(p->individual->map));
       *m = p->individual->map[y * num_map_parts_row + x];
     }
 
   if (dbg_map_parts >= VERBOSITY_PLACEMENT)
-    printf("Returning %u map parts potentially containing the symbol\n", GARY_SIZE(buffer));
+    printf("Returning %zu map parts potentially containing the symbol\n", GARY_SIZE(buffer));
 
   return buffer;
 }
@@ -1873,13 +1950,13 @@ struct placement **get_closure(struct placement *placement)
   while (first < GARY_SIZE(closure))
   {
     if (dbg_breeding >= VERBOSITY_ALL)
-      printf("Iterating, first is %d of current %u\n", first, GARY_SIZE(closure));
+      printf("Iterating, first is %u of current %zu\n", first, GARY_SIZE(closure));
     struct placement **overlapping = get_overlapping(placement);
     if (! overlapping) { first++; continue; }
 
     struct placement **filtered = filter(overlapping, &chosen);
     if (dbg_breeding >= VERBOSITY_ALL)
-      printf("There are %u new overlapping symbols\n", GARY_SIZE(filtered));
+      printf("There are %zu new overlapping symbols\n", GARY_SIZE(filtered));
     GARY_FREE(overlapping);
     overlapping = filtered;
     for (uns j=0; j<GARY_SIZE(overlapping); j++)
@@ -1908,7 +1985,7 @@ void copy_symbols(struct placement **closure, struct individual *parent, struct
 {
   bool *processed = *processed_ptr;
   if (dbg_breeding >= VERBOSITY_ALL)
-    printf("Will copy %u symbols\n", GARY_SIZE(closure));
+    printf("Will copy %zu symbols\n", GARY_SIZE(closure));
 
   for (uns i=0; i<GARY_SIZE(closure); i++)
   {
@@ -2020,6 +2097,7 @@ void init_placement(struct placement *p, struct individual *individual, struct r
     printf("Inited placement to [%.2f; %.2f]\n", p->x, p->y);
 }
 
+/**
 void reset_individual_map(struct individual *i)
 {
   for (uns j=0; j<num_map_parts; j++)
@@ -2044,7 +2122,9 @@ void reset_individual_map(struct individual *i)
     i->map[j] = part;
   }
 }
+**/
 
+/**
 void update_individual(struct individual *individual)
 {
   for (uns i=0; i<GARY_SIZE(individual->placements); i++)
@@ -2052,6 +2132,7 @@ void update_individual(struct individual *individual)
     update_map_parts_delete(&individual->placements[i]);
   }
 }
+**/
 
 void clear_individual(struct individual *individual)
 {
@@ -2105,7 +2186,7 @@ struct placement **get_overlapping(struct placement *p)
   GARY_FREE(parts);
 
   if (dbg_map_parts >= VERBOSITY_PLACEMENT)
-    printf("Returning %u potentially overlapping placements\n", GARY_SIZE(buffer));
+    printf("Returning %zu potentially overlapping placements\n", GARY_SIZE(buffer));
 
   return buffer;
 }