- // FIXME: default?
- }
-
- struct graph_edge *candidate = NULL;
- for (uns i=0; i<GARY_SIZE(other_node->edges); i++)
- {
- struct graph_edge *other = other_node->edges[i];
- if (! other->visited)
- {
- struct graph_edge **new = GARY_PUSH(bfs_queue);
- *new = other_node->edges[i];
- }
-
- if ((!other->visited) && (e->text) && (other->text) && (e->text->text == other->text->text))
- {
- if (e->color == other_node->edges[i]->color)
- {
- if ((!candidate) || (candidate->length < other->length))
- {
- candidate = other;
- }
- }
- else
- {
- // Beware: Name conflict here
- }
- }
- }
-
- if (candidate)
- {
- candidate->longline = e->longline;
- if (dir == 1)
- {
- if (candidate->n2 != e->n1)
- {
- candidate->n1 = candidate->n2;
- candidate->n2 = e->n1;
- }
- e->prev = candidate;
- candidate->next = e;
-
- longlines[e->longline].first = candidate;
- }
- else
- {
- if (candidate->n1 != e->n2)
- {
- candidate->n2 = candidate->n1;
- candidate->n1 = e->n2;
- }
- e->next = candidate;
- candidate->prev = e;
- }
- }
-}
-
-void bfs(void)
-{
- GARY_INIT(bfs_queue, 0);
- GARY_INIT(longlines, 0);
-
- HASH_FOR_ALL(hash, node)
- {
- for (uns i=0; i<GARY_SIZE(node->edges); i++)
- {
- struct graph_edge *e = node->edges[i];
-
-// printf("Examining edge from [%.2f; %.2f] to [%.2f; %.2f]\n",
-// e->n1->o->x, e->n1->o->y, e->n2->o->x, e->n2->o->y);
-
- // if (e->visited) HASH_CONTINUE; // FIXME: Is is correct?
- if (e->visited) continue;
-// printf("Continuing\n");
- if (e->longline == (uns) -1)
- {
- GARY_PUSH(longlines);
- e->longline = num_longlines++;
- longlines[e->longline].first = e;
- }
-// printf("Longline is %u\n", e->longline);
-
- e->visited = 1;
-
- if (! e->prev)
- {
- join_edge(e, 1);
- }
- if (! e->next)
- {
- join_edge(e, 2);
- }
- }
- }
- HASH_END_FOR;
-
- GARY_FREE(bfs_queue);
-}
-
-void make_segments(void)
-{
- for (uns i=0; i<GARY_SIZE(longlines); i++)
- {
- if (! longlines[i].first->text) continue;
-// printf("Survived! %s\n", osm_val_decode(longlines[i].first->text->text));
-printf("New longline\n");
- struct request_line *request = GARY_PUSH(requests_line);
- request->request.ind = -1;
- request->request.type = REQUEST_LINELABEL;
-
- GARY_INIT(request->segments, 0);
- request->num_segments = 0;
-
- // ->num_variants FIXME
- // ->variants FIXME
-
- struct graph_edge *e = longlines[i].first;
-
- if (! e) printf("Oops\n");
- num_requests++;
- while (e)
- {
- if (! e->text) break;
- struct request_segment *r = GARY_PUSH(request->segments);
- request->num_segments++;
-
- r->request.ind = num_requests++;
- r->request.type = REQUEST_SEGMENT;
-
- struct osm_node *n = e->n1->o;
- r->x1 = n->x;
- r->y1 = n->y;
- n = e->n2->o;
- r->x2 = n->x;
- r->y2 = n->y;
- r->k = abs(r->x2 - r->x1) / (abs(r->y2 - r->y1) + 0.001); // FIXME: Hack to prevent floating point exception when y2 = y1
-
-printf("Segment [%.2f; %.2f] -- [%.2f; %.2f]\n", r->x1, r->y1, r->x2, r->y2);
-
- r->sym = e->sym;
- r->zindex = e->zindex;
- r->text = malloc(sizeof(struct sym_text));
- *(r->text) = *(e->text);
- r->text->x = r->x1;
- r->text->y = r->y1;
-
- r->variant = malloc(sizeof(struct point_variant)); // FIXME
- make_bitmap_label(r->variant, e->text);
-
- e = e->next;
- }
- }
-}
-
-void labeller_label(void)
-{
- make_graph();
- label_graph();
- bfs();
- make_segments();
-
-printf("Having %u point requests, %u line requests and %u area requests\n", GARY_SIZE(requests_point), GARY_SIZE(requests_line), GARY_SIZE(requests_area));
-
- GARY_INIT(population1, conf_pop_size);
- GARY_INIT(population2, conf_pop_size);
- make_population();
-
- printf("Dealing with %d requests\n", num_requests);
-
- while (! shall_terminate())
- {
- iteration++;
-
- struct individual **swp = population1;
- population1 = population2;
- population2 = swp;
- pop2_ind = 0;
- }
-
- for (uns i=0; i<GARY_SIZE(population1[0]->placements); i++)
- {
- switch (population1[0]->placements[i].request->type)
- {
- case REQUEST_POINT: ;
- struct request_point *rp = (struct request_point *) population1[0]->placements[i].request;
- switch (rp->sym->type)
- {
- case SYMBOLIZER_POINT: ;
- struct sym_point *sp = (struct sym_point *) rp->sym;
- sp->x = i*10;
- sp->y = i*10;
- sym_plan((struct symbol *) sp, rp->zindex);
- break;
- case SYMBOLIZER_ICON: ;
- struct sym_icon *si = (struct sym_icon *) rp->sym;
- si->sir.x = population1[0]->placements[i].x;
- si->sir.y = population1[0]->placements[i].y;
- sym_plan((struct symbol *) si, rp->zindex);
- break;
- default:
- ;
- }
- break;
- case REQUEST_AREALABEL: ;
- struct request_area *ra = (struct request_area *) population1[0]->placements[i].request;
- sym_plan((struct symbol *) ra->sym, ra->zindex);
- break;
-
- case REQUEST_LINELABEL: ;
- struct request_line *rl = (struct request_line *) population1[0]->placements[i].request;
- for (uns j=0; j<GARY_SIZE(rl->segments); j++)
- {
- printf("Planning text %s to [%.2f; %.2f]\n", osm_val_decode(rl->segments[j].text->text), rl->segments[j].text->x, rl->segments[j].text->y);
- rl->segments[j].text->next_duplicate = NULL;
- rl->segments[j].text->next_in_tile = NULL;
- sym_plan((struct symbol *) rl->segments[j].text, rl->segments[j].zindex); // FIXME: z-index
- }
-
- }
- }
-
- return;
-
- while (! shall_terminate())
- {
- iteration++;
-
- breed();
- mutate();
- elite();
- rank_population();
- // sort population by fitness
-
- struct individual **swp = population1;
- population1 = population2;
- printf("Swapped populations\n");
- population2 = swp;
- // GARY_RESIZE(population2, 0) -- is it needed?
- pop2_ind = 0;
- }
-}
-
-void make_population(void)
-{
- for (int i=0; i<conf_pop_size; i++)
- {
- struct individual *individual = ep_alloc(ep_individuals); init_individual(individual);
- population1[i] = individual;
-
- int p = 0;
- for (uns j=0; j<GARY_SIZE(requests_point); j++)
- {
- init_placement(&(individual->placements[p++]), (struct request *) &requests_point[j]);
- }
- for (uns j=0; j<GARY_SIZE(requests_line); j++)
- {
- init_placement(&(individual->placements[p++]), (struct request *) &requests_line[j]);
- for (uns k=0; k<GARY_SIZE(requests_line[j].segments); k++)
- {
- init_placement(&(individual->placements[p++]), (struct request *) &requests_line[j].segments[k]);
- }
- }
- for (uns j=0; j<GARY_SIZE(requests_area); j++)
- {
- init_placement(&(individual->placements[p++]), (struct request *) &requests_area[j]);
- }
-
- ASSERT(p == num_requests);
- }
-}
-
-bool shall_terminate(void)
-{
- switch (conf_term_cond)
- {
- case TERM_COND_PENALTY:
- return (population1[0]->penalty < conf_penalty_bound);
- case TERM_COND_STAGNATION:
- return (abs(old_best - population1[0]->penalty) < conf_stagnation_bound);
- case TERM_COND_ITERATIONS:
- return (iteration >= conf_iteration_limit);