]> mj.ucw.cz Git - leo.git/commitdiff
Labeller: DEBUG macro for one-line debug prints
authorKarryanna <karry@karryanna.cz>
Mon, 29 Jun 2015 17:05:03 +0000 (19:05 +0200)
committerKarryanna <karry@karryanna.cz>
Mon, 29 Jun 2015 17:05:03 +0000 (19:05 +0200)
labeller.c

index bad0242deb0f0dd5eba16ceb8e56c431f5892980..a709ccd8f187f82295dde09c21c4e6e94cc74be0 100644 (file)
@@ -24,6 +24,8 @@
 
 #define BLOCK_SIZE 4096
 
+#define DEBUG(dbg_sec, dbg_lvl, msg, ...) if (dbg_sec >= dbg_lvl) printf(msg, ##__VA_ARGS__)
+
 static struct request_point *requests_point;
 static struct request_line *requests_line;
 static struct request_area *requests_area;
@@ -330,8 +332,7 @@ void make_bitmap_label(struct variant *v, struct sym_text *text)
 
 void labeller_add_point(struct symbol *sym, struct osm_object *object, z_index_t zindex)
 {
-  if (dbg_requests >= VERBOSITY_PLACEMENT)
-    printf("Adding point\n");
+  DEBUG(dbg_requests, VERBOSITY_PLACEMENT, "Adding point\n");
   if (object->type != OSM_TYPE_NODE)
   {
     printf("Warning: Point label requested on non-point object\n");
@@ -370,14 +371,12 @@ void labeller_add_point(struct symbol *sym, struct osm_object *object, z_index_t
       return;
   }
 
-  if (dbg_requests >= VERBOSITY_PLACEMENT)
-    printf("Inited point to [%.2f; %.2f] on %u\n", r->x, r->y, r->zindex);
+  DEBUG(dbg_requests, VERBOSITY_PLACEMENT, "Inited point to [%.2f; %.2f] on %u\n", r->x, r->y, r->zindex);
 }
 
 void labeller_add_line(struct symbol *sym, z_index_t zindex)
 {
-  if (dbg_requests >= VERBOSITY_PLACEMENT)
-    printf("Adding line on %u\n", zindex);
+  DEBUG(dbg_requests, VERBOSITY_PLACEMENT, "Adding line on %u\n", zindex);
   struct buffer_line *b = GARY_PUSH(buffer_line);
   b->line = (struct sym_line *) sym;
   b->zindex = zindex;
@@ -392,8 +391,7 @@ void labeller_add_linelabel(struct symbol *sym, struct osm_object *o, z_index_t
     return;
   }
 
-  if (dbg_requests >= VERBOSITY_PLACEMENT)
-    printf("Labelling way %ju on %u\n", o->id, zindex);
+  DEBUG(dbg_requests, VERBOSITY_PLACEMENT, "Labelling way %ju on %u\n", o->id, zindex);
   struct buffer_linelabel *ll = GARY_PUSH(buffer_linelabel);
   ll->way = (struct osm_way *) o;
   ll->label = sym;
@@ -402,8 +400,7 @@ void labeller_add_linelabel(struct symbol *sym, struct osm_object *o, z_index_t
 
 void labeller_add_arealabel(struct symbol *sym, struct osm_object *o, z_index_t zindex)
 {
-  if (dbg_requests >= VERBOSITY_PLACEMENT)
-    printf("Adding area on %u\n", zindex);
+  DEBUG(dbg_requests, VERBOSITY_PLACEMENT, "Adding area on %u\n", zindex);
   struct request_area *r = GARY_PUSH(requests_area);
 
   r->request.type = REQUEST_AREA;
@@ -425,8 +422,7 @@ void make_graph(void)
   hash_init();
   struct mempool *mp_edges = mp_new(BLOCK_SIZE);
 
-  if (dbg_graph >= VERBOSITY_GENERAL)
-    printf("Extracting nodes, will iterate over %zu ways\n", GARY_SIZE(buffer_line));
+  DEBUG(dbg_graph, VERBOSITY_GENERAL, "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;
@@ -515,17 +511,14 @@ void dump_graph(void)
 
 void label_graph(void)
 {
-  if (dbg_graph >= VERBOSITY_GENERAL)
-    printf("There are %zu line labels requested\n", GARY_SIZE(buffer_linelabel));
+  DEBUG(dbg_graph, VERBOSITY_GENERAL, "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)
-    if (dbg_graph >= VERBOSITY_INDIVIDUAL)
-      printf("Labelling nodes of way %s\n", osm_val_decode(((struct sym_text *) buffer_linelabel[i].label)->text));
+    DEBUG(dbg_graph, VERBOSITY_INDIVIDUAL, "Labelling nodes of way %s\n", osm_val_decode(((struct sym_text *) buffer_linelabel[i].label)->text));
     CLIST_FOR_EACH(struct osm_ref *, ref, buffer_linelabel[i].way->nodes)
     {
-      if (dbg_graph >= VERBOSITY_PLACEMENT)
-        printf("Looking for node %ju\n", ref->o->id);
+      DEBUG(dbg_graph, VERBOSITY_PLACEMENT, "Looking for node %ju\n", ref->o->id);
       struct graph_node *n = hash_find(ref->o->id);
       if (n == NULL)
       {
@@ -533,14 +526,12 @@ void label_graph(void)
       }
       else
       {
-        if (dbg_graph >= VERBOSITY_ALL)
-          printf("Searching among %zu edges\n", GARY_SIZE(n->edges));
+        DEBUG(dbg_graph, VERBOSITY_ALL, "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)
           {
-            if (dbg_graph >= VERBOSITY_ALL)
-              printf("Labelling node %ju\n", n->id);
+            DEBUG(dbg_graph, VERBOSITY_ALL, "Labelling node %ju\n", n->id);
             n->edges[j]->label = buffer_linelabel[i].label;
             n->edges[j]->zindex = buffer_linelabel[i].zindex;
           }
@@ -552,8 +543,7 @@ void label_graph(void)
 
 void bfs_edge(struct graph_edge *e, struct graph_node *node, struct graph_node *anode, enum edge_dir dir)
 {
-  if (dbg_bfs >= VERBOSITY_PLACEMENT)
-    printf("BFS edge called for edge %d (going %d) in direction %d\n", e->num, e->dir, dir);
+  DEBUG(dbg_bfs, VERBOSITY_PLACEMENT, "BFS edge called for edge %d (going %d) in direction %d\n", e->num, e->dir, dir);
   struct graph_edge *candidate = NULL;
 
   for (uns i=0; i<GARY_SIZE(node->edges); i++)
@@ -562,8 +552,7 @@ void bfs_edge(struct graph_edge *e, struct graph_node *node, struct graph_node *
     if ((other->longline != (uns) -1) && (other->longline != e->longline)) continue;
 
     if ((uns) other->visited != e->longline) {
-    if (dbg_bfs >= VERBOSITY_PLACEMENT)
-      printf("Pushing new edge %d / %ju\n", other->num, other->id);
+    DEBUG(dbg_bfs, VERBOSITY_PLACEMENT, "Pushing new edge %d / %ju\n", other->num, other->id);
     struct graph_edge **e_ptr = GARY_PUSH(bfs_queue);
     *e_ptr = other;
     other->visited = e->longline;
@@ -585,8 +574,7 @@ void bfs_edge(struct graph_edge *e, struct graph_node *node, struct graph_node *
 
   if (candidate)
   {
-    if (dbg_bfs >= VERBOSITY_PLACEMENT)
-      printf("New line in longline %u\n", e->longline);
+    DEBUG(dbg_bfs, VERBOSITY_PLACEMENT, "New line in longline %u\n", e->longline);
     struct graph_edge *other = candidate;
       other->longline = e->longline;
       other->dir = dir;
@@ -618,17 +606,13 @@ void bfs_edge(struct graph_edge *e, struct graph_node *node, struct graph_node *
 
 void bfs(uns longline)
 {
-  if (dbg_bfs >= VERBOSITY_INDIVIDUAL)
-  {
-    printf("BFS called for longline %u\n", longline);
-    printf("%zu longlines exist\n", GARY_SIZE(longlines));
-  }
+  DEBUG(dbg_bfs, VERBOSITY_INDIVIDUAL, "BFS called for longline %u\n", longline);
+  DEBUG(dbg_bfs, VERBOSITY_INDIVIDUAL, "%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; %zu remaining\n", cur->num, GARY_SIZE(bfs_queue));
+    DEBUG(dbg_bfs, VERBOSITY_PLACEMENT, "Exploring new edge %d; %zu remaining\n", cur->num, GARY_SIZE(bfs_queue));
 
     cur->visited = longline;
 
@@ -673,11 +657,8 @@ void bfs_wrapper(void)
         GARY_PUSH(longlines);
         longlines[GARY_SIZE(longlines)-1].first = node->edges[i];
 
-        if (dbg_bfs >= VERBOSITY_INDIVIDUAL)
-        {
-          printf("Running new BFS\n");
-          printf("Creating longline %zu\n", GARY_SIZE(longlines)-1);
-        }
+        DEBUG(dbg_bfs, VERBOSITY_INDIVIDUAL, "Running new BFS\n");
+        DEBUG(dbg_bfs, VERBOSITY_INDIVIDUAL, "Creating longline %zu\n", GARY_SIZE(longlines)-1);
 
         GARY_RESIZE(bfs_queue, 0);
         struct graph_edge **e = GARY_PUSH(bfs_queue);
@@ -685,11 +666,8 @@ void bfs_wrapper(void)
         node->edges[i]->longline = GARY_SIZE(longlines)-1;
         bfs(node->edges[i]->longline);
 
-        if (dbg_bfs >= VERBOSITY_INDIVIDUAL)
-        {
-          printf("Joined %d edges\n", dbg_num_hits); dbg_num_hits = 0;
-          printf("Planned %zu edges\n", GARY_SIZE(bfs_queue));
-        }
+        DEBUG(dbg_bfs, VERBOSITY_INDIVIDUAL, "Joined %d edges\n", dbg_num_hits); dbg_num_hits = 0;
+        DEBUG(dbg_bfs, VERBOSITY_INDIVIDUAL, "Planned %zu edges\n", GARY_SIZE(bfs_queue));
       }
     }
   }
@@ -762,8 +740,7 @@ struct request_segment *make_new_segment(struct request_section *rls, struct sym
 
 void cut_edge(struct graph_edge *e, double dist)
 {
-  if (dbg_segments >= VERBOSITY_PLACEMENT)
-    printf("Cutting [%.2f; %.2f] -- [%.2f; %.2f] to dist %.2f\n", e->n1->o->x, e->n1->o->y, e->n2->o->x, e->n2->o->y, dist);
+  DEBUG(dbg_segments, VERBOSITY_PLACEMENT, "Cutting [%.2f; %.2f] -- [%.2f; %.2f] to dist %.2f\n", e->n1->o->x, e->n1->o->y, e->n2->o->x, e->n2->o->y, dist);
 
   struct graph_edge *new = xmalloc(sizeof(struct graph_edge));
   *new = *e;
@@ -785,8 +762,7 @@ void cut_edge(struct graph_edge *e, double dist)
   if ((n1->x == n2->x) && (n1->y == n2->y))
   {
     printf("[%.2f; %.2f] -- [%.2f; %.2f]\n", n1->x, n1->y, n2->x, n2->y);
-    if (dbg_segments >= VERBOSITY_PLACEMENT)
-      printf("Won't cut point\n");
+    DEBUG(dbg_segments, VERBOSITY_PLACEMENT, "Won't cut point\n");
     return;
   }
 
@@ -827,39 +803,33 @@ void make_segments(void)
     else
     {
       // FIXME: Should other label types be supported in future?
-      if (dbg_segments >= VERBOSITY_PLACEMENT)
-        printf("Warning: Skipping line\n");
+      DEBUG(dbg_segments, VERBOSITY_PLACEMENT, "Warning: Skipping line\n");
       continue;
     }
 
-    if (dbg_segments >= VERBOSITY_INDIVIDUAL)
-      printf("New longline\n");
+    DEBUG(dbg_segments, VERBOSITY_INDIVIDUAL, "New longline\n");
 
     while (e)
     {
       if (e->visited < 0)
       {
-        if (dbg_segments >= VERBOSITY_PLACEMENT)
-          printf("BEWARE: Edge cycle\n");
+        DEBUG(dbg_segments, VERBOSITY_PLACEMENT, "BEWARE: Edge cycle\n");
         break;
       }
       e->visited = -1;
 
-      if (dbg_segments >= VERBOSITY_PLACEMENT)
-        printf("Taking edge from [%.2f; %.2f] to [%.2f; %.2f] of length %.2f\n", e->n1->o->x, e->n1->o->y, e->n2->o->x, e->n2->o->y, e->length);
+      DEBUG(dbg_segments, VERBOSITY_PLACEMENT, "Taking edge from [%.2f; %.2f] to [%.2f; %.2f] of length %.2f\n", e->n1->o->x, e->n1->o->y, e->n2->o->x, e->n2->o->y, e->length);
 
       if (st && (e->length < st->tw))
       {
         e = e->next;
-        if (dbg_segments >= VERBOSITY_PLACEMENT)
-          printf("Warning: Skipping segment\n");
+        DEBUG(dbg_segments, VERBOSITY_PLACEMENT, "Warning: Skipping segment\n");
         continue;
       }
 
       if (cur_length + e->length > conf_max_section_length + conf_max_section_overlay)
       {
-        if (dbg_segments >= VERBOSITY_PLACEMENT)
-          printf("Edge too long, length is %.2f; %.2f - %.2f = %.2f\n", e->length, conf_max_section_length, cur_length, conf_max_section_length - cur_length);
+        DEBUG(dbg_segments, VERBOSITY_PLACEMENT, "Edge too long, length is %.2f; %.2f - %.2f = %.2f\n", e->length, conf_max_section_length, cur_length, conf_max_section_length - cur_length);
         // HACK to prevent cutting to 0 lenght
         cut_edge(e, max2(conf_max_section_length - cur_length, 2));
       }
@@ -883,8 +853,7 @@ void make_segments(void)
       cur_length += e->length;
       if (cur_length > conf_max_section_length)
       {
-        if (dbg_segments >= VERBOSITY_PLACEMENT)
-          printf("Making new section, new length would be %f, allowed is %.2f / %.2f\n", cur_length + e->length, conf_max_section_length, conf_max_section_overlay);
+        DEBUG(dbg_segments, VERBOSITY_PLACEMENT, "Making new section, new length would be %f, allowed is %.2f / %.2f\n", cur_length + e->length, conf_max_section_length, conf_max_section_overlay);
 
         rls = make_new_section(request);
         cur_length = 0;
@@ -895,8 +864,7 @@ void make_segments(void)
 
     if (request->sections[0].num_segments == 0)
     {
-      if (dbg_segments >= VERBOSITY_INDIVIDUAL)
-        printf("WARNING: Longline without any segment, skipped\n");
+      DEBUG(dbg_segments, VERBOSITY_INDIVIDUAL, "WARNING: Longline without any segment, skipped\n");
 
       struct request_section *rls = &request->sections[0];
       GARY_FREE(rls->segments);
@@ -918,8 +886,7 @@ void dump_linelabel_requests(void)
   {
     if (requests_line[i].sections[0].num_segments == 0)
     {
-      if (dbg_segments >= VERBOSITY_INDIVIDUAL)
-        printf("Beware: Longline without any segment\n");
+      DEBUG(dbg_segments, VERBOSITY_INDIVIDUAL, "Beware: Longline without any segment\n");
       continue;
     }
 
@@ -979,8 +946,7 @@ void dump_bitmaps(struct individual *individual)
       }
     }
   }
-  if (dbg_overlaps >= VERBOSITY_GENERAL)
-    printf("There were %d collisions during bitmap dump\n", total);
+  DEBUG(dbg_overlaps, VERBOSITY_GENERAL, "There were %d collisions during bitmap dump\n", total);
 
   FILE *fd_dump = fopen("dump.pbm", "w");
   fprintf(fd_dump, "P1\n");
@@ -1087,8 +1053,7 @@ void plan_individual(struct individual *individual)
         continue;
     }
 
-  if (dbg_plan >= VERBOSITY_PLACEMENT)
-    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);
+  DEBUG(dbg_plan, VERBOSITY_PLACEMENT, "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)
     {
@@ -1109,8 +1074,7 @@ void plan_individual(struct individual *individual)
         st->x = individual->placements[i].x;
         st->y = individual->placements[i].y;
         st->next_duplicate = NULL;
-        if (dbg_plan >= VERBOSITY_PLACEMENT)
-          printf("Planning text %s at [%.2f; %.2f] on %u, with rotation %.2f\n", osm_val_decode(st->text), st->x, st->y, zindex, st->rotate);
+        DEBUG(dbg_plan, VERBOSITY_PLACEMENT, "Planning text %s at [%.2f; %.2f] on %u, with rotation %.2f\n", osm_val_decode(st->text), st->x, st->y, zindex, st->rotate);
         sym_plan((struct symbol *) st, zindex);
         break;
       default:
@@ -1257,8 +1221,7 @@ void labeller_label(void)
       dump_penalties(population1);
     }
 
-    if (dbg_evolution >= VERBOSITY_GENERAL)
-      printf("Sorting population\n");
+    DEBUG(dbg_evolution, VERBOSITY_GENERAL, "Sorting population\n");
     qsort(population1, conf_pop_size, sizeof(struct individual *), cmp_individual);
 
     if (dbg_evolution >= VERBOSITY_GENERAL)
@@ -1306,8 +1269,7 @@ void make_population(void)
     init_individual(i2);
     population2[i] = i2;
 
-    if (dbg_init >= VERBOSITY_INDIVIDUAL)
-      printf("Making individual %d\n", i);
+    DEBUG(dbg_init, VERBOSITY_INDIVIDUAL, "Making individual %d\n", i);
     struct individual *individual = ep_alloc(ep_individuals); init_individual(individual);
     population1[i] = individual;
 
@@ -1368,8 +1330,7 @@ void breed(void)
   {
     int parent1 = randint(0, breed_rbest_size);
     int parent2 = randint(0, breed_rbest_size);
-    if (dbg_breeding >= VERBOSITY_INDIVIDUAL)
-      printf("Will breed %d and %d\n", parent1, parent2);
+    DEBUG(dbg_breeding, VERBOSITY_INDIVIDUAL, "Will breed %d and %d\n", parent1, parent2);
 
     breed_buffer = perform_crossover(population1[parent1], population1[parent2]);
     population2[pop2_ind++] = breed_buffer[0];
@@ -1392,23 +1353,20 @@ struct individual **perform_crossover(struct individual *parent1, struct individ
   {
     if (! processed[parent1->placements[i].ind])
     {
-      if (dbg_breeding >= VERBOSITY_PLACEMENT)
-        printf("Creating symbol closure for placement %u\n", i);
+      DEBUG(dbg_breeding, VERBOSITY_PLACEMENT, "Creating symbol closure for placement %u\n", i);
 
       struct placement **clos_symbols = get_closure(&(parent1->placements[i]));
       int x = randint(0, 2);
 
       if (x == 0)
       {
-        if (dbg_breeding >= VERBOSITY_PLACEMENT)
-          printf("Copying parent->child 1->1 and 2->2\n");
+        DEBUG(dbg_breeding, VERBOSITY_PLACEMENT, "Copying parent->child 1->1 and 2->2\n");
         copy_symbols(clos_symbols, parent1, child1, &processed);
         copy_symbols(clos_symbols, parent2, child2, &processed);
       }
       else
       {
-        if (dbg_breeding >= VERBOSITY_PLACEMENT)
-          printf("Copying parent->child 2->1 and 1->2\n");
+        DEBUG(dbg_breeding, VERBOSITY_PLACEMENT, "Copying parent->child 2->1 and 1->2\n");
         copy_symbols(clos_symbols, parent2, child1, &processed);
         copy_symbols(clos_symbols, parent1, child2, &processed);
       }
@@ -1437,15 +1395,12 @@ void mutate(void)
 {
   for (int i=0; i < mutate_pop_size; i++)
   {
-    if (dbg_mutation >= VERBOSITY_INDIVIDUAL)
-      printf("Creating %d-th individual by mutation\n", i);
+    DEBUG(dbg_mutation, VERBOSITY_INDIVIDUAL, "Creating %d-th individual by mutation\n", i);
     int ind = randint(0, mutate_rbest_size);
-    if (dbg_mutation >= VERBOSITY_INDIVIDUAL)
-      printf("Mutating %d-th individual of original population\n", ind);
+    DEBUG(dbg_mutation, VERBOSITY_INDIVIDUAL, "Mutating %d-th individual of original population\n", ind);
     population2[pop2_ind] = ep_alloc(ep_individuals);
     copy_individual(population1[ind], population2[pop2_ind]);
-    if (dbg_mutation >= VERBOSITY_INDIVIDUAL)
-      printf("Individual %d in pop2 inited from individual %d in pop1\n", pop2_ind, ind);
+    DEBUG(dbg_mutation, VERBOSITY_INDIVIDUAL, "Individual %d in pop2 inited from individual %d in pop1\n", pop2_ind, ind);
     perform_mutation(population2[pop2_ind]);
     pop2_ind++;
   }
@@ -1460,8 +1415,7 @@ void perform_mutation(struct individual *individual)
 
     if (x <= acc + conf_mutate_move_bound)
     {
-      if (dbg_mutation >= VERBOSITY_PLACEMENT)
-        printf("Mutation: Moving symbol in placement %u\n", i);
+      DEBUG(dbg_mutation, VERBOSITY_PLACEMENT, "Mutation: Moving symbol in placement %u\n", i);
       move_symbol(&(individual->placements[i]));
       continue;
     }
@@ -1503,10 +1457,7 @@ 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);
-    }
+    DEBUG(dbg_evolution, VERBOSITY_INDIVIDUAL, "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++]);
   }
@@ -1557,8 +1508,7 @@ int get_overlap(struct placement *p, int **planned_ptr, int iteration)
   struct map_part **parts = get_map_parts(p);
   if (! parts)
   {
-    if (dbg_overlaps >= VERBOSITY_PLACEMENT)
-      printf("Placement of request %d seems not to be placed\n", p->request->ind);
+    DEBUG(dbg_overlaps, VERBOSITY_PLACEMENT, "Placement of request %d seems not to be placed\n", p->request->ind);
     return 0;
   }
 
@@ -1643,8 +1593,7 @@ double get_distance(struct placement *p)
       dx = rp->x + v->offset_x - p->x;
       dy = rp->y + v->offset_y - p->y;
       distance = hypot(dx, dy);
-      if (dbg_rank >= VERBOSITY_PLACEMENT)
-        printf("Point placed at [%.2f; %.2f], expected at [%.2f; %.2f]\n", p->x, p->y, rp->x, rp->y);
+      DEBUG(dbg_rank, VERBOSITY_PLACEMENT, "Point placed at [%.2f; %.2f], expected at [%.2f; %.2f]\n", p->x, p->y, rp->x, rp->y);
       break;
     case REQUEST_SEGMENT: ;
       struct request_segment *rs = (struct request_segment *) p->request;
@@ -1696,15 +1645,13 @@ double get_distance(struct placement *p)
       dx = ra->cx + v->offset_x - p->x;
       dy = ra->cy + v->offset_y - p->y;
       distance = hypot(dx, dy);
-      if (dbg_rank >= VERBOSITY_PLACEMENT)
-        printf("Area placed at [%.2f; %.2f], expected at [%.2f; %.2f]\n", p->x, p->y, ra->cx, ra->cy);
+      DEBUG(dbg_rank, VERBOSITY_PLACEMENT, "Area placed at [%.2f; %.2f], expected at [%.2f; %.2f]\n", p->x, p->y, ra->cx, ra->cy);
       break;
     default:
       return 0;
   }
 
-  if (dbg_rank >= VERBOSITY_PLACEMENT)
-    printf("Placement %d has distance %.2f\n", p->ind, distance);
+  DEBUG(dbg_rank, VERBOSITY_PLACEMENT, "Placement %d has distance %.2f\n", p->ind, distance);
   return distance;
 }
 
@@ -1762,23 +1709,19 @@ void rank_population(void)
 
   for (int i=0; i<conf_pop_size; i++)
   {
-    if (dbg_rank >= VERBOSITY_INDIVIDUAL)
-      printf("Individual %d\n", i);
+    DEBUG(dbg_rank, VERBOSITY_INDIVIDUAL, "Individual %d\n", i);
     population1[i]->penalty = 0;
 
     penalty = individual_omittment(population1[i]);
-    if (dbg_rank >= VERBOSITY_INDIVIDUAL)
-      printf("Increasing penalty by %d for omittment\n", penalty);
+    DEBUG(dbg_rank, VERBOSITY_INDIVIDUAL, "Increasing penalty by %d for omittment\n", penalty);
     population1[i]->penalty += penalty;
 
     penalty = individual_overlap(population1[i]);
-    if (dbg_rank >= VERBOSITY_INDIVIDUAL)
-      printf("Increasing penalty by %d for overlap\n", penalty);
+    DEBUG(dbg_rank, VERBOSITY_INDIVIDUAL, "Increasing penalty by %d for overlap\n", penalty);
     population1[i]->penalty += penalty;
 
     penalty = individual_distances(population1[i]);
-    if (dbg_rank >= VERBOSITY_INDIVIDUAL)
-      printf("Increasing penalty by %d for distances\n", penalty);
+    DEBUG(dbg_rank, VERBOSITY_INDIVIDUAL, "Increasing penalty by %d for distances\n", penalty);
     population1[i]->penalty += penalty;
   }
 }
@@ -1790,8 +1733,7 @@ struct map_part **get_map_parts(struct placement *p)
   struct map_part **buffer;
   GARY_INIT(buffer, 0);
 
-  if (dbg_map_parts >= VERBOSITY_PLACEMENT)
-    printf("Looking for map parts containing placement of request %d, placed at [%.2f; %.2f]\n", p->request->ind, p->x, p->y);
+  DEBUG(dbg_map_parts, VERBOSITY_PLACEMENT, "Looking for map parts containing placement of request %d, placed at [%.2f; %.2f]\n", p->request->ind, p->x, p->y);
 
   struct variant v;
   switch (p->request->type)
@@ -1802,13 +1744,11 @@ struct map_part **get_map_parts(struct placement *p)
       v = p->request->variants[p->variant_used];
       break;
     default:
-      if (dbg_map_parts >= VERBOSITY_ALL)
-        printf("Skipping unsupported request type (%d)\n", p->request->type);
+      DEBUG(dbg_map_parts, VERBOSITY_ALL, "Skipping unsupported request type (%d)\n", p->request->type);
       return NULL;
   }
 
-  if (dbg_map_parts >= VERBOSITY_PLACEMENT)
-    printf("Bitmap is %d x %d\n", v.width, v.height);
+  DEBUG(dbg_map_parts, VERBOSITY_PLACEMENT, "Bitmap is %d x %d\n", v.width, v.height);
 
   int x_min = max2(0, p->x) / conf_map_part_width;
   // CHECK ME: Is rounding needed?
@@ -1817,20 +1757,17 @@ struct map_part **get_map_parts(struct placement *p)
   // CHECK ME: Is rounding needed?
   int y_max = min2(page_height_int, (p->y + v.height)) / conf_map_part_height;
 
-  if (dbg_map_parts >= VERBOSITY_PLACEMENT)
-    printf("Cells between [%d; %d] and [%d; %d] generated\n", x_min, y_min, x_max, y_max);
+  DEBUG(dbg_map_parts, VERBOSITY_PLACEMENT, "Cells between [%d; %d] and [%d; %d] generated\n", x_min, y_min, x_max, y_max);
 
   for (int y=y_min; y<=y_max; y++)
     for (int x=x_min; x<=x_max; x++)
     {
       struct map_part **m = GARY_PUSH(buffer);
-      if (dbg_map_parts >= VERBOSITY_ALL)
-        printf("Asking for %d of %zu\n", y * num_map_parts_row + x, GARY_SIZE(p->individual->map));
+      DEBUG(dbg_map_parts, VERBOSITY_ALL, "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 %zu map parts potentially containing the symbol\n", GARY_SIZE(buffer));
+  DEBUG(dbg_map_parts, VERBOSITY_PLACEMENT, "Returning %zu map parts potentially containing the symbol\n", GARY_SIZE(buffer));
 
   return buffer;
 }
@@ -1899,8 +1836,7 @@ void gen_coords(struct placement *p)
         printf("Not yet implemented\n");
       break;
     default:
-      if (dbg_movement >= VERBOSITY_ALL)
-        printf("Testing request type\n");
+      DEBUG(dbg_movement, VERBOSITY_ALL, "Testing request type\n");
       ASSERT(p->request->type != REQUEST_INVALID);
   }
 
@@ -1911,8 +1847,7 @@ double gen_movement(void)
 {
   double m = (random() % 100000) / 10000;
   m = pow(m, 1.0/3) * flip(1, -1);
-  if (dbg_movement >= VERBOSITY_ALL)
-    printf("Movement %.2f\n", m);
+  DEBUG(dbg_movement, VERBOSITY_ALL, "Movement %.2f\n", m);
   return m;
 }
 
@@ -1940,8 +1875,7 @@ void gen_coords_area(struct placement *p)
   p->x = p->x + gen_movement();
   p->y = p->y + gen_movement();
 
-  if (dbg_movement >= VERBOSITY_PLACEMENT)
-    printf("Moved label to [%.2f; %.2f] from [%.2f; %.2f]\n", p->x, p->y, ra->cx, ra->cy);
+  DEBUG(dbg_movement, VERBOSITY_PLACEMENT, "Moved label to [%.2f; %.2f] from [%.2f; %.2f]\n", p->x, p->y, ra->cx, ra->cy);
 }
 
 int randint(int min, int max)
@@ -1964,14 +1898,12 @@ struct placement **get_closure(struct placement *placement)
   uns first = 0;
   while (first < GARY_SIZE(closure))
   {
-    if (dbg_breeding >= VERBOSITY_ALL)
-      printf("Iterating, first is %u of current %zu\n", first, GARY_SIZE(closure));
+    DEBUG(dbg_breeding, VERBOSITY_ALL, "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 %zu new overlapping symbols\n", GARY_SIZE(filtered));
+    DEBUG(dbg_breeding, VERBOSITY_ALL, "There are %zu new overlapping symbols\n", GARY_SIZE(filtered));
     GARY_FREE(overlapping);
     overlapping = filtered;
     for (uns j=0; j<GARY_SIZE(overlapping); j++)
@@ -1981,8 +1913,7 @@ struct placement **get_closure(struct placement *placement)
         if (overlaps(*p, overlapping[j]))
         {
          p = GARY_PUSH(closure); *p = overlapping[j];
-         if (dbg_breeding >= VERBOSITY_ALL)
-            printf("Adding placement of request %d (in fact at [%.2f; %.2f] of size %d x %d)\n", overlapping[j]->request->ind, overlapping[j]->x, overlapping[j]->y, overlapping[j]->request->variants[overlapping[j]->variant_used].width, overlapping[j]->request->variants[overlapping[j]->variant_used].height);
+         DEBUG(dbg_breeding, VERBOSITY_ALL, "Adding placement of request %d (in fact at [%.2f; %.2f] of size %d x %d)\n", overlapping[j]->request->ind, overlapping[j]->x, overlapping[j]->y, overlapping[j]->request->variants[overlapping[j]->variant_used].width, overlapping[j]->request->variants[overlapping[j]->variant_used].height);
          chosen[overlapping[j]->request->ind] = 1;
        }
       }
@@ -1999,8 +1930,7 @@ struct placement **get_closure(struct placement *placement)
 void copy_symbols(struct placement **closure, struct individual *parent, struct individual *child, bool **processed_ptr)
 {
   bool *processed = *processed_ptr;
-  if (dbg_breeding >= VERBOSITY_ALL)
-    printf("Will copy %zu symbols\n", GARY_SIZE(closure));
+  DEBUG(dbg_breeding, VERBOSITY_ALL, "Will copy %zu symbols\n", GARY_SIZE(closure));
 
   for (uns i=0; i<GARY_SIZE(closure); i++)
   {
@@ -2108,8 +2038,7 @@ void init_placement(struct placement *p, struct individual *individual, struct r
   }
 
   gen_coords(p);
-  if (dbg_init >= VERBOSITY_PLACEMENT)
-    printf("Inited placement to [%.2f; %.2f]\n", p->x, p->y);
+  DEBUG(dbg_init, VERBOSITY_PLACEMENT, "Inited placement to [%.2f; %.2f]\n", p->x, p->y);
 }
 
 /**
@@ -2200,8 +2129,7 @@ struct placement **get_overlapping(struct placement *p)
   }
   GARY_FREE(parts);
 
-  if (dbg_map_parts >= VERBOSITY_PLACEMENT)
-    printf("Returning %zu potentially overlapping placements\n", GARY_SIZE(buffer));
+  DEBUG(dbg_map_parts, VERBOSITY_PLACEMENT, "Returning %zu potentially overlapping placements\n", GARY_SIZE(buffer));
 
   return buffer;
 }