int num_requests = 0;
+int conf_map_part_width = 5;
+int conf_map_part_height = 5;
+int num_map_parts_row;
+int num_map_parts_col;
+int num_map_parts;
+
void make_graph(void);
void label_graph(void);
void join_edge(struct graph_edge *e, int dir);
void gen_coords_segment(struct placement *p);
void gen_coords_area(struct placement *p);
+struct map_part **get_map_parts(struct placement *p);
+void update_map_parts(struct placement *p);
+
void make_segments_old(void);
void labeller_cleanup(void);
int max4(int a, int b, int c, int d);
int min4(int a, int b, int c, int d);
+struct placement dummy_placement;
+
int max2(int a, int b)
{
return (a > b ? a : b);
page_width_int = floor(page_width);
page_height_int = floor(page_height);
+
+ num_map_parts_row = (page_width_int + conf_map_part_width) / conf_map_part_width;
+ num_map_parts_col = (page_height_int + conf_map_part_height) / conf_map_part_height;
+ num_map_parts = num_map_parts_row * num_map_parts_col;
}
void make_bitmap(struct point_variant *v, struct symbol *sym)
// FIXME
}
+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 point_variant v;
+ switch (p->request->type)
+ {
+ case REQUEST_POINT:
+ v = ((struct request_point *) p->request)->variants[p->variant_used];
+ break;
+ case REQUEST_SEGMENT:
+ v = ((struct request_segment *) p->request)->variant[p->variant_used];
+ break;
+ case REQUEST_AREA:
+ v = ((struct request_area *) 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 = mp->next;
+ if (mp->next)
+ mp->next->prev = mp->prev;
+ free(mp);
+
+ struct placement_link *tmp = ml;
+ ml = ml->next;
+ free(tmp);
+ }
+
+ 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;
+ 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);
+}
+
void gen_coords(struct placement *p)
{
switch(p->request->type)
printf("Testing request type\n");
ASSERT(p->request->type != REQUEST_INVALID);
}
+
+ update_map_parts(p);
}
double gen_movement(void)
p->processed = 0;
p->x = p->y = 0; // To prevent valgrind from complaining
p->variant_used = 0;
+ p->map_links = NULL;
p->individual = individual;
switch (r->type)
{
//printf("Initing individual\n");
GARY_INIT(i->placements, num_requests);
GARY_INIT(i->map, 0);
+ for (uns j=0; j<num_map_parts; j++)
+ {
+ struct map_part *part = GARY_PUSH(i->map);
+ GARY_INIT(part->placement, 0);
+ struct map_placement *mp = GARY_PUSH(part->placement);
+ mp->placement = &dummy_placement;
+ mp->next = mp->prev = NULL;
+ }
i->penalty = 0; // FIXME
}