* (c) 2022 Martin Mares <mj@ucw.cz>
*/
+#include "leo.h"
+
#include <ucw/lib.h>
#include <ucw/clists.h>
#include <ucw/mempool.h>
#include <stdio.h>
#include <math.h>
-#include "leo.h"
#include "osm.h"
#include "map.h"
#include "graph.h"
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));
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);
}