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;
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);
}
}
+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; i<GARY_SIZE(parts); i++)
+ {
+ struct map_placement *mp = parts[i]->placement->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; i<GARY_SIZE(others); i++)
+ {
+ overlap += overlaps(p, others[i]);
+ }
+
+ GARY_FREE(planned);
+ GARY_FREE(parts);
+ GARY_FREE(others);
+
+ return overlap;
+}
+
+int individual_overlap(struct individual *individual)
+{
+ int overlap = 0;
+
+ for (uns i=0; i<GARY_SIZE(individual->placements); i++)
+ {
+ overlap += get_overlap(&individual->placements[i]);
+ }
+
+ return overlap;
+}
+
void rank_population(void)
{
// FIXME