22 #include <grass/dgl/graph.h> 39 int count, last, cur, result, index, more;
58 if (count == 0 || cur != last) {
66 *lengths = (
int *)
G_calloc(count,
sizeof(
int));
67 *ids = (
int *)
G_calloc(count,
sizeof(
int));
68 if (!*lengths || !*ids) {
80 if (count != 0 && cur != last)
82 if (count == 0 || cur != last)
91 static int cmp_int(
const void *a,
const void *
b)
93 return *(
int *)a - *(
int *)
b;
114 int walk_layer,
char *route_id,
char *times,
115 char *to_stop,
char *walk_length,
119 int more, i, stop, route, time, *stop_pnt, stop1, stop2;
123 dbColumn *column1, *column2, *column3;
138 sprintf(buf,
"select %s from %s order by %s", route_id, Fi->
table,
144 if (timetable->
routes < 0)
147 sprintf(buf,
"select %s from %s order by %s", Fi->
key, Fi->
table,
152 if (timetable->
stops < 0)
172 for (i = 0; i < timetable->
routes; i++) {
185 for (i = 0; i < timetable->
stops; i++) {
198 sprintf(buf,
"select %s, %s, %s from %s order by %s", Fi->
key, route_id,
199 times, Fi->
table, times);
220 (
int *)bsearch(&stop, *stop_ids, timetable->
stops,
sizeof(
int),
221 cmp_int) - (*stop_ids);
223 (
int *)bsearch(&route, *route_ids, timetable->
routes,
sizeof(
int),
224 cmp_int) - (*route_ids);
235 if (walk_layer != -1) {
238 sprintf(buf,
"select %s, %s, %s from %s", Fi->
key, to_stop,
239 walk_length, Fi->
table);
244 G_warning(
_(
"Unable to open select cursor: %s"),
256 (
int *)bsearch(&stop, *stop_ids, timetable->
stops,
257 sizeof(
int), cmp_int);
262 (
int *)bsearch(&stop, *stop_ids, timetable->
stops,
263 sizeof(
int), cmp_int);
265 stop = stop_pnt - (*stop_ids);
272 for (i = 0; i < timetable->
stops; i++) {
286 G_warning(
_(
"Unable to open select cursor: %s"),
299 (
int *)bsearch(&stop, *stop_ids, timetable->
stops,
300 sizeof(
int), cmp_int);
302 stop2 = stop_pnt - (*stop_ids);
306 (
int *)bsearch(&stop, *stop_ids, timetable->
stops,
307 sizeof(
int), cmp_int);
309 stop1 = stop_pnt - (*stop_ids);
313 walk_length[stop1]] = stop2;
315 walk_length[stop1]++] = time;
332 static neta_heap_data *new_heap_data(
int conns,
int v)
335 (neta_heap_data *)
G_calloc(1,
sizeof(neta_heap_data));
356 int v,
int route,
int rows,
int update,
359 if (result->
dst[new_conns][to] == -1 ||
360 result->
dst[new_conns][to] > new_dst) {
361 result->
dst[new_conns][to] = new_dst;
364 result->
prev_conn[new_conns][to] = old_conns;
368 heap_data.
pv = (
void *)new_heap_data(new_conns, to);
393 int to_stop,
int start_time,
int min_change,
394 int max_changes,
int walking_change,
400 int opt_conns, rows = 1;
402 if (max_changes != -1)
403 rows = max_changes + 2;
406 result->
dst = (
int **)
G_calloc(rows,
sizeof(
int *));
417 for (i = 0; i < rows; i++) {
430 if (from_stop == to_stop) {
431 result->
dst[0][to_stop] = start_time;
438 if (walking_change > 1)
440 if (walking_change < 0 || max_changes == -1)
444 for (i = 0; i < rows; i++)
445 for (j = 0; j < timetable->
stops; j++)
449 result->
dst[0][from_stop] = start_time - min_change;
453 heap_data.
pv = (
void *)new_heap_data(0, from_stop);
459 int new_conns, walk_conns, update;
463 v = ((neta_heap_data *) (heap_node.
value.
pv))->v;
464 conns = ((neta_heap_data *) (heap_node.
value.
pv))->conns;
465 dist = heap_node.
key;
467 if (dist > result->
dst[conns][v])
471 new_conns = (max_changes == -1) ? 0 : (conns + 1);
472 walk_conns = conns + walking_change;
475 if (walk_conns < rows) {
480 int new_dst = dist + timetable->
walk_times[v][i];
483 rows, update, result, &heap);
487 if (new_conns >= rows)
491 if (timetable->
stop_times[v][i] >= dist + min_change) {
504 route, rows, 1, result, &heap);
510 for (i = 0; i < rows; i++)
511 if (result->
dst[i][to_stop] != -1 &&
513 result->
dst[opt_conns][to_stop] > result->
dst[i][to_stop]))
515 result->
routes = opt_conns;
518 return result->
dst[opt_conns][to_stop];
554 for (i = 0; i < result->
rows; i++) {
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
dbValue * db_get_column_value(dbColumn *)
Returns column value for given column structure.
void db_init_string(dbString *)
Initialize dbString.
int db_fetch(dbCursor *, int, int *)
Fetch data from open cursor.
int db_open_select_cursor(dbDriver *, dbString *, dbCursor *, int)
Open select cursor.
char * db_get_string(const dbString *)
Get string.
char * table
Name of DB table.
void dglHeapFree(dglHeap_s *pheap, dglHeapCancelItem_fn pfnCancelItem)
void G_free(void *)
Free allocated memory.
int db_get_value_int(dbValue *)
Get integer value.
dbDriver * db_start_driver_open_database(const char *, const char *)
Open driver/database connection.
void dglHeapInit(dglHeap_s *pheap)
int db_set_string(dbString *, const char *)
Inserts string to dbString (enlarge string)
int db_close_database_shutdown_driver(dbDriver *)
Close driver/database connection.
struct field_info * Vect_get_field(const struct Map_info *, int)
Get information about link to database (by layer number)
Layer (old: field) information.
const struct driver * driver
char * driver
Name of DB driver ('sqlite', 'dbf', ...)
void G_warning(const char *,...) __attribute__((format(printf
dbColumn * db_get_table_column(dbTable *, int)
Returns column structure for given table and column number.
dbTable * db_get_cursor_table(dbCursor *)
Get table allocated by cursor.
int dglHeapInsertMin(dglHeap_s *pheap, long key, unsigned char flags, dglHeapData_u value)
int dglHeapExtractMin(dglHeap_s *pheap, dglHeapNode_s *pnoderet)
int db_close_cursor(dbCursor *)
Close cursor.
char * key
Name of key column (usually 'cat')