From: Karryanna Date: Wed, 13 May 2015 09:45:24 +0000 (+0200) Subject: Labelling: Counting label overlaps X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=7a77304fe4edf3d2cce2c772241cc9cde47cc9e1;p=leo.git Labelling: Counting label overlaps --- diff --git a/labeller.c b/labeller.c index 0089fc4..3ccb6a1 100644 --- a/labeller.c +++ b/labeller.c @@ -49,6 +49,7 @@ int dbg_bfs = 0; int dbg_map_parts = 0; int dbg_movement = 0; int dbg_init = 0; +int dbg_overlaps = 0; int page_width_int; int page_height_int; @@ -108,6 +109,10 @@ void join_edge(struct graph_edge *e, int dir); void bfs(uns longline); void make_segments(void); +int overlaps(struct placement *p1, struct placement *p2); +int get_overlap(struct placement *p); +int individual_overlap(struct individual *individual); + void make_population(void); bool shall_terminate(void); void breed(void); @@ -1250,6 +1255,98 @@ void elite(void) } } +int overlaps(struct placement *p1, struct placement *p2) +{ + if (p1->request->type != REQUEST_POINT && + p1->request->type != REQUEST_SEGMENT && + p1->request->type != REQUEST_AREA) + return 0; + + if (p2->request->type != REQUEST_POINT && + p2->request->type != REQUEST_SEGMENT && + p2->request->type != REQUEST_AREA) + return 0; + + if (p1->variant_used == -1 || p2->variant_used == -1) + return 0; + + struct variant *v1, *v2; + + v1 = &(p1->request->variants[p1->variant_used]); + v2 = &(p2->request->variants[p2->variant_used]); + + int p1x = p1->x; int p1y = p1->y; + int p2x = p2->x; int p2y = p2->y; + + int overlap = 0; + for (int y=max2(p1y, p2y); y<=min2(p1y+v1->height, p2y+v2->height); y++) + for (int x=max2(p1x, p2x); x<=min2(p1x+v1->width, p2x+v2->width); x++) + { + if (v1->bitmap[(y-p1y)*v1->width + (x-p1x)] && + v2->bitmap[(y-p2y)*v2->width + (x-p2x)]) + overlap++; + } + + return overlap; +} + +int get_overlap(struct placement *p) +{ + struct map_part **parts = get_map_parts(p); + if (! parts) + { + if (dbg_overlaps) + printf("Placement of request %d seems not to be placed\n", p->request->ind); + return 0; + } + + struct placement **others; + bool *planned; + + GARY_INIT_ZERO(planned, num_requests); + planned[p->request->ind] = 1; + GARY_INIT(others, 0); + + for (uns i=0; iplacement->next; + while (mp) + { + if (! planned[mp->placement->request->ind]) + { + struct placement **p = GARY_PUSH(others); + *p = mp->placement; + planned[mp->placement->request->ind] = true; + } + mp = mp->next; + } + } + + int overlap = 0; + for (uns i=0; iplacements); i++) + { + overlap += get_overlap(&individual->placements[i]); + } + + return overlap; +} + void rank_population(void) { // FIXME