22 #include <grass/dgl/graph.h>
39 int count, last, cur, result, index, more;
58 if (
count == 0 || cur != last) {
68 if (!*lengths || !*ids) {
83 if (
count != 0 && cur != last)
85 if (
count == 0 || cur != last)
95 static int cmp_int(
const void *a,
const void *
b)
97 return *(
int *)a - *(
int *)
b;
118 int walk_layer,
char *route_id,
char *times,
119 char *to_stop,
char *walk_length,
123 int more, i, stop, route, time, *stop_pnt, stop1, stop2;
127 dbColumn *column1, *column2, *column3;
145 snprintf(buf,
sizeof(buf),
"select %s from %s order by %s", route_id,
146 Fi->
table, route_id);
150 if (timetable->
routes < 0)
153 snprintf(buf,
sizeof(buf),
"select %s from %s order by %s", Fi->
key,
158 if (timetable->
stops < 0)
175 for (i = 0; i < timetable->
routes; i++) {
188 for (i = 0; i < timetable->
stops; i++) {
201 snprintf(buf,
sizeof(buf),
"select %s, %s, %s from %s order by %s", Fi->
key,
202 route_id, times, Fi->
table, times);
221 stop = (
int *)bsearch(&stop, *stop_ids, timetable->
stops,
sizeof(
int),
224 route = (
int *)bsearch(&route, *route_ids, timetable->
routes,
225 sizeof(
int), cmp_int) -
236 if (walk_layer != -1) {
239 snprintf(buf,
sizeof(buf),
"select %s, %s, %s from %s", Fi->
key,
240 to_stop, walk_length, Fi->
table);
245 G_warning(
_(
"Unable to open select cursor: %s"),
256 stop_pnt = (
int *)bsearch(&stop, *stop_ids, timetable->
stops,
257 sizeof(
int), cmp_int);
261 stop_pnt = (
int *)bsearch(&stop, *stop_ids, timetable->
stops,
262 sizeof(
int), cmp_int);
264 stop = stop_pnt - (*stop_ids);
271 for (i = 0; i < timetable->
stops; i++) {
285 G_warning(
_(
"Unable to open select cursor: %s"),
297 stop_pnt = (
int *)bsearch(&stop, *stop_ids, timetable->
stops,
298 sizeof(
int), cmp_int);
300 stop2 = stop_pnt - (*stop_ids);
303 stop_pnt = (
int *)bsearch(&stop, *stop_ids, timetable->
stops,
304 sizeof(
int), cmp_int);
306 stop1 = stop_pnt - (*stop_ids);
331 static neta_heap_data *new_heap_data(
int conns,
int v)
333 neta_heap_data *d = (neta_heap_data *)
G_calloc(1,
sizeof(neta_heap_data));
354 int v,
int route,
int rows
UNUSED,
int update,
357 if (result->
dst[new_conns][to] == -1 ||
358 result->
dst[new_conns][to] > new_dst) {
359 result->
dst[new_conns][to] = new_dst;
362 result->
prev_conn[new_conns][to] = old_conns;
366 heap_data.
pv = (
void *)new_heap_data(new_conns, to);
391 int to_stop,
int start_time,
int min_change,
392 int max_changes,
int walking_change,
398 int opt_conns, rows = 1;
400 if (max_changes != -1)
401 rows = max_changes + 2;
404 result->
dst = (
int **)
G_calloc(rows,
sizeof(
int *));
415 for (i = 0; i < rows; i++) {
427 if (from_stop == to_stop) {
428 result->
dst[0][to_stop] = start_time;
435 if (walking_change > 1)
437 if (walking_change < 0 || max_changes == -1)
441 for (i = 0; i < rows; i++)
442 for (j = 0; j < timetable->
stops; j++)
446 result->
dst[0][from_stop] = start_time - min_change;
450 heap_data.
pv = (
void *)new_heap_data(0, from_stop);
456 int new_conns, walk_conns, update;
460 v = ((neta_heap_data *)(heap_node.
value.
pv))->v;
461 conns = ((neta_heap_data *)(heap_node.
value.
pv))->conns;
462 dist = heap_node.
key;
464 if (dist > result->
dst[conns][v])
468 new_conns = (max_changes == -1) ? 0 : (conns + 1);
469 walk_conns = conns + walking_change;
472 if (walk_conns < rows) {
478 int new_dst = dist + timetable->
walk_times[v][i];
481 rows, update, result, &heap);
485 if (new_conns >= rows)
489 if (timetable->
stop_times[v][i] >= dist + min_change) {
502 route, rows, 1, result, &heap);
508 for (i = 0; i < rows; i++)
509 if (result->
dst[i][to_stop] != -1 &&
511 result->
dst[opt_conns][to_stop] > result->
dst[i][to_stop]))
513 result->
routes = opt_conns;
516 return result->
dst[opt_conns][to_stop];
552 for (i = 0; i < result->
rows; i++) {
Main header of GRASS DataBase Management Interface.
dbValue * db_get_column_value(dbColumn *)
Returns column value for given column structure.
dbColumn * db_get_table_column(dbTable *, int)
Returns column structure for given table and column number.
dbDriver * db_start_driver_open_database(const char *, const char *)
Open driver/database connection.
dbTable * db_get_cursor_table(dbCursor *)
Get table allocated by cursor.
int db_close_database_shutdown_driver(dbDriver *)
Close driver/database connection.
int db_set_string(dbString *, const char *)
Inserts string to dbString (enlarge string)
int db_get_value_int(dbValue *)
Get integer value.
void db_init_string(dbString *)
Initialize dbString.
int db_close_cursor(dbCursor *)
Close cursor.
int db_open_select_cursor(dbDriver *, dbString *, dbCursor *, int)
Open select cursor.
char * db_get_string(const dbString *)
Get string.
int db_fetch(dbCursor *, int, int *)
Fetch data from open cursor.
void G_free(void *)
Free allocated memory.
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
void G_warning(const char *,...) __attribute__((format(printf
struct field_info * Vect_get_field(struct Map_info *, int)
Get information about link to database (by layer number)
void Vect_destroy_field_info(struct field_info *)
Free a struct field_info and all memory associated with it.
const struct driver * driver
#define UNUSED
A macro for an attribute, if attached to a variable, indicating that the variable is not used.
void dglHeapInit(dglHeap_s *pheap)
int dglHeapInsertMin(dglHeap_s *pheap, long key, unsigned char flags, dglHeapData_u value)
void dglHeapFree(dglHeap_s *pheap, dglHeapCancelItem_fn pfnCancelItem)
int dglHeapExtractMin(dglHeap_s *pheap, dglHeapNode_s *pnoderet)
Layer (old: field) information.
char * table
Name of DB table.
char * driver
Name of DB driver ('sqlite', 'dbf', ...)
char * key
Name of key column (usually 'cat')