From: Martin Mares Date: Mon, 14 Mar 2022 15:11:38 +0000 (+0100) Subject: Průvodce: Identifying endpoints X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=b6cd4ac6f31faa85a0755ff0d5f6077d9b71aeaf;p=leo.git Průvodce: Identifying endpoints --- diff --git a/graph.c b/graph.c index 2b1c36a..f82f06a 100644 --- a/graph.c +++ b/graph.c @@ -4,6 +4,8 @@ * (c) 2022 Martin Mares */ +#include "leo.h" + #include #include #include @@ -11,7 +13,6 @@ #include #include -#include "leo.h" #include "osm.h" #include "map.h" #include "graph.h" @@ -50,6 +51,16 @@ static struct graph_vertex *graph_lookup_vertex(struct osm_node *n) return n->vertex; } +static struct graph_vertex *graph_vertex_by_node_id(osm_id_t id) +{ + struct osm_node *n = (struct osm_node *) osm_obj_find_by_id(OSM_TYPE_NODE, id); + if (!n) + die("Cannot find node #%jd", (uintmax_t) id); + ASSERT(n->vertex); + ASSERT(n->vertex->node); + return n->vertex; +} + static struct graph_edge *graph_add_edge(struct graph_vertex *u, struct graph_vertex *v, struct osm_way *way, double length) { struct graph_edge *e1 = mp_alloc_zero(graph_pool, sizeof(*e1)); @@ -141,14 +152,23 @@ void graph_build(void) graph_pool = mp_new(65536); clist_init(&graph_vertices); - CLIST_FOR_EACH(struct data_source *, ds, map_sources) - CLIST_FOR_EACH(struct osm_way *, w, ds->osm->obj_list[OSM_TYPE_WAY]) - { - if (way_is_edge(w)) - way_add_edge(w); - } + // We are considering only the first data source for the graph. + // Otherwise, things start becoming ugly, because node IDs are generally not unique. + + struct data_source *ds = clist_head(&map_sources); + ASSERT(ds); + osm_this = ds->osm; + CLIST_FOR_EACH(struct osm_way *, w, osm_this->obj_list[OSM_TYPE_WAY]) + { + if (way_is_edge(w)) + way_add_edge(w); + } msg(L_INFO, "Built road graph: %u vertices, %u edges", num_vertices, num_edges); graph_optimize(); msg(L_INFO, "Optimized road graph: %u vertices, %u edges", num_vertices, num_edges); + + struct graph_vertex *v1 = graph_vertex_by_node_id(32292698); // Praha-Zbraslav, K Přehradám + struct graph_vertex *v2 = graph_vertex_by_node_id(21289321); // Brno, HerÅ¡pická x OpuÅ¡těná + msg(L_INFO, "Finding path from #%jd to #%jd", (uintmax_t) v1->node->o.id, (uintmax_t) v2->node->o.id); }