]> mj.ucw.cz Git - leo.git/commitdiff
Labelling: A bunch of bug-fixes and debug prints
authorKarryanna <karry@karryanna.cz>
Wed, 8 Apr 2015 08:04:39 +0000 (10:04 +0200)
committerKarryanna <karry@karryanna.cz>
Wed, 8 Apr 2015 08:04:39 +0000 (10:04 +0200)
… still seg-faulting, though

labeller.c

index 7f74bbf8efb6f579705999b3d9af4a56c84b1699..f503154adf5165b2b866e64693862f23a7edb448 100644 (file)
@@ -69,6 +69,8 @@ int conf_part_size = 50;
 int move_min = 0;
 int move_max = 1;
 
+int num_requests = 0;
+
 void labeller_init(void)
 {
 //  mpool_requests = mp_new(BLOCK_SIZE);
@@ -112,6 +114,7 @@ void labeller_add_point(struct symbol *sym, struct osm_object *object, z_index_t
   r->sym = sym;
   r->object = object;
   r->zindex = zindex;
+  ((struct request *)r)->ind = num_requests++;
 
   struct osm_node *n = (struct osm_node *) object;
   r->x = n->x;
@@ -156,6 +159,7 @@ void labeller_add_arealabel(struct symbol *sym UNUSED, struct osm_object *o, z_i
   struct request_area *r = GARY_PUSH(requests_area);
   r->o = (struct osm_multipolygon *) o;
   r->zindex = zindex;
+  ((struct request *)r)->ind = num_requests++;
 }
 
 void make_graph(void)
@@ -254,7 +258,6 @@ void join_edge(struct graph_edge *e, int dir)
     struct graph_edge *other = other_node->edges[i];
     if (! other->visited)
     {
-    printf("Trying to add %dth edge\n", GARY_SIZE(bfs_queue)+1);
     struct graph_edge **new = GARY_PUSH(bfs_queue);
     *new = other_node->edges[i];
     }
@@ -328,7 +331,7 @@ void bfs(void)
       {
         GARY_PUSH(longlines);
         e->longline = num_longlines++;
-        longlines[num_longlines].first = e;
+        longlines[e->longline].first = e;
       }
 
       e->visited = 1;
@@ -357,6 +360,7 @@ void make_segments(void)
     struct request_line *request = GARY_PUSH(requests_line);
     GARY_INIT(request->segments, 0);
     struct graph_edge *e = longlines[i].first;
+    if (! e) printf("Oops\n");
     while (e)
     {
       struct request_segment *r = GARY_PUSH(request->segments);
@@ -366,8 +370,9 @@ void make_segments(void)
       r->x2 = ((struct osm_node *) e->n2)->x;
       r->y2 = ((struct osm_node *) e->n2)->y;
       r->sym = e->sym;
-      r->k = abs(r->x2 - r->x1) / abs(r->y2 - r->y1);
+      r->k = abs(r->x2 - r->x1) / (abs(r->y2 - r->y1) + 0.001); // FIXME: Hack to prevent floating point exception when y2 = y1
       r->variant = malloc(sizeof(struct point_variant)); // FIXME
+      ((struct request *)r)->ind = num_requests++;
       make_bitmap_label(r->variant, e->text);
 
       e = e->next;
@@ -444,12 +449,14 @@ void breed(void)
 {
   int acc = 0;
   int i=0;
-  int conf_breed_pop_size = conf_breed_pop_size_perc * conf_pop_size;
+  printf("%.2f\n", ((double) conf_breed_pop_size_perc/100));
+  int conf_breed_pop_size = ((double) conf_breed_pop_size_perc/100) * conf_pop_size;
   struct individual **breed_buffer;
   while (i < conf_breed_rbest_perc * conf_pop_size)
   {
     int parent1 = randint(1, conf_breed_pop_size);
     int parent2 = randint(1, conf_breed_pop_size);
+    printf("Will breed %d and %d, chosen of %d best of %d population (intended to be %d)\n", parent1, parent2, conf_breed_pop_size, GARY_SIZE(population1), conf_pop_size);
     breed_buffer = perform_crossover(population1[parent1], population1[parent2]);
     population2[2*i] = breed_buffer[0];
     population2[2*i+1] = breed_buffer[1];
@@ -475,9 +482,14 @@ struct individual **perform_crossover(struct individual *parent1, struct individ
   struct individual **buffer = malloc(2*sizeof(struct individual));
   struct individual *child1 = ep_alloc(ep_individuals);
   struct individual *child2 = ep_alloc(ep_individuals);
+  GARY_INIT(child1->placements, 0);
+  GARY_INIT(child2->placements, 0);
+
+  printf("Performing crossover\n");
 
   for (uns i=0; i<GARY_SIZE(parent1->placements); i++)
   {
+    printf("%dth placement\n", i);
     if (! parent1->placements[i].processed)
     {
       struct placement **clos_symbols;
@@ -495,6 +507,7 @@ struct individual **perform_crossover(struct individual *parent1, struct individ
         copy_symbols(clos_symbols, parent2, child1);
         copy_symbols(clos_symbols, parent1, child2);
       }
+      printf("%lld\n", GARY_SIZE(clos_symbols));
       GARY_FREE(clos_symbols);
     }
 
@@ -602,11 +615,14 @@ struct map_part **get_parts(struct placement *symbol, struct individual *individ
 int randint(int min, int max)
 {
   int r = random();
+  printf("Returning %d + (%d % (%d - %d)) = %d + %d % %d = %d + %d = %d\n", min, r, max, min, min, r, max-min, min, r%(max-min), min+(r%(max-min)));
+  return min + (r % (max - min));
   return (r * (max - min));
 }
 
 void get_closure(struct placement **closure UNUSED, struct placement *placement UNUSED, struct individual *parent1 UNUSED, struct individual *parent2 UNUSED)
 {
+  printf("Getting closure\n");
   bool *chosen = malloc(GARY_SIZE(parent1->placements) * sizeof(bool));
   chosen[placement->request->ind] = 1;
 
@@ -615,6 +631,7 @@ void get_closure(struct placement **closure UNUSED, struct placement *placement
   uns first = 0;
   while (first < GARY_SIZE(closure))
   {
+    printf("Iterating, first is %d\n", first);
     struct placement **overlapping = get_overlapping(placement);
     filter(overlapping, chosen);
     for (uns j=0; j<GARY_SIZE(overlapping); j++)
@@ -623,11 +640,13 @@ void get_closure(struct placement **closure UNUSED, struct placement *placement
       chosen[overlapping[j]->request->ind] = 1;
     }
     GARY_FREE(overlapping);
+    first++;
   }
 }
 
 void copy_symbols(struct placement **closure, struct individual *parent, struct individual *child)
 {
+  printf("%.2f\n", child->penalty);
   for (uns i=0; i<GARY_SIZE(closure); i++)
   {
     int ind = closure[i]->request->ind;
@@ -650,9 +669,11 @@ void move_symbol_point(struct placement *p)
   p->y += (double) (move_min + randdouble()) * flip(1, -1);
 }
 
-void init_placement(struct placement *p UNUSED, struct request *r UNUSED)
+void init_placement(struct placement *p, struct request *r)
 {
   // FIXME
+  p->request = r;
+  p->processed = 0;
 }
 
 struct placement **get_overlapping(struct placement *p UNUSED)