]> mj.ucw.cz Git - leo.git/commitdiff
Labelling: Let's truly support map parts and links to them
authorKarryanna <karry@karryanna.cz>
Tue, 12 May 2015 18:56:56 +0000 (20:56 +0200)
committerKarryanna <karry@karryanna.cz>
Tue, 12 May 2015 18:56:56 +0000 (20:56 +0200)
labeller.c
labeller.h

index 0942f073d826788166d232f13ae4842e19176e5e..5e82680e6648342ed180ca389ba834d2c924f16e 100644 (file)
@@ -90,6 +90,12 @@ int move_max = 1;
 
 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);
@@ -131,6 +137,9 @@ void gen_coords_point(struct placement *p);
 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);
@@ -165,6 +174,8 @@ int min2(int a, int b);
 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);
@@ -209,6 +220,10 @@ void labeller_init(void)
 
   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)
@@ -1235,6 +1250,89 @@ void rank_population(void)
   // 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)
@@ -1255,6 +1353,8 @@ void gen_coords(struct placement *p)
       printf("Testing request type\n");
       ASSERT(p->request->type != REQUEST_INVALID);
   }
+
+  update_map_parts(p);
 }
 
 double gen_movement(void)
@@ -1410,6 +1510,7 @@ void init_placement(struct placement *p, struct individual *individual, struct r
   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)
   {
@@ -1449,6 +1550,14 @@ void init_individual(struct individual *i)
 //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
 }
 
index 4e643dfbf67f28ca1e7593b727d467751848a2a9..d6f53ef60fb3ad0e3249956aed85fdfc086e0d78 100644 (file)
@@ -152,11 +152,28 @@ struct placement
   double y;
   int variant_used;
   bool processed;
+  // FIXME: Replace with clist?
+  struct placement_link *map_links;
   struct individual *individual;
 };
 
+struct placement_link
+{
+  struct map_placement *mp;
+  struct placement_link *next;
+};
+
+struct map_placement
+{
+  struct placement *placement;
+  struct map_placement *next;
+  struct map_placement *prev;
+};
+
 struct map_part
 {
+  // FIXME: Replace with clist?
+  struct map_placement *placement;
 };
 
 struct individual