+ int penalty;
+
+ for (int i=0; i<conf_pop_size; i++)
+ {
+ if (dbg_rank)
+ printf("Individual %d\n", i);
+ population1[i]->penalty = 0;
+
+ penalty = individual_overlap(population1[i]);
+ if (dbg_rank)
+ printf("Increasing penalty by %d for overlap\n", penalty);
+ population1[i]->penalty += penalty;
+ }
+}
+
+struct map_part **get_map_parts(struct placement *p)
+{
+ if (p->variant_used < 0) return NULL;
+
+ struct map_part **buffer;
+ GARY_INIT(buffer, 0);
+
+ if (dbg_map_parts)
+ printf("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)
+ {
+ case REQUEST_POINT:
+ case REQUEST_SEGMENT:
+ case REQUEST_AREA:
+ v = p->request->variants[p->variant_used];
+ break;
+ default:
+ return NULL;
+ }
+
+ int x_min = max2(0, p->x) / conf_map_part_width;
+ int x_max = min2(page_width_int, (p->x + v.width + conf_map_part_width - 1)) / conf_map_part_width;
+ int y_min = max2(0, p->y) / conf_map_part_height;
+ int y_max = min2(page_height_int, (p->y + v.height + conf_map_part_height - 1)) / conf_map_part_height;
+
+ if (dbg_map_parts)
+ printf("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)
+ printf("Asking for %d of %u\n", y * num_map_parts_row + x, GARY_SIZE(p->individual->map));
+ *m = p->individual->map[y * num_map_parts_row + x];
+ }
+
+ return buffer;
+}
+
+void update_map_parts(struct placement *p)
+{
+ struct placement_link *ml = p->map_links;
+ while (ml)
+ {
+ struct map_placement *mp = ml->mp;
+
+ mp->prev->next = mp->next;
+ if (mp->next)
+ mp->next->prev = mp->prev;
+ free(mp);
+
+ struct placement_link *tmp = ml;
+ ml = ml->next;
+ free(tmp);
+ }
+ p->map_links = NULL;
+
+ struct map_part **parts = get_map_parts(p);
+ if (parts == NULL) return;
+
+ for (uns i=0; i<GARY_SIZE(parts); i++)
+ {
+ struct map_placement *mp = malloc(sizeof(struct map_placement));
+ mp->placement = p;
+
+ mp->next = parts[i]->placement->next;
+ mp->prev = parts[i]->placement;
+ parts[i]->placement->next = mp;
+ if (mp->next) mp->next->prev = mp;
+
+ struct placement_link *ml = malloc(sizeof(struct placement_link));
+ ml->mp = mp;
+ ml->next = p->map_links;
+ p->map_links = ml;
+ }
+
+ GARY_FREE(parts);