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)
94 static int cmp_int(
const void *a,
const void *
b)
96 return *(
int *)a - *(
int *)
b;
117 int walk_layer,
char *route_id,
char *times,
118 char *to_stop,
char *walk_length,
122 int more, i, stop, route, time, *stop_pnt, stop1, stop2;
126 dbColumn *column1, *column2, *column3;
144 sprintf(buf,
"select %s from %s order by %s", route_id, Fi->
table,
149 if (timetable->
routes < 0)
152 sprintf(buf,
"select %s from %s order by %s", Fi->
key, Fi->
table, Fi->
key);
156 if (timetable->
stops < 0)
173 for (i = 0; i < timetable->
routes; i++) {
186 for (i = 0; i < timetable->
stops; i++) {
199 sprintf(buf,
"select %s, %s, %s from %s order by %s", Fi->
key, route_id,
200 times, Fi->
table, times);
219 stop = (
int *)bsearch(&stop, *stop_ids, timetable->
stops,
sizeof(
int),
222 route = (
int *)bsearch(&route, *route_ids, timetable->
routes,
223 sizeof(
int), cmp_int) -
234 if (walk_layer != -1) {
237 sprintf(buf,
"select %s, %s, %s from %s", Fi->
key, to_stop, walk_length,
243 G_warning(
_(
"Unable to open select cursor: %s"),
254 stop_pnt = (
int *)bsearch(&stop, *stop_ids, timetable->
stops,
255 sizeof(
int), cmp_int);
259 stop_pnt = (
int *)bsearch(&stop, *stop_ids, timetable->
stops,
260 sizeof(
int), cmp_int);
262 stop = stop_pnt - (*stop_ids);
269 for (i = 0; i < timetable->
stops; i++) {
283 G_warning(
_(
"Unable to open select cursor: %s"),
295 stop_pnt = (
int *)bsearch(&stop, *stop_ids, timetable->
stops,
296 sizeof(
int), cmp_int);
298 stop2 = stop_pnt - (*stop_ids);
301 stop_pnt = (
int *)bsearch(&stop, *stop_ids, timetable->
stops,
302 sizeof(
int), cmp_int);
304 stop1 = stop_pnt - (*stop_ids);
329 static neta_heap_data *new_heap_data(
int conns,
int v)
331 neta_heap_data *d = (neta_heap_data *)
G_calloc(1,
sizeof(neta_heap_data));
352 int v,
int route,
int rows
UNUSED,
int update,
355 if (result->
dst[new_conns][to] == -1 ||
356 result->
dst[new_conns][to] > new_dst) {
357 result->
dst[new_conns][to] = new_dst;
360 result->
prev_conn[new_conns][to] = old_conns;
364 heap_data.
pv = (
void *)new_heap_data(new_conns, to);
389 int to_stop,
int start_time,
int min_change,
390 int max_changes,
int walking_change,
396 int opt_conns, rows = 1;
398 if (max_changes != -1)
399 rows = max_changes + 2;
402 result->
dst = (
int **)
G_calloc(rows,
sizeof(
int *));
413 for (i = 0; i < rows; i++) {
425 if (from_stop == to_stop) {
426 result->
dst[0][to_stop] = start_time;
433 if (walking_change > 1)
435 if (walking_change < 0 || max_changes == -1)
439 for (i = 0; i < rows; i++)
440 for (j = 0; j < timetable->
stops; j++)
444 result->
dst[0][from_stop] = start_time - min_change;
448 heap_data.
pv = (
void *)new_heap_data(0, from_stop);
454 int new_conns, walk_conns, update;
458 v = ((neta_heap_data *)(heap_node.
value.
pv))->v;
459 conns = ((neta_heap_data *)(heap_node.
value.
pv))->conns;
460 dist = heap_node.
key;
462 if (dist > result->
dst[conns][v])
466 new_conns = (max_changes == -1) ? 0 : (conns + 1);
467 walk_conns = conns + walking_change;
470 if (walk_conns < rows) {
476 int new_dst = dist + timetable->
walk_times[v][i];
479 rows, update, result, &heap);
483 if (new_conns >= rows)
487 if (timetable->
stop_times[v][i] >= dist + min_change) {
500 route, rows, 1, result, &heap);
506 for (i = 0; i < rows; i++)
507 if (result->
dst[i][to_stop] != -1 &&
509 result->
dst[opt_conns][to_stop] > result->
dst[i][to_stop]))
511 result->
routes = opt_conns;
514 return result->
dst[opt_conns][to_stop];
550 for (i = 0; i < result->
rows; i++) {
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')