From: Karryanna Date: Mon, 29 Jun 2015 16:33:59 +0000 (+0200) Subject: Labelling: Changes in overlap counting to decrease complexity X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=0800e8f3057e5b2ee107ca921bebe8c1f1988316;p=leo.git Labelling: Changes in overlap counting to decrease complexity Repeated initialization of planned array made the computation quadratic in fact. The array is now initialized only ones. --- diff --git a/labeller.c b/labeller.c index 3a608d4..97e4714 100644 --- a/labeller.c +++ b/labeller.c @@ -123,7 +123,7 @@ void rank_population(void); void plan_individual(struct individual *individual); int overlaps(struct placement *p1, struct placement *p2); -int get_overlap(struct placement *p); +int get_overlap(struct placement *p, int **planed_ptr, int iteration); int individual_overlap(struct individual *individual); double get_distance(struct placement *p); @@ -1537,8 +1537,10 @@ int overlaps(struct placement *p1, struct placement *p2) return overlap; } -int get_overlap(struct placement *p) +int get_overlap(struct placement *p, int **planned_ptr, int iteration) { + int *planned = *planned_ptr; + if (p->variant_used == -1) return 0; struct map_part **parts = get_map_parts(p); @@ -1550,10 +1552,8 @@ int get_overlap(struct placement *p) } struct placement **others; - bool *planned; - GARY_INIT_ZERO(planned, num_requests); - planned[p->request->ind] = 1; + planned[p->request->ind] = iteration; 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); @@ -1564,11 +1564,11 @@ int get_overlap(struct placement *p) struct map_placement *mp = parts[i]->placement->next_in_map; while (mp) { - if (! planned[mp->placement->request->ind]) + if (planned[mp->placement->request->ind] != iteration) { struct placement **p = GARY_PUSH(others); *p = mp->placement; - planned[mp->placement->request->ind] = true; + planned[mp->placement->request->ind] = iteration; } mp = mp->next_in_map; } @@ -1580,7 +1580,6 @@ int get_overlap(struct placement *p) overlap += overlaps(p, others[i]); } - GARY_FREE(planned); GARY_FREE(parts); GARY_FREE(others); @@ -1605,11 +1604,16 @@ int individual_overlap(struct individual *individual) { int overlap = 0; + int *planned; + GARY_INIT_ZERO(planned, GARY_SIZE(individual->placements)); + for (uns i=0; iplacements); i++) { - overlap += get_overlap(&individual->placements[i]); + overlap += get_overlap(&individual->placements[i], &planned, i+1); } + GARY_FREE(planned); + // printf("Total overlap is %d\n", overlap); return overlap;