131 lines
2.7 KiB
C
131 lines
2.7 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <getopt.h>
|
|
#include <glib.h>
|
|
|
|
#include "dijkstragraph.h"
|
|
#include "dijkstrasearch.h"
|
|
#include "dijkstraserv.h"
|
|
#include "geojson.h"
|
|
#include "logging.h"
|
|
|
|
struct dijkstra_node *start;
|
|
struct dijkstra_node *dest;
|
|
|
|
void add_test_map(struct dijkstra_solver *solver)
|
|
{
|
|
dijkstra_path_new_to_list(solver,
|
|
5,0,
|
|
5,10,
|
|
"Vertical",
|
|
1);
|
|
|
|
dijkstra_path_new_to_list(solver,
|
|
0,5,
|
|
10,5,
|
|
"Horizontal",
|
|
1);
|
|
}
|
|
|
|
void help(const char *exec)
|
|
{
|
|
fprintf(stderr,
|
|
"Usage: %s [OPTION] [FILE]...\n"
|
|
"Start the lifo-dijkstraserv routing server.\n\n"
|
|
" -s\tset output to silent\n"
|
|
" -v\tincrease verbosity. Maybe used multiple times.\n"
|
|
" -p\tport number (default 6802)\n",
|
|
exec);
|
|
}
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
int opt;
|
|
int i;
|
|
|
|
struct dijkstra_solver *solver;
|
|
|
|
GList *l = NULL;
|
|
struct dijkstra_node *node;
|
|
struct dijkstra_path *path;
|
|
|
|
int port = 6802;
|
|
struct dijkstra_serv *serv;
|
|
|
|
/* Init stuff */
|
|
set_log_level(LL_DEBUG);
|
|
|
|
/* Process arguments */
|
|
while((opt = getopt(argc, argv, "vsp")) != -1) {
|
|
switch(opt)
|
|
{
|
|
case 'v':
|
|
set_log_level(get_log_level() + 1);
|
|
break;
|
|
case 's':
|
|
set_log_level(0);
|
|
break;
|
|
case 'p':
|
|
port = atoi(argv[i]);
|
|
break;
|
|
case ':':
|
|
case '?':
|
|
help(argv[0]);
|
|
return 1;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (optind == argc) {
|
|
help(argv[0]);
|
|
return 1;
|
|
}
|
|
|
|
/* Generate solver */
|
|
solver = dijkstra_solver_new();
|
|
if (!solver) {
|
|
report(LL_CRITICAL, "Memory allocation failure.");
|
|
return 2;
|
|
}
|
|
|
|
/* Load map data -> Generate graph */
|
|
for (i = optind; i < argc; ++i) {
|
|
add_geojson_to_dijkstra(solver, argv[i]);
|
|
}
|
|
|
|
if (should_report(LL_NOISY)) {
|
|
for (l = solver->nodes; l != NULL; l = l->next) {
|
|
node = (struct dijkstra_node*) l->data;
|
|
fprintf(stderr, "Node %5d @%p: %f,\t%f [%d paths]\n", node->uid, node, node->position.x, node->position.y, g_list_length(node->paths));
|
|
}
|
|
printf("\n");
|
|
|
|
for (l = solver->paths; l != NULL; l = l->next) {
|
|
path = (struct dijkstra_path*) l->data;
|
|
fprintf(stderr, "Path %p: %5d (%f,%f) -> %5d (%f,%f) cost %d \t\"%s\"\n", path,
|
|
path->source->uid, path->source->position.x, path->source->position.y,
|
|
path->destination->uid, path->destination->position.x, path->destination->position.y,
|
|
path->weight,
|
|
path->name);
|
|
}
|
|
printf("\n");
|
|
}
|
|
|
|
report(LL_INFO, "Created graph with %d nodes and %d paths.",
|
|
g_list_length(solver->nodes),
|
|
g_list_length(solver->paths));
|
|
|
|
/* Start server */
|
|
serv = dijkstra_serv_new(solver, port);
|
|
if (!serv) {
|
|
dijkstra_solver_free(solver);
|
|
return -4;
|
|
}
|
|
dijkstra_serv_run(serv);
|
|
|
|
dijkstra_solver_free(solver);
|
|
|
|
return 0;
|
|
}
|