From 0d83da66b2afb75cc509ab88eca3073123d0914f Mon Sep 17 00:00:00 2001 From: Thomas Koch Date: Sun, 28 Dec 2014 23:28:42 +0100 Subject: [PATCH] Refactor stop to stoppoint --- cli.c | 28 +-- config.h | 6 +- router.c | 398 +++++++++++++++++++------------------- router.h | 30 +-- router_dump.c | 16 +- router_dump.h | 2 +- router_request.c | 110 +++++------ router_result.c | 83 ++++---- router_result.h | 8 +- rrrr_types.h | 26 +-- stubs.h | 2 +- tdata.c | 120 ++++++------ tdata.h | 58 +++--- tdata_io_v3.h | 24 +-- tdata_io_v3_dynamic.c | 36 ++-- tdata_io_v3_mmap.c | 12 +- tdata_realtime_alerts.c | 6 +- tdata_realtime_expanded.c | 152 +++++++-------- tdata_validation.c | 76 ++++---- 19 files changed, 597 insertions(+), 596 deletions(-) diff --git a/cli.c b/cli.c index 88dd466..3b496e0 100644 --- a/cli.c +++ b/cli.c @@ -52,7 +52,7 @@ static void set_add_jp (uint32_t *set, } #endif -#if RRRR_MAX_BANNED_STOPS > 0 || RRRR_MAX_BANNED_STOPS_HARD > 0 +#if RRRR_MAX_BANNED_STOP_POINTS > 0 || RRRR_MAX_BANNED_STOP_POINTS_HARD > 0 static void set_add_sp (spidx_t *set, uint8_t *length, uint8_t max_length, spidx_t value) { @@ -126,7 +126,7 @@ int main (int argc, char *argv[]) { #if RRRR_MAX_BANNED_JOURNEY_PATTERNS > 0 "[ --banned-jp-idx=idx ]\n" #endif -#if RRRR_MAX_BANNED_STOPS > 0 +#if RRRR_MAX_BANNED_STOP_POINTS > 0 "[ --banned-stop-idx=idx ]\n" #endif #if RRRR_MAX_BANNED_STOP_HARD > 0 @@ -200,7 +200,7 @@ int main (int argc, char *argv[]) { case 'f': if (strncmp(argv[i], "--from-idx=", 11) == 0) { - req.from = (uint32_t) strtol(&argv[i][11], NULL, 10); + req.from_stop_point = (uint32_t) strtol(&argv[i][11], NULL, 10); } #ifdef RRRR_FEATURE_LATLON else if (strncmp(argv[i], "--from-latlon=", 14) == 0) { @@ -236,7 +236,7 @@ int main (int argc, char *argv[]) { case 't': if (strncmp(argv[i], "--to-idx=", 9) == 0) { - req.to = (uint32_t) strtol(&argv[i][9], NULL, 10); + req.to_stop_point = (uint32_t) strtol(&argv[i][9], NULL, 10); } #ifdef RRRR_FEATURE_LATLON else if (strncmp(argv[i], "--to-latlon=", 12) == 0) { @@ -260,26 +260,26 @@ int main (int argc, char *argv[]) { } } #endif - #if RRRR_MAX_BANNED_STOPS > 0 + #if RRRR_MAX_BANNED_STOP_POINTS > 0 else if (strncmp(argv[i], "--banned-stop-idx=", 19) == 0) { uint32_t stop_idx = (uint32_t) strtol(&argv[i][19], NULL, 10); - if (stop_idx < tdata.n_stops) { + if (stop_idx < tdata.n_stop_points) { set_add_sp(req.banned_stops, &req.n_banned_stops, - RRRR_MAX_BANNED_STOPS, + RRRR_MAX_BANNED_STOP_POINTS, stop_idx); } } #endif - #if RRRR_MAX_BANNED_STOPS_HARD > 0 + #if RRRR_MAX_BANNED_STOP_POINTS_HARD > 0 else if (strncmp(argv[i], "--banned-stop-hard-idx=", 23) == 0) { uint32_t stop_idx = (uint32_t) strtol(&argv[i][23], NULL, 10); - if (stop_idx < tdata.n_stops) { - set_add_sp(req.banned_stops_hard, - &req.n_banned_stops_hard, - RRRR_MAX_BANNED_STOPS_HARD, + if (stop_idx < tdata.n_stop_points) { + set_add_sp(req.banned_stop_points_hard, + &req.n_banned_stop_points_hard, + RRRR_MAX_BANNED_STOP_POINTS_HARD, stop_idx); } } @@ -310,7 +310,7 @@ int main (int argc, char *argv[]) { cli_args.verbose = true; } else if (strncmp(argv[i], "--via=", 6) == 0) { - req.via = (uint32_t) strtol(&argv[i][6], NULL, 10); + req.via_stop_point = (uint32_t) strtol(&argv[i][6], NULL, 10); } #ifdef RRRR_FEATURE_LATLON else if (strncmp(argv[i], "--via-latlon=", 13) == 0) { @@ -343,7 +343,7 @@ int main (int argc, char *argv[]) { if (cli_args.gtfsrt_alerts_filename != NULL || cli_args.gtfsrt_tripupdates_filename != NULL) { - tdata.stopid_index = radixtree_load_strings_from_tdata (tdata.stop_ids, tdata.stop_ids_width, tdata.n_stops); + tdata.stopid_index = radixtree_load_strings_from_tdata (tdata.stop_point_ids, tdata.stop_point_ids_width, tdata.n_stop_points); tdata.vjid_index = radixtree_load_strings_from_tdata (tdata.vj_ids, tdata.vj_ids_width, tdata.n_vjs); tdata.lineid_index = radixtree_load_strings_from_tdata (tdata.line_ids, tdata.line_ids_width, tdata.n_journey_patterns); diff --git a/config.h b/config.h index 176e183..3cbd4bd 100644 --- a/config.h +++ b/config.h @@ -13,14 +13,14 @@ #define RRRR_DEFAULT_WALK_SPEED 1.5 /* Maximum distance in meters to travel by feet from the - * origin to the first stop, and from the last stop to + * origin to the first stop_point, and from the last stop_point to * the destination. */ #define RRRR_DEFAULT_WALK_MAX_DISTANCE 500 #define RRRR_MAX_BANNED_JOURNEY_PATTERNS 1 -#define RRRR_MAX_BANNED_STOPS 1 -#define RRRR_MAX_BANNED_STOPS_HARD 1 +#define RRRR_MAX_BANNED_STOP_POINTS 1 +#define RRRR_MAX_BANNED_STOP_POINTS_HARD 1 #define RRRR_MAX_BANNED_VEHICLE_JOURNEYS 1 #define RRRR_FEATURE_LATLON 1 diff --git a/router.c b/router.c index 2468138..2d761e3 100644 --- a/router.c +++ b/router.c @@ -24,19 +24,19 @@ #ifdef RRRR_FEATURE_LATLON static bool router_setup_hashgrid(router_t *router) { coord_t *coords; - uint32_t i_stop; + uint32_t i_sp; - coords = (coord_t *) malloc(sizeof(coord_t) * router->tdata->n_stops); + coords = (coord_t *) malloc(sizeof(coord_t) * router->tdata->n_stop_points); if (!coords) return false; - i_stop = router->tdata->n_stops; + i_sp = router->tdata->n_stop_points; do { - i_stop--; - coord_from_latlon(coords + i_stop, - router->tdata->stop_coords + i_stop); - } while(i_stop); + i_sp--; + coord_from_latlon(coords + i_sp, + router->tdata->stop_point_coords + i_sp); + } while(i_sp); - hashgrid_init (&router->hg, 100, 500.0, coords, router->tdata->n_stops); + hashgrid_init (&router->hg, 100, 500.0, coords, router->tdata->n_stop_points); free(coords); return true; @@ -44,9 +44,9 @@ static bool router_setup_hashgrid(router_t *router) { #endif bool router_setup(router_t *router, tdata_t *tdata) { - uint64_t n_states = tdata->n_stops * RRRR_DEFAULT_MAX_ROUNDS; + uint64_t n_states = tdata->n_stop_points * RRRR_DEFAULT_MAX_ROUNDS; router->tdata = tdata; - router->best_time = (rtime_t *) malloc(sizeof(rtime_t) * tdata->n_stops); + router->best_time = (rtime_t *) malloc(sizeof(rtime_t) * tdata->n_stop_points); router->states_back_journey_pattern = (uint32_t *) malloc(sizeof(uint32_t) * n_states); router->states_back_vehicle_journey = (uint32_t *) malloc(sizeof(uint32_t) * n_states); router->states_ride_from = (spidx_t *) malloc(sizeof(spidx_t) * n_states); @@ -60,8 +60,8 @@ bool router_setup(router_t *router, tdata_t *tdata) { router->states_journey_pattern_point = (uint16_t *) malloc(sizeof(uint16_t) * n_states); #endif - router->updated_stops = bitset_new(tdata->n_stops); - router->updated_walk_stops = bitset_new(tdata->n_stops); + router->updated_stop_points = bitset_new(tdata->n_stop_points); + router->updated_walk_stop_points = bitset_new(tdata->n_stop_points); router->updated_journey_patterns = bitset_new(tdata->n_journey_patterns); #if RRRR_BANNED_JOURNEY_PATTERNS_BITMASK == 1 @@ -80,8 +80,8 @@ bool router_setup(router_t *router, tdata_t *tdata) { && router->states_back_journey_pattern_point && router->states_journey_pattern_point #endif - && router->updated_stops - && router->updated_walk_stops + && router->updated_stop_points + && router->updated_walk_stop_points && router->updated_journey_patterns #if RRRR_BANNED_JOURNEY_PATTERNS_BITMASK == 1 && router->banned_journey_patterns @@ -112,8 +112,8 @@ void router_teardown(router_t *router) { free(router->states_back_journey_pattern_point); free(router->states_journey_pattern_point); #endif - bitset_destroy(router->updated_stops); - bitset_destroy(router->updated_walk_stops); + bitset_destroy(router->updated_stop_points); + bitset_destroy(router->updated_walk_stop_points); bitset_destroy(router->updated_journey_patterns); #if RRRR_BANNED_JOURNEY_PATTERNS_BITMASK == 1 @@ -129,20 +129,20 @@ void router_reset(router_t *router) { /* Make sure both origin and target are initialised with NONE, so it * becomes possible to validate that they have been set to a valid - * stop index. + * stop_point index. */ router->origin = STOP_NONE; router->target = STOP_NONE; - /* The best times to arrive at a stop scratch space is initialised with + /* The best times to arrive at a stop_point scratch space is initialised with * UNREACHED. This allows to compare for a lesser time candidate in the * search. */ - rrrr_memset (router->best_time, UNREACHED, router->tdata->n_stops); + rrrr_memset (router->best_time, UNREACHED, router->tdata->n_stop_points); } static bool initialize_states (router_t *router) { - uint64_t i_state = ((uint64_t) RRRR_DEFAULT_MAX_ROUNDS) * router->tdata->n_stops; + uint64_t i_state = ((uint64_t) RRRR_DEFAULT_MAX_ROUNDS) * router->tdata->n_stop_points; do { i_state--; @@ -237,12 +237,12 @@ static bool initialize_servicedays (router_t *router, router_request_t *req) { return true; } -/* Given a stop index, mark all journey_patterns that serve it as updated. */ -static void flag_journey_patterns_for_stop(router_t *router, router_request_t *req, - uint32_t stop_index) { +/* Given a stop_point index, mark all journey_patterns that serve it as updated. */ +static void flag_journey_patterns_for_stop_point(router_t *router, router_request_t *req, + uint32_t sp_index) { uint32_t *journey_patterns; - uint32_t i_jp = tdata_journey_patterns_for_stop(router->tdata, stop_index, - &journey_patterns); + uint32_t i_jp = tdata_journey_patterns_for_stop_point(router->tdata, sp_index, + &journey_patterns); if (i_jp == 0) return; @@ -252,8 +252,8 @@ static void flag_journey_patterns_for_stop(router_t *router, router_request_t *r i_jp--; #ifdef RRRR_INFO - fprintf (stderr, "flagging journey_pattern %d at stop %d\n", - journey_patterns[i_jp], stop_index); + fprintf (stderr, "flagging journey_pattern %d at stop_point %d\n", + journey_patterns[i_jp], sp_index); #endif jp_active_flags = router->tdata->journey_pattern_active[journey_patterns[i_jp]]; @@ -278,16 +278,16 @@ static void flag_journey_patterns_for_stop(router_t *router, router_request_t *r #ifdef RRRR_FEATURE_REALTIME_EXPANDED if (router->servicedays[1].apply_realtime && - router->tdata->rt_journey_patterns_at_stop[stop_index]) { - journey_patterns = router->tdata->rt_journey_patterns_at_stop[stop_index]->list; - i_jp = router->tdata->rt_journey_patterns_at_stop[stop_index]->len; + router->tdata->rt_journey_patterns_at_stop_point[sp_index]) { + journey_patterns = router->tdata->rt_journey_patterns_at_stop_point[sp_index]->list; + i_jp = router->tdata->rt_journey_patterns_at_stop_point[sp_index]->len; if (i_jp == 0) return; do { i_jp--; #ifdef RRRR_INFO - fprintf (stderr, " flagging changed journey_pattern %d at stop %d\n", - journey_patterns[i_jp], stop_index); + fprintf (stderr, " flagging changed journey_pattern %d at stop_point %d\n", + journey_patterns[i_jp], sp_index); #endif /* extra journey_patterns should only be applied on the current day */ if ((req->mode & router->tdata->journey_patterns[journey_patterns[i_jp]].attributes) > 0) { @@ -334,19 +334,19 @@ static void unflag_banned_journey_patterns(router_t *router, router_request_t *r #endif #endif -#if RRRR_MAX_BANNED_STOPS > 0 -static void unflag_banned_stops (router_t *router, router_request_t *req) { - uint8_t i_banned_stop = req->n_banned_stops; - if (i_banned_stop == 0) return; +#if RRRR_MAX_BANNED_STOP_POINTS > 0 +static void unflag_banned_stop_points(router_t *router, router_request_t *req) { + uint8_t i_banned_sp = req->n_banned_stops; + if (i_banned_sp == 0) return; do { - i_banned_stop--; - bitset_unset (router->updated_stops, - req->banned_stops[i_banned_stop]); - } while (i_banned_stop); + i_banned_sp--; + bitset_unset (router->updated_stop_points, + req->banned_stops[i_banned_sp]); + } while (i_banned_sp); } #endif -#if RRRR_MAX_BANNED_STOPS > 0 || RRRR_BAX_BANNED_STOPS_HARD > 0 +#if RRRR_MAX_BANNED_STOP_POINTS > 0 || RRRR_BAX_BANNED_STOPS_HARD > 0 static bool set_in (spidx_t *set, uint8_t length, spidx_t value) { uint8_t i = length; if (i == 0) return false; @@ -381,8 +381,8 @@ static bool set2_in (uint32_t *set1, uint16_t *set2, uint8_t length, * maintain a list of all the stops that might have been added by the hashgrid. */ static void initialize_transfers_full (router_t *router, uint32_t round) { - uint32_t i_state = router->tdata->n_stops; - rtime_t *states_walk_time = router->states_walk_time + (round * router->tdata->n_stops); + uint32_t i_state = router->tdata->n_stop_points; + rtime_t *states_walk_time = router->states_walk_time + (round * router->tdata->n_stop_points); do { i_state--; states_walk_time[i_state] = UNREACHED; @@ -399,18 +399,18 @@ static void initialize_transfers_full (router_t *router, uint32_t round) { * Alternatively we could instead initialize walks to UNREACHED at the * beginning of the transfer calculation function. * We should not however reset the best times for those stops reached from the - * initial stop on foot. This will prevent finding circuitous itineraries that + * initial stop_point on foot. This will prevent finding circuitous itineraries that * return to them. */ static void initialize_transfers (router_t *router, - uint32_t round, spidx_t stop_index_from) { - rtime_t *states_walk_time = router->states_walk_time + (round * router->tdata->n_stops); - uint32_t t = router->tdata->stops[stop_index_from ].transfers_offset; - uint32_t tN = router->tdata->stops[stop_index_from + 1].transfers_offset; - states_walk_time[stop_index_from] = UNREACHED; + uint32_t round, spidx_t sp_index_from) { + rtime_t *states_walk_time = router->states_walk_time + (round * router->tdata->n_stop_points); + uint32_t t = router->tdata->stop_points[sp_index_from ].transfers_offset; + uint32_t tN = router->tdata->stop_points[sp_index_from + 1].transfers_offset; + states_walk_time[sp_index_from] = UNREACHED; for ( ; t < tN ; ++t) { - spidx_t stop_index_to = router->tdata->transfer_target_stops[t]; - states_walk_time[stop_index_to] = UNREACHED; + spidx_t sp_index_to = router->tdata->transfer_target_stops[t]; + states_walk_time[sp_index_to] = UNREACHED; } } #endif @@ -435,7 +435,7 @@ tdata_stoptime (tdata_t* tdata, serviceday_t *serviceday, if (serviceday->apply_realtime) { /* the expanded stoptimes can be found at the same row as the vehicle_journey */ - vj_stoptimes = tdata->vj_stoptimes[tdata->journey_patterns[jp_index].vj_ids_offset + vj_offset]; + vj_stoptimes = tdata->vj_stoptimes[tdata->journey_patterns[jp_index].vj_offset + vj_offset]; if (vj_stoptimes) { /* if the expanded stoptimes have been added, @@ -467,7 +467,7 @@ tdata_stoptime (tdata_t* tdata, serviceday_t *serviceday, time_adjusted = time + serviceday->midnight; /* - printf ("boarding at stop %d, time is: %s \n", journey_pattern_point, timetext (time)); + printf ("boarding at stop_point %d, time is: %s \n", journey_pattern_point, timetext (time)); printf (" after adjusting: %s \n", timetext (time_adjusted)); printf (" midnight: %d \n", serviceday->midnight); */ @@ -484,13 +484,13 @@ tdata_stoptime (tdata_t* tdata, serviceday_t *serviceday, static bool tdata_next (router_t *router, router_request_t *req, uint32_t jp_index, uint32_t vj_offset, rtime_t qtime, - spidx_t *ret_stop_index, rtime_t *ret_stop_time) { + spidx_t *ret_sp_index, rtime_t *ret_stop_time) { spidx_t *journey_pattern_points = tdata_points_for_journey_pattern(router->tdata, jp_index); journey_pattern_t *jp = router->tdata->journey_patterns + jp_index; uint32_t jpp_i; - *ret_stop_index = STOP_NONE; + *ret_sp_index = STOP_NONE; *ret_stop_time = UNREACHED; for (jpp_i = 0; jpp_i < jp->n_stops; ++jpp_i) { @@ -499,97 +499,97 @@ tdata_next (router_t *router, router_request_t *req, rtime_t time = tdata_stoptime (router->tdata, &(router->servicedays[1]), jp_index, vj_offset, jpp_i, false); - /* Find stop immediately after the given time on the given vj. */ + /* Find stop_point immediately after the given time on the given vj. */ if (req->arrive_by ? time > qtime : time < qtime) { if (*ret_stop_time == UNREACHED || (req->arrive_by ? time < *ret_stop_time : time > *ret_stop_time)) { - *ret_stop_index = (spidx_t) journey_pattern_points[jpp_i]; + *ret_sp_index = (spidx_t) journey_pattern_points[jpp_i]; *ret_stop_time = time; } } } - return (*ret_stop_index != STOP_NONE); + return (*ret_sp_index != STOP_NONE); } -/* For each updated stop and each destination of a transfer from an updated - * stop, set the associated journey_patterns as updated. The journey_patterns bitset is cleared - * before the operation, and the stops bitset is cleared after all transfers +/* For each updated stop_point and each destination of a transfer from an updated + * stop_point, set the associated journey_patterns as updated. The journey_patterns bitset is cleared + * before the operation, and the stop_points bitset is cleared after all transfers * have been computed and all journey_patterns have been set. * Transfer results are computed within the same round, based on arrival time * in the ride phase and stored in the walk time member of states. */ static void apply_transfers (router_t *router, router_request_t *req, uint32_t round, bool transfer) { - rtime_t *states_time = router->states_time + (round * router->tdata->n_stops); - rtime_t *states_walk_time = router->states_walk_time + (round * router->tdata->n_stops); - spidx_t *states_walk_from = router->states_walk_from + (round * router->tdata->n_stops); - uint32_t stop_index_from; /* uint32_t: because we need to compare to BITSET_NONE */ + rtime_t *states_time = router->states_time + (round * router->tdata->n_stop_points); + rtime_t *states_walk_time = router->states_walk_time + (round * router->tdata->n_stop_points); + spidx_t *states_walk_from = router->states_walk_from + (round * router->tdata->n_stop_points); + uint32_t sp_index_from; /* uint32_t: because we need to compare to BITSET_NONE */ /* The transfer process will flag journey_patterns that should be explored in * the next round. */ bitset_clear (router->updated_journey_patterns); - for (stop_index_from = bitset_next_set_bit (router->updated_stops, 0); - stop_index_from != BITSET_NONE; - stop_index_from = bitset_next_set_bit (router->updated_stops, stop_index_from + 1)) { - rtime_t time_from = states_time[stop_index_from]; + for (sp_index_from = bitset_next_set_bit (router->updated_stop_points, 0); + sp_index_from != BITSET_NONE; + sp_index_from = bitset_next_set_bit (router->updated_stop_points, sp_index_from + 1)) { + rtime_t time_from = states_time[sp_index_from]; #ifdef RRRR_INFO - printf ("stop %d was marked as updated \n", stop_index_from); + printf ("stop_point %d was marked as updated \n", sp_index_from); #endif if (time_from == UNREACHED) { - fprintf (stderr, "ERROR: transferring from unreached stop %d in round %d. \n", stop_index_from, round); + fprintf (stderr, "ERROR: transferring from unreached stop_point %d in round %d. \n", sp_index_from, round); continue; } - /* At this point, the best time at the from stop may be different than + /* At this point, the best time at the from stop_point may be different than * the state_from->time, because the best time may have been updated * by a transfer. */ #ifdef RRRR_DEBUG - if (time_from != router->best_time[stop_index_from]) { + if (time_from != router->best_time[sp_index_from]) { char buf[13]; - fprintf (stderr, "ERROR: time at stop %d in round %d " \ + fprintf (stderr, "ERROR: time at stop_point %d in round %d " \ "is not the same as its best time. \n", - stop_index_from, round); + sp_index_from, round); fprintf (stderr, " from time %s \n", btimetext(time_from, buf)); fprintf (stderr, " walk time %s \n", - btimetext(states_walk_time[stop_index_from], buf)); + btimetext(states_walk_time[sp_index_from], buf)); fprintf (stderr, " best time %s \n", - btimetext(router->best_time[stop_index_from], buf)); + btimetext(router->best_time[sp_index_from], buf)); continue; } #endif #ifdef RRRR_INFO - fprintf (stderr, " applying transfer at %d (%s) \n", stop_index_from, - tdata_stop_name_for_index(router->tdata, stop_index_from)); + fprintf (stderr, " applying transfer at %d (%s) \n", sp_index_from, + tdata_stop_point_name_for_index(router->tdata, sp_index_from)); #endif - /* First apply a transfer from the stop to itself, + /* First apply a transfer from the stop_point to itself, * if case that's the best way. */ - if (states_time[stop_index_from] == router->best_time[stop_index_from]) { + if (states_time[sp_index_from] == router->best_time[sp_index_from]) { /* This state's best time is still its own. * No improvements from other transfers. */ - states_walk_time[stop_index_from] = time_from; - states_walk_from[stop_index_from] = (spidx_t) stop_index_from; - /* assert (router->best_time[stop_index_from] == time_from); */ - bitset_set(router->updated_walk_stops, stop_index_from); + states_walk_time[sp_index_from] = time_from; + states_walk_from[sp_index_from] = (spidx_t) sp_index_from; + /* assert (router->best_time[sp_index_from] == time_from); */ + bitset_set(router->updated_walk_stop_points, sp_index_from); } if (transfer) { - /* Then apply transfers from the stop to nearby stops */ - uint32_t tr = router->tdata->stops[stop_index_from ].transfers_offset; - uint32_t tr_end = router->tdata->stops[stop_index_from + 1].transfers_offset; + /* Then apply transfers from the stop_point to nearby stops */ + uint32_t tr = router->tdata->stop_points[sp_index_from].transfers_offset; + uint32_t tr_end = router->tdata->stop_points[sp_index_from + 1].transfers_offset; for ( ; tr < tr_end ; ++tr) { /* Transfer distances are stored in units of 16 meters, * rounded not truncated, in a uint8_t */ - spidx_t stop_index_to = router->tdata->transfer_target_stops[tr]; + spidx_t sp_index_to = router->tdata->transfer_target_stops[tr]; rtime_t transfer_duration = router->tdata->transfer_dist_meters[tr] + req->walk_slack; rtime_t time_to = req->arrive_by ? time_from - transfer_duration : time_from + transfer_duration; @@ -607,9 +607,9 @@ static void apply_transfers (router_t *router, router_request_t *req, { char buf[13]; fprintf (stderr, " target %d %s (%s) \n", - stop_index_to, - btimetext(router->best_time[stop_index_to], buf), - tdata_stop_name_for_index(router->tdata, stop_index_to)); + sp_index_to, + btimetext(router->best_time[sp_index_to], buf), + tdata_stop_point_name_for_index(router->tdata, sp_index_to)); fprintf (stderr, " transfer time %s\n", btimetext(transfer_duration, buf)); @@ -620,29 +620,29 @@ static void apply_transfers (router_t *router, router_request_t *req, #endif /* TODO verify state_to->walk_time versus - * router->best_time[stop_index_to] */ - if (router->best_time[stop_index_to] == UNREACHED || - (req->arrive_by ? time_to > router->best_time[stop_index_to] - : time_to < router->best_time[stop_index_to])) { + * router->best_time[sp_index_to] */ + if (router->best_time[sp_index_to] == UNREACHED || + (req->arrive_by ? time_to > router->best_time[sp_index_to] + : time_to < router->best_time[sp_index_to])) { #ifdef RRRR_INFO char buf[13]; fprintf (stderr, " setting %d to %s\n", - stop_index_to, btimetext(time_to, buf)); + sp_index_to, btimetext(time_to, buf)); #endif - states_walk_time[stop_index_to] = time_to; - states_walk_from[stop_index_to] = stop_index_from; - router->best_time[stop_index_to] = time_to; - bitset_set(router->updated_walk_stops, stop_index_to); + states_walk_time[sp_index_to] = time_to; + states_walk_from[sp_index_to] = sp_index_from; + router->best_time[sp_index_to] = time_to; + bitset_set(router->updated_walk_stop_points, sp_index_to); } } } } - for (stop_index_from = bitset_next_set_bit (router->updated_walk_stops, 0); - stop_index_from != BITSET_NONE; - stop_index_from = bitset_next_set_bit (router->updated_walk_stops, stop_index_from + 1)) { - flag_journey_patterns_for_stop(router, req, stop_index_from); + for (sp_index_from = bitset_next_set_bit (router->updated_walk_stop_points, 0); + sp_index_from != BITSET_NONE; + sp_index_from = bitset_next_set_bit (router->updated_walk_stop_points, sp_index_from + 1)) { + flag_journey_patterns_for_stop_point(router, req, sp_index_from); } #if RRRR_MAX_BANNED_JOURNEY_PATTERNS > 0 @@ -650,9 +650,9 @@ static void apply_transfers (router_t *router, router_request_t *req, #endif /* Done with all transfers, reset stop-reached bits for the next round */ - bitset_clear (router->updated_stops); - bitset_clear (router->updated_walk_stops); - /* Check invariant: Every stop reached in this round should have a + bitset_clear (router->updated_stop_points); + bitset_clear (router->updated_walk_stop_points); + /* Check invariant: Every stop_point reached in this round should have a * best time equal to its walk time, and * a walk arrival time <= its ride arrival time. */ @@ -755,11 +755,11 @@ static void search_vehicle_journeys_within_days(router_t *router, router_request static bool write_state(router_t *router, router_request_t *req, uint8_t round, uint32_t jpp_index, uint32_t vj_offset, - spidx_t stop_index, uint16_t jpp_offset, rtime_t time, + spidx_t sp_index, uint16_t jpp_offset, rtime_t time, spidx_t board_stop, uint16_t board_jpp_stop, rtime_t board_time) { - uint64_t i_state = ((uint64_t) round) * router->tdata->n_stops + stop_index; + uint64_t i_state = ((uint64_t) round) * router->tdata->n_stop_points + sp_index; #ifndef RRRR_REALTIME UNUSED (jpp_offset); @@ -769,11 +769,11 @@ write_state(router_t *router, router_request_t *req, #ifdef RRRR_INFO { char buf[13]; - fprintf(stderr, " setting stop to %s \n", btimetext(time, buf)); + fprintf(stderr, " setting stop_point to %s \n", btimetext(time, buf)); } #endif - router->best_time[stop_index] = time; + router->best_time[sp_index] = time; router->states_time[i_state] = time; router->states_back_journey_pattern[i_state] = jpp_index; router->states_back_vehicle_journey[i_state] = vj_offset; @@ -799,20 +799,20 @@ write_state(router_t *router, router_request_t *req, static void router_round(router_t *router, router_request_t *req, uint8_t round) { /* TODO restrict pointers? */ - rtime_t *states_walk_time = router->states_walk_time + (((round == 0) ? 1 : round - 1) * router->tdata->n_stops); + rtime_t *states_walk_time = router->states_walk_time + (((round == 0) ? 1 : round - 1) * router->tdata->n_stop_points); uint32_t jp_index; #ifdef RRRR_INFO fprintf(stderr, "round %d\n", round); #endif - /* Iterate over all journey_patterns which contain a stop that was updated in the last round. */ + /* Iterate over all journey_patterns which contain a stop_point that was updated in the last round. */ for (jp_index = bitset_next_set_bit (router->updated_journey_patterns, 0); jp_index != BITSET_NONE; jp_index = bitset_next_set_bit (router->updated_journey_patterns, jp_index + 1)) { journey_pattern_t *jp = &(router->tdata->journey_patterns[jp_index]); spidx_t *journey_pattern_points = tdata_points_for_journey_pattern(router->tdata, jp_index); - uint8_t *journey_pattern_point_attributes = tdata_stop_attributes_for_journey_pattern(router->tdata, jp_index); + uint8_t *journey_pattern_point_attributes = tdata_stop_point_attributes_for_journey_pattern(router->tdata, jp_index); /* Service day on which that vj was boarded */ serviceday_t *board_serviceday = NULL; @@ -820,8 +820,8 @@ static void router_round(router_t *router, router_request_t *req, uint8_t round) /* vj index within the route. NONE means not yet boarded. */ uint32_t vj_index = NONE; - /* stop index where that vj was boarded */ - spidx_t board_stop = 0; + /* stop_point index where that vj was boarded */ + spidx_t board_sp = 0; /* journey_pattern_point index where that vj was boarded */ uint16_t board_jpp = 0; @@ -830,8 +830,8 @@ static void router_round(router_t *router, router_request_t *req, uint8_t round) rtime_t board_time = 0; - /* Iterate over stop indexes within the route. Each one corresponds to - * a global stop index. Note that the stop times array should be + /* Iterate over stop_point indexes within the route. Each one corresponds to + * a global stop_point index. Note that the stop times array should be * accessed with [vj_index][jpp_index] not [vj_index][jpp_index]. * * The iteration variable is signed to allow ending the iteration at @@ -862,7 +862,7 @@ static void router_round(router_t *router, router_request_t *req, uint8_t round) req->arrive_by ? --jpp_index : ++jpp_index) { - uint32_t stop_index = journey_pattern_points[jpp_index]; + uint32_t sp_index = journey_pattern_points[jpp_index]; rtime_t prev_time; bool attempt_board = false; bool forboarding = (journey_pattern_point_attributes[jpp_index] & rsa_boarding); @@ -870,13 +870,13 @@ static void router_round(router_t *router, router_request_t *req, uint8_t round) #ifdef RRRR_INFO char buf[13]; - fprintf(stderr, " stop %2d [%d] %c%c %s %s\n", jpp_index, - stop_index, + fprintf(stderr, " sp %2d [%d] %c%c %s %s\n", jpp_index, + sp_index, forboarding ? 'B' : ' ', foralighting ? 'A' : ' ', - btimetext(router->best_time[stop_index], buf), - tdata_stop_name_for_index (router->tdata, - stop_index)); + btimetext(router->best_time[sp_index], buf), + tdata_stop_point_name_for_index (router->tdata, + sp_index)); #endif if (vj_index != NONE && @@ -895,14 +895,14 @@ static void router_round(router_t *router, router_request_t *req, uint8_t round) continue; } - #if RRRR_MAX_BANNED_STOPS_HARD > 0 - /* If a stop in in banned_stops_hard, we do not want to transit + #if RRRR_MAX_BANNED_STOP_POINTS_HARD > 0 + /* If a stop_point in in banned_stop_points_hard, we do not want to transit * through this stationwe reset the current vj to NONE and skip * the currect stop. This effectively splits the journey_pattern in two, * and forces a re-board afterwards. */ - if (set_in (req->banned_stops_hard, req->n_banned_stops_hard, - stop_index)) { + if (set_in (req->banned_stop_points_hard, req->n_banned_stop_points_hard, + sp_index)) { vj_index = NONE; continue; } @@ -912,14 +912,14 @@ static void router_round(router_t *router, router_request_t *req, uint8_t round) * a better vj on this journey_pattern at this location, indicate that we * want to search for a vj. */ - prev_time = states_walk_time[stop_index]; + prev_time = states_walk_time[sp_index]; /* Only board at placed that have been reached. */ if (prev_time != UNREACHED) { - if (vj_index == NONE || req->via == stop_index) { + if (vj_index == NONE || req->via_stop_point == sp_index) { attempt_board = true; - } else if (vj_index != NONE && req->via != STOP_NONE && - req->via == board_stop) { + } else if (vj_index != NONE && req->via_stop_point != STOP_NONE && + req->via_stop_point == board_sp) { attempt_board = false; } else { /* removed xfer slack for simplicity */ @@ -945,7 +945,7 @@ static void router_round(router_t *router, router_request_t *req, uint8_t round) } } /* If we have not yet boarded a vj on this route, see if we can - * board one. Also handle the case where we hit a stop with an + * board one. Also handle the case where we hit a stop_point with an * existing better arrival time. */ if (attempt_board) { @@ -959,8 +959,8 @@ static void router_round(router_t *router, router_request_t *req, uint8_t round) rtime_t best_time = (rtime_t) (req->arrive_by ? 0 : UNREACHED); #ifdef RRRR_INFO - fprintf (stderr, " attempting boarding at stop %d\n", - stop_index); + fprintf (stderr, " attempting boarding at stop_point %d\n", + sp_index); #endif #ifdef RRRR_TDATA tdata_dump_journey_pattern(router->tdata, jp_index, NONE); @@ -978,14 +978,14 @@ static void router_round(router_t *router, router_request_t *req, uint8_t round) #endif if ((req->arrive_by ? best_time > req->time : best_time < req->time) && - req->from != ONBOARD) { + req->from_stop_point != ONBOARD) { fprintf(stderr, "ERROR: boarded before start time, " - "vj %d stop %d \n", - best_vj, stop_index); + "vj %d stop_point %d \n", + best_vj, sp_index); } else { /* TODO: use a router_state struct for all this? */ board_time = best_time; - board_stop = stop_index; + board_sp = sp_index; board_jpp = (uint16_t) jpp_index; board_serviceday = best_serviceday; vj_index = best_vj; @@ -995,7 +995,7 @@ static void router_round(router_t *router, router_request_t *req, uint8_t round) fprintf(stderr, " no suitable vj to board.\n"); #endif } - continue; /* to the next stop in the journey_pattern */ + continue; /* to the next stop_point in the journey_pattern */ /* We have already boarded a vehicle_journey along this journey_pattern. */ } else if (vj_index != NONE) { @@ -1035,9 +1035,9 @@ static void router_round(router_t *router, router_request_t *req, uint8_t round) * Yes, because the best time may not have been found in the * previous round. */ - if (!((router->best_time[stop_index] == UNREACHED) || - (req->arrive_by ? time > router->best_time[stop_index] - : time < router->best_time[stop_index]))) { + if (!((router->best_time[sp_index] == UNREACHED) || + (req->arrive_by ? time > router->best_time[sp_index] + : time < router->best_time[sp_index]))) { #ifdef RRRR_INFO fprintf(stderr, " (no improvement)\n"); #endif @@ -1060,26 +1060,26 @@ static void router_round(router_t *router, router_request_t *req, uint8_t round) #ifdef RRRR_DEBUG fprintf(stderr, "ERROR: setting state to time before" \ - "start time. journey_pattern %d vj %d stop %d \n", - jp_index, vj_index, stop_index); + "start time. journey_pattern %d vj %d stop_point %d \n", + jp_index, vj_index, sp_index); #endif } else { write_state(router, req, round, jp_index, vj_index, - stop_index, (uint16_t) jpp_index, time, - board_stop, board_jpp, board_time); + sp_index, (uint16_t) jpp_index, time, + board_sp, board_jpp, board_time); - /* mark stop for next round. */ - bitset_set(router->updated_stops, stop_index); + /* mark stop_point for next round. */ + bitset_set(router->updated_stop_points, sp_index); } } - } /* end for (stop_index) */ + } /* end for (sp_index) */ } /* end for (route) */ - #if RRRR_MAX_BANNED_STOPS > 0 + #if RRRR_MAX_BANNED_STOP_POINTS > 0 /* Remove the banned stops from the bitset, * so no transfers will happen there. */ - unflag_banned_stops(router, req); + unflag_banned_stop_points(router, req); #endif /* Also updates the list of journey_patterns for next round @@ -1110,34 +1110,34 @@ static bool initialize_origin_onboard (router_t *router, router_request_t *req) /* We cannot expand the start vj into the temporary round (1) * during initialization because we may be able to reach the * destination on that starting vj. - * We discover the previous stop and flag only the selected journey_pattern + * We discover the previous stop_point and flag only the selected journey_pattern * for exploration in round 0. This would interfere with search * reversal, but reversal is meaningless/useless in on-board * depart vehicle_journeys anyway. */ - spidx_t stop_index; + spidx_t sp_index; rtime_t stop_time; if (tdata_next (router, req, req->onboard_vj_journey_pattern, req->onboard_journey_pattern_offset, - req->time, &stop_index, &stop_time) ){ + req->time, &sp_index, &stop_time) ){ uint64_t i_state; - req->from = ONBOARD; + req->from_stop_point = ONBOARD; /* Initialize the origin */ - router->origin = stop_index; + router->origin = sp_index; router->best_time[router->origin] = stop_time; - /* Set the origin stop in the "2nd round" */ - i_state = router->tdata->n_stops + router->origin; + /* Set the origin stop_point in the "2nd round" */ + i_state = router->tdata->n_stop_points + router->origin; router->states_time[i_state] = stop_time; router->states_walk_time[i_state] = stop_time; /* When starting on board, only flag one journey_pattern and * do not apply transfers, only a single walk. */ - bitset_clear (router->updated_stops); + bitset_clear (router->updated_stop_points); bitset_clear (router->updated_journey_patterns); bitset_set (router->updated_journey_patterns, req->onboard_vj_journey_pattern); @@ -1150,7 +1150,7 @@ static bool initialize_origin_onboard (router_t *router, router_request_t *req) static bool initialize_origin_index (router_t *router, router_request_t *req) { uint32_t i_state; - router->origin = (req->arrive_by ? req->to : req->from); + router->origin = (req->arrive_by ? req->to_stop_point : req->from_stop_point); if (router->origin == STOP_NONE) return false; @@ -1161,17 +1161,17 @@ static bool initialize_origin_index (router_t *router, router_request_t *req) { * structs. eliminate this now that we have rtimes in requests. */ router->states_time[router->origin] = req->time; - bitset_clear(router->updated_stops); + bitset_clear(router->updated_stop_points); /* This is inefficient, as it depends on iterating over * a bitset with only one bit true. */ - bitset_set(router->updated_stops, router->origin); + bitset_set(router->updated_stop_points, router->origin); /* We will use round 1 to hold the initial state for round 0. * Round 1 must then be re-initialized before use. */ - i_state = router->tdata->n_stops + router->origin; + i_state = router->tdata->n_stop_points + router->origin; router->states_time[i_state] = req->time; /* the rest of these should be unnecessary */ @@ -1189,51 +1189,51 @@ static bool initialize_origin_index (router_t *router, router_request_t *req) { } static bool initialize_target_index (router_t *router, router_request_t *req) { - router->target = (req->arrive_by ? req->from : req->to); + router->target = (req->arrive_by ? req->from_stop_point : req->to_stop_point); return (router->target != STOP_NONE); } #ifdef RRRR_FEATURE_LATLON -static bool latlon_best_stop_index(router_t *router, router_request_t *req, - hashgrid_result_t *hg_result) { +static bool latlon_best_stop_point_index(router_t *router, router_request_t *req, + hashgrid_result_t *hg_result) { double distance, best_distance = INFINITY; - uint32_t stop_index, best_stop_index = HASHGRID_NONE; + uint32_t sp_index, best_sp_index = HASHGRID_NONE; hashgrid_result_reset(hg_result); - stop_index = hashgrid_result_next_filtered(hg_result, &distance); + sp_index = hashgrid_result_next_filtered(hg_result, &distance); - while (stop_index != HASHGRID_NONE) { + while (sp_index != HASHGRID_NONE) { uint32_t i_state; rtime_t extra_walktime; /* TODO: this is terrible. For each result we explicitly remove if it * is banned. While banning doesn't happen that often a more elegant * way would be to just overwrite the state and best_time. - * Sadly that might not give us an accurate best_stop_index. + * Sadly that might not give us an accurate best_sp_index. */ - #if RRRR_MAX_BANNED_STOPS > 0 - /* if a stop is banned, we should not act upon it here */ + #if RRRR_MAX_BANNED_STOP_POINTS > 0 + /* if a stop_point is banned, we should not act upon it here */ if (set_in (req->banned_stops, req->n_banned_stops, - stop_index)) continue; + sp_index)) continue; #endif - #if RRRR_MAX_BANNED_STOPS_HARD > 0 - /* if a stop is banned hard, we should not act upon it here */ - if (set_in (req->banned_stops_hard, req->n_banned_stops_hard, - stop_index)) continue; + #if RRRR_MAX_BANNED_STOP_POINTS_HARD > 0 + /* if a stop_point is banned hard, we should not act upon it here */ + if (set_in (req->banned_stop_points_hard, req->n_banned_stop_points_hard, + sp_index)) continue; #endif - i_state = router->tdata->n_stops + stop_index; + i_state = router->tdata->n_stop_points + sp_index; extra_walktime = SEC_TO_RTIME((uint32_t)((distance * RRRR_WALK_COMP) / req->walk_speed)); if (req->arrive_by) { - router->best_time[stop_index] = req->time - extra_walktime; + router->best_time[sp_index] = req->time - extra_walktime; router->states_time[i_state] = req->time - extra_walktime; } else { - router->best_time[stop_index] = req->time + extra_walktime; + router->best_time[sp_index] = req->time + extra_walktime; router->states_time[i_state] = req->time + extra_walktime; } @@ -1243,26 +1243,26 @@ static bool latlon_best_stop_index(router_t *router, router_request_t *req, router->states_back_vehicle_journey[i_state] = NONE; router->states_board_time[i_state] = UNREACHED; - bitset_set(router->updated_stops, stop_index); + bitset_set(router->updated_stop_points, sp_index); if (distance < best_distance) { best_distance = distance; - best_stop_index = stop_index; + best_sp_index = sp_index; } #ifdef RRRR_INFO fprintf (stderr, "%d %s %s (%.0fm)\n", - stop_index, - tdata_stop_id_for_index(router->tdata, stop_index), - tdata_stop_name_for_index(router->tdata, stop_index), + sp_index, + tdata_stop_point_id_for_index(router->tdata, sp_index), + tdata_stop_point_name_for_index(router->tdata, sp_index), distance); #endif - /* get the next potential start stop */ - stop_index = hashgrid_result_next_filtered(hg_result, &distance); + /* get the next potential start stop_point */ + sp_index = hashgrid_result_next_filtered(hg_result, &distance); } - router->origin = best_stop_index; + router->origin = best_sp_index; if (router->origin == STOP_NONE) return false; @@ -1287,7 +1287,7 @@ static bool initialize_origin_latlon (router_t *router, router_request_t *req) { hashgrid_query (&router->hg, &req->to_hg_result, coord, req->walk_max_distance); } - return latlon_best_stop_index (router, req, &req->to_hg_result); + return latlon_best_stop_point_index(router, req, &req->to_hg_result); } else { if (req->from_latlon.lat == 0.0 && req->from_latlon.lon == 0.0) { @@ -1300,7 +1300,7 @@ static bool initialize_origin_latlon (router_t *router, router_request_t *req) { hashgrid_query (&router->hg, &req->from_hg_result, coord, req->walk_max_distance); } - return latlon_best_stop_index (router, req, &req->from_hg_result); + return latlon_best_stop_point_index(router, req, &req->from_hg_result); } return false; @@ -1350,10 +1350,10 @@ static bool initialize_origin (router_t *router, router_request_t *req) { * 1) from/to a station, req->from and/or req->to are filled * 2) from/to a coordinate, req->from_coord and/or req->to_coord are filled * - * Given 0, we calculate the previous stop from an existing running vj + * Given 0, we calculate the previous stop_point from an existing running vj * and determine the best way to the destination. * - * Given 1, the user is actually at a stop and wants to leave from there, + * Given 1, the user is actually at a stop_point and wants to leave from there, * in the second round transfers are applied which may move the user by * feet to a different stop. We consider the origin and destination as * constraint, explicitly enforced by the user. @@ -1364,7 +1364,7 @@ static bool initialize_origin (router_t *router, router_request_t *req) { * configurable by the user. The first forward search starts from all * found locations. Based on the distance, a weight factor and the * walk-speed an extra time calculated and encounted for. - * A normal search will match up to the stop which is the closest to the + * A normal search will match up to the stop_point which is the closest to the * destination. * TODO: We store all possible paths from the forward search to all * possible destinations. @@ -1396,9 +1396,9 @@ static bool initialize_origin (router_t *router, router_request_t *req) { /* In the first two searches the LATLON search will find the best * values for req->to and req->from the final interation have both * set to the walk optimum. For the geographic optimisation to start - * a latlon must be set and the stop_index must be set to NONE. + * a latlon must be set and the stop_point_index must be set to NONE. */ - if (req->to == STOP_NONE || req->from == STOP_NONE) { + if (req->to_stop_point == STOP_NONE || req->from_stop_point == STOP_NONE) { /* search the target based on latlon */ return initialize_origin_latlon (router, req); } else @@ -1414,10 +1414,10 @@ static bool initialize_target (router_t *router, router_request_t *req) { /* In the first two searches the LATLON search will find the best * values for req->to and req->from the final interation have both * set to the walk optimum. For the geographic optimisation to start - * a latlon must be set and the stop_index must be set to NONE. + * a latlon must be set and the stop_point_index must be set to NONE. */ #ifdef RRRR_FEATURE_LATLON - if (req->to == STOP_NONE || req->from == STOP_NONE) { + if (req->to_stop_point == STOP_NONE || req->from_stop_point == STOP_NONE) { /* search the target based on latlon */ return initialize_target_latlon (router, req); } else diff --git a/router.h b/router.h index 13c7f60..8c7ec59 100644 --- a/router.h +++ b/router.h @@ -15,14 +15,14 @@ #include #include -/* When associated with a stop index, +/* When associated with a stop_point index, * a router_state_t describes a leg of an itinerary. */ /* We could potentially remove the back_time from router_state, * but this requires implementing some lookup functions and storing - * the back_vj_stop rather than the back_stop (global stop index): - * a vehicle_journey can pass through a stop more than once. + * the back_vj_stop_point rather than the back_stop_point (global stop_point index): + * a vehicle_journey can pass through a stop_point more than once. */ /* Scratch space for use by the routing algorithm. @@ -33,29 +33,29 @@ struct router { /* The transit / timetable data tables */ tdata_t *tdata; - /* The best known time at each stop */ + /* The best known time at each stop_point */ rtime_t *best_time; - /* The index of the journey_pattern used to travel from back_stop to here, or WALK */ + /* The index of the journey_pattern used to travel from back_stop_point to here, or WALK */ uint32_t *states_back_journey_pattern; - /* The index of the vehicle_journey used to travel from back_stop */ + /* The index of the vehicle_journey used to travel from back_stop_point */ uint32_t *states_back_vehicle_journey; - /* The index of the previous stop in the itinerary */ + /* The index of the previous stop_point in the itinerary */ spidx_t *states_ride_from; /* Second phase footpath/transfer results */ - /* The stop from which this stop was reached by walking (2nd phase) */ + /* The stop_point from which this stop_point was reached by walking (2nd phase) */ spidx_t *states_walk_from; /* Second phase footpath/transfer results */ - /* The time when this stop was reached by walking (2nd phase) */ + /* The time when this stop_point was reached by walking (2nd phase) */ rtime_t *states_walk_time; - /* The time when this stop was reached */ + /* The time when this stop_point was reached */ rtime_t *states_time; - /* The time at which the vehicle_journey within back_journey_pattern left back_stop */ + /* The time at which the vehicle_journey within back_journey_pattern left back_stop_point */ rtime_t *states_board_time; #ifdef RRRR_FEATURE_REALTIME_EXPANDED @@ -63,14 +63,14 @@ struct router { uint16_t *states_journey_pattern_point; #endif - /* Used to track which stops improved during each round */ - bitset_t *updated_stops; + /* Used to track which stop_points improved during each round */ + bitset_t *updated_stop_points; /* Used to track which journey_patterns might have changed during each round */ bitset_t *updated_journey_patterns; - /* Used to track to which stops we changed the walk_time during each round */ - bitset_t *updated_walk_stops; + /* Used to track to which stop_points we changed the walk_time during each round */ + bitset_t *updated_walk_stop_points; #ifdef RRRR_BANNED_JOURNEY_PATTERNS_BITMASK /* Used to ban journey_patterns and in the final clockwise search optimise */ diff --git a/router_dump.c b/router_dump.c index 9f1f433..fe5224b 100644 --- a/router_dump.c +++ b/router_dump.c @@ -11,7 +11,7 @@ void router_state_dump (router_t *router, uint64_t i_state) { char walk_time[13], time[13], board_time[13]; fprintf (stderr, "-- Router State --\n" "walk time: %s\n" - "walk from: %d\n" + "walk from_stop_point: %d\n" "time: %s\n" "board time: %s\n" "back route: ", @@ -27,7 +27,7 @@ void router_state_dump (router_t *router, uint64_t i_state) { } void dump_results(router_t *router) { - spidx_t i_stop; + spidx_t i_sp; uint8_t i_round; #if 0 char id_fmt[10]; @@ -45,20 +45,20 @@ void dump_results(router_t *router) { } fprintf(stderr, "\n"); - for (i_stop = 0; i_stop < router->tdata->n_stops; ++i_stop) { + for (i_sp = 0; i_sp < router->tdata->n_stop_points; ++i_sp) { const char *stop_id; char time[13], walk_time[13]; /* filter out stops which will not be reached */ - if (router->best_time[i_stop] == UNREACHED) continue; + if (router->best_time[i_sp] == UNREACHED) continue; - stop_id = tdata_stop_name_for_index (router->tdata, i_stop); + stop_id = tdata_stop_point_name_for_index(router->tdata, i_sp); fprintf(stderr, id_fmt, stop_id); - fprintf(stderr, " [%6d]", i_stop); + fprintf(stderr, " [%6d]", i_sp); for (i_round = 0; i_round < RRRR_DEFAULT_MAX_ROUNDS; ++i_round) { fprintf(stderr, " %8s %8s", - btimetext(router->states_time[i_round * router->tdata->n_stops + i_stop], time), - btimetext(router->states_walk_time[i_round * router->tdata->n_stops + i_stop], walk_time)); + btimetext(router->states_time[i_round * router->tdata->n_stop_points + i_sp], time), + btimetext(router->states_walk_time[i_round * router->tdata->n_stop_points + i_sp], walk_time)); } fprintf(stderr, "\n"); } diff --git a/router_dump.h b/router_dump.h index 0e6c6c2..6548e54 100644 --- a/router_dump.h +++ b/router_dump.h @@ -15,7 +15,7 @@ #include #include "config.h" void router_state_dump (router_t *router, uint64_t i_state); -bool stop_is_reached(router_t *router, uint32_t stop_index); +bool stop_is_reached(router_t *router, uint32_t sp_index); void dump_results(router_t *router); void day_mask_dump (uint32_t mask); void service_day_dump (struct service_day *sd); diff --git a/router_request.c b/router_request.c index 7b732ee..7f2e6f6 100644 --- a/router_request.c +++ b/router_request.c @@ -53,7 +53,7 @@ void router_request_initialize(router_request_t *req) { req->walk_speed = RRRR_DEFAULT_WALK_SPEED; req->walk_slack = RRRR_DEFAULT_WALK_SLACK; req->walk_max_distance = RRRR_DEFAULT_WALK_MAX_DISTANCE; - req->from = req->to = req->via = STOP_NONE; + req->from_stop_point = req->to_stop_point = req->via_stop_point = STOP_NONE; req->time = UNREACHED; req->time_cutoff = UNREACHED; req->arrive_by = true; @@ -67,13 +67,13 @@ void router_request_initialize(router_request_t *req) { req->n_banned_journey_patterns = 0; rrrr_memset (req->banned_journey_patterns, NONE, RRRR_MAX_BANNED_JOURNEY_PATTERNS); #endif - #if RRRR_MAX_BANNED_STOPS > 0 + #if RRRR_MAX_BANNED_STOP_POINTS > 0 req->n_banned_stops = 0; - rrrr_memset (req->banned_stops, STOP_NONE, RRRR_MAX_BANNED_STOPS); + rrrr_memset (req->banned_stops, STOP_NONE, RRRR_MAX_BANNED_STOP_POINTS); #endif - #if RRRR_MAX_BANNED_STOPS_HARD > 0 - req->n_banned_stops_hard = 0; - rrrr_memset (req->banned_stops_hard, STOP_NONE, RRRR_MAX_BANNED_STOPS_HARD); + #if RRRR_MAX_BANNED_STOP_POINTS_HARD > 0 + req->n_banned_stop_points_hard = 0; + rrrr_memset (req->banned_stop_points_hard, STOP_NONE, RRRR_MAX_BANNED_STOP_POINTS_HARD); #endif #if RRRR_MAX_BANNED_VEHICLE_JOURNEYS > 0 req->n_banned_vjs = 0; @@ -132,7 +132,7 @@ void router_request_randomize (router_request_t *req, tdata_t *tdata) { req->walk_slack = RRRR_DEFAULT_WALK_SLACK; req->walk_max_distance = RRRR_DEFAULT_WALK_MAX_DISTANCE; req->time = RTIME_ONE_DAY + SEC_TO_RTIME(3600 * 9 + rrrrandom(3600 * 12)); - req->via = STOP_NONE; + req->via_stop_point = STOP_NONE; req->time_cutoff = UNREACHED; /* 0 or 1 */ req->arrive_by = (bool) rrrrandom(2); @@ -145,13 +145,13 @@ void router_request_randomize (router_request_t *req, tdata_t *tdata) { req->n_banned_journey_patterns = 0; rrrr_memset (req->banned_journey_patterns, NONE, RRRR_MAX_BANNED_JOURNEY_PATTERNS); #endif - #if RRRR_MAX_BANNED_STOPS > 0 + #if RRRR_MAX_BANNED_STOP_POINTS > 0 req->n_banned_stops = 0; - rrrr_memset (req->banned_stops, STOP_NONE, RRRR_MAX_BANNED_STOPS); + rrrr_memset (req->banned_stops, STOP_NONE, RRRR_MAX_BANNED_STOP_POINTS); #endif - #if RRRR_MAX_BANNED_STOPS_HARD > 0 - req->n_banned_stops_hard = 0; - rrrr_memset (req->banned_stops_hard, STOP_NONE, RRRR_MAX_BANNED_STOPS_HARD); + #if RRRR_MAX_BANNED_STOP_POINTS_HARD > 0 + req->n_banned_stop_points_hard = 0; + rrrr_memset (req->banned_stop_points_hard, STOP_NONE, RRRR_MAX_BANNED_STOP_POINTS_HARD); #endif #if RRRR_MAX_BANNED_VEHICLE_JOURNEYS > 0 req->n_banned_vjs = 0; @@ -159,14 +159,14 @@ void router_request_randomize (router_request_t *req, tdata_t *tdata) { rrrr_memset (req->banned_vjs_offset, 0, RRRR_MAX_BANNED_VEHICLE_JOURNEYS); #endif req->intermediatestops = false; - req->from = rrrrandom(tdata->n_stops); - req->to = rrrrandom(tdata->n_stops); + req->from_stop_point = (spidx_t) rrrrandom(tdata->n_stop_points); + req->to_stop_point = (spidx_t) rrrrandom(tdata->n_stop_points); #ifdef RRRR_FEATURE_LATLON - req->from_latlon = tdata->stop_coords[rrrrandom(tdata->n_stops)]; - req->to_latlon = tdata->stop_coords[rrrrandom(tdata->n_stops)]; - req->from = STOP_NONE; - req->to = STOP_NONE; + req->from_latlon = tdata->stop_point_coords[rrrrandom(tdata->n_stop_points)]; + req->to_latlon = tdata->stop_point_coords[rrrrandom(tdata->n_stop_points)]; + req->from_stop_point = STOP_NONE; + req->to_stop_point = STOP_NONE; #endif #ifdef RRRR_FEATURE_AGENCY_FILTER @@ -197,7 +197,7 @@ void router_request_next(router_request_t *req, rtime_t inc) { */ bool router_request_reverse(router_t *router, router_request_t *req) { uint32_t max_transfers = req->max_transfers; - uint32_t best_stop_index = HASHGRID_NONE; + uint32_t best_sp_index = HASHGRID_NONE; uint8_t round = UINT8_MAX; /* range-check to keep search within states array */ @@ -205,9 +205,9 @@ bool router_request_reverse(router_t *router, router_request_t *req) { max_transfers = RRRR_DEFAULT_MAX_ROUNDS - 1; #ifdef RRRR_FEATURE_LATLON - if ((req->arrive_by ? req->from == STOP_NONE : req->to == STOP_NONE)) { + if ((req->arrive_by ? req->from_stop_point == STOP_NONE : req->to_stop_point == STOP_NONE)) { hashgrid_result_t *hg_result; - uint32_t stop_index; + uint32_t sp_index; double distance; rtime_t best_time = (rtime_t) (req->arrive_by ? 0 : UNREACHED); @@ -223,63 +223,63 @@ bool router_request_reverse(router_t *router, router_request_t *req) { fprintf (stderr, "Reversal - Hashgrid results:\n"); #endif - stop_index = hashgrid_result_next_filtered(hg_result, &distance); + sp_index = hashgrid_result_next_filtered(hg_result, &distance); - while (stop_index != HASHGRID_NONE) { + while (sp_index != HASHGRID_NONE) { rtime_t extra_walktime = 0; - if (router->best_time[stop_index] != UNREACHED) { + if (router->best_time[sp_index] != UNREACHED) { extra_walktime = SEC_TO_RTIME((uint32_t)((distance * RRRR_WALK_COMP) / req->walk_speed)); if (req->arrive_by) { - router->best_time[stop_index] -= extra_walktime; - if (router->best_time[stop_index] > best_time) { - best_stop_index = stop_index; - best_time = router->best_time[stop_index]; + router->best_time[sp_index] -= extra_walktime; + if (router->best_time[sp_index] > best_time) { + best_sp_index = sp_index; + best_time = router->best_time[sp_index]; } } else { - router->best_time[stop_index] += extra_walktime; - if (router->best_time[stop_index] < best_time) { - best_stop_index = stop_index; - best_time = router->best_time[stop_index]; + router->best_time[sp_index] += extra_walktime; + if (router->best_time[sp_index] < best_time) { + best_sp_index = sp_index; + best_time = router->best_time[sp_index]; } } } #ifdef RRRR_DEBUG - fprintf (stderr, "%d %s %s (%.0fm) %d %d\n", stop_index, - tdata_stop_id_for_index(router->tdata, stop_index), - tdata_stop_name_for_index(router->tdata, stop_index), - distance, router->best_time[stop_index], extra_walktime); + fprintf (stderr, "%d %s %s (%.0fm) %d %d\n", sp_index, + tdata_stop_point_id_for_index(router->tdata, sp_index), + tdata_stop_point_name_for_index(router->tdata, sp_index), + distance, router->best_time[sp_index], extra_walktime); #endif - /* get the next potential start stop */ - stop_index = hashgrid_result_next_filtered(hg_result, &distance); + /* get the next potential start stop_point */ + sp_index = hashgrid_result_next_filtered(hg_result, &distance); } if (req->arrive_by) { - req->from = (spidx_t) best_stop_index; + req->from_stop_point = (spidx_t) best_sp_index; } else { - req->to = (spidx_t) best_stop_index; + req->to_stop_point = (spidx_t) best_sp_index; } - /* TODO: Ideally we should implement a o_transfers option here to find the stop that requires the + /* TODO: Ideally we should implement a o_transfers option here to find the stop_point that requires the * least transfers and is the best with respect to arrival time. This might be a different stop - * than the stop that is the best with most transfers. + * than the stop_point that is the best with most transfers. */ } else #endif { - best_stop_index = (req->arrive_by ? req->from : req->to); + best_sp_index = (req->arrive_by ? req->from_stop_point : req->to_stop_point); } { /* find the solution with the most transfers and the earliest arrival */ uint8_t r; for (r = 0; r <= max_transfers; ++r) { - if (router->states_walk_time[r * router->tdata->n_stops + best_stop_index] != UNREACHED) { + if (router->states_walk_time[r * router->tdata->n_stop_points + best_sp_index] != UNREACHED) { round = r; /* Instead of the earliest arrival (most transfers) * use the solution with the least transfers. @@ -293,11 +293,11 @@ bool router_request_reverse(router_t *router, router_request_t *req) { if (round == UINT8_MAX) return false; req->time_cutoff = req->time; - req->time = router->states_walk_time[round * router->tdata->n_stops + - best_stop_index]; + req->time = router->states_walk_time[round * router->tdata->n_stop_points + + best_sp_index]; #if 0 fprintf (stderr, "State present at round %d \n", round); - router_state_dump (router, round * router->tdata->n_stops + stop); + router_state_dump (router, round * router->tdata->n_stop_points + sp_index); #endif req->max_transfers = round; req->arrive_by = !(req->arrive_by); @@ -347,20 +347,20 @@ time_t req_to_epoch (router_request_t *req, tdata_t *tdata, struct tm *tm_out) { * Indexes larger than array lengths for the given router, signed values less than zero, etc. * can and will cause segfaults and present security risks. * - * We could also infer departure stop etc. from start vehicle_journey here, "missing start point" and reversal problems. + * We could also infer departure stop_point etc. from start vehicle_journey here, "missing start point" and reversal problems. */ bool range_check(router_request_t *req, tdata_t *tdata) { return !(req->walk_speed < 0.1 || - req->from >= tdata->n_stops || - req->to >= tdata->n_stops + req->from_stop_point >= tdata->n_stop_points || + req->to_stop_point >= tdata->n_stop_points ); } /* router_request_dump prints the current request structure to the screen */ void router_request_dump(router_request_t *req, tdata_t *tdata) { - const char *from_stop_id = tdata_stop_name_for_index(tdata, req->from); - const char *to_stop_id = tdata_stop_name_for_index(tdata, req->to); + const char *from_stop_id = tdata_stop_point_name_for_index(tdata, req->from_stop_point); + const char *to_stop_id = tdata_stop_point_name_for_index(tdata, req->to_stop_point); char time[32], time_cutoff[32], date[11]; struct tm ltm; @@ -370,8 +370,8 @@ void router_request_dump(router_request_t *req, tdata_t *tdata) { btimetext(req->time, time); btimetext(req->time_cutoff, time_cutoff); printf("-- Router Request --\n" - "from: %s [%d]\n" - "to: %s [%d]\n" + "from_stop_point: %s [%d]\n" + "to_stop_point: %s [%d]\n" "date: %s\n" "time: %s [%d]\n" "speed: %f m/sec\n" @@ -379,7 +379,7 @@ void router_request_dump(router_request_t *req, tdata_t *tdata) { "max xfers: %d\n" "max time: %s\n" "mode: ", - from_stop_id, req->from, to_stop_id, req->to, date, time, + from_stop_id, req->from_stop_point, to_stop_id, req->to_stop_point, date, time, req->time, req->walk_speed, (req->arrive_by ? "true" : "false"), req->max_transfers, time_cutoff); diff --git a/router_result.c b/router_result.c index 44e0f2a..4a9b365 100644 --- a/router_result.c +++ b/router_result.c @@ -6,15 +6,15 @@ /* Reverse the times and stops in a leg. Used for creating arrive-by itineraries. */ static void leg_swap (leg_t *leg) { struct leg temp = *leg; - leg->s0 = temp.s1; - leg->s1 = temp.s0; + leg->sp_from = temp.sp_to; + leg->sp_to = temp.sp_from; leg->t0 = temp.t1; leg->t1 = temp.t0; } /* Checks charateristics that should be the same for all vj plans produced by this router: All stops should chain, all times should be increasing, all waits should be at the ends of walk legs, etc. - Returns true if any of the checks fail, false if no problems are detected. */ + Returns true if any of the checks fail, false if no problems are detected. f*/ static bool check_plan_invariants (plan_t *plan) { uint8_t i_itinerary; bool fail = false; @@ -45,11 +45,11 @@ static bool check_plan_invariants (plan_t *plan) { prev_target_time = target_time; prev_itin = itin; /* Check that itinerary does indeed connect the places in the request. */ - if (leg0->s0 != plan->req.from) { + if (leg0->sp_from != plan->req.from_stop_point) { fprintf(stderr, "itinerary does not begin at from location.\n"); fail = true; } - if (legN->s1 != plan->req.to) { + if (legN->sp_to != plan->req.to_stop_point) { fprintf(stderr, "itinerary does not end at to location.\n"); fail = true; } @@ -85,8 +85,8 @@ static bool check_plan_invariants (plan_t *plan) { fail = true; } if (i_leg > 0) { - if (leg->s0 != prev_leg->s1) { - fprintf(stderr, "legs do not chain: leg %d begins with stop %d, previous leg ends with stop %d.\n", i_leg, leg->s0, prev_leg->s1); + if (leg->sp_from != prev_leg->sp_to) { + fprintf(stderr, "legs do not chain: leg %d begins with stop_point %d, previous leg ends with stop_point %d.\n", i_leg, leg->sp_from, prev_leg->sp_to); fail = true; } if (leg->journey_pattern == WALK && leg->t0 != prev_leg->t1) { @@ -112,8 +112,8 @@ static bool check_plan_invariants (plan_t *plan) { bool router_result_to_plan (struct plan *plan, router_t *router, router_request_t *req) { itinerary_t *itin; uint8_t i_transfer; - /* Router states are a 2D array of stride n_stops */ - /* router_state_t (*states)[n_stops] = (router_state_t(*)[]) router->states; */ + /* Router states are a 2D array of stride n_stop_points */ + /* router_state_t (*states)[n_stop_points] = (router_state_t(*)[]) router->states; */ plan->n_itineraries = 0; plan->req = *req; /* copy the request into the plan for use in rendering */ itin = plan->itineraries; @@ -122,10 +122,10 @@ bool router_result_to_plan (struct plan *plan, router_t *router, router_request_ /* Work backward from the target to the origin */ uint64_t i_state; leg_t *l = itin->legs; /* the slot in which record a leg, reversing them for forward vehicle_journey's */ - uint32_t stop = router->target; /* Work backward from the target to the origin */ + spidx_t sp_index = router->target; /* Work backward from the target to the origin */ int16_t j_transfer; /* signed int because we will be decreasing */ - i_state = (i_transfer * router->tdata->n_stops) + stop; + i_state = (i_transfer * router->tdata->n_stop_points) + sp_index; /* skip rounds that were not reached */ if (router->states_walk_time[i_state] == UNREACHED) continue; @@ -135,36 +135,37 @@ bool router_result_to_plan (struct plan *plan, router_t *router, router_request_ /* Follow the chain of states backward */ for (j_transfer = i_transfer; j_transfer >= 0; --j_transfer) { uint64_t i_walk, i_ride; - uint32_t walk_stop, ride_stop; + spidx_t walk_stop_point; + spidx_t ride_stop_point; - i_state = (((uint8_t) j_transfer) * router->tdata->n_stops); + i_state = (((uint8_t) j_transfer) * router->tdata->n_stop_points); - if (stop > router->tdata->n_stops) { - fprintf (stderr, "ERROR: stopid %d out of range.\n", stop); + if (sp_index > router->tdata->n_stop_points) { + fprintf (stderr, "ERROR: stop_point idx %d out of range.\n", sp_index); return false; } /* Walk phase */ - i_walk = i_state + stop; + i_walk = i_state + sp_index; if (router->states_walk_time[i_walk] == UNREACHED) { - fprintf (stderr, "ERROR: stop %d was unreached by walking.\n", stop); + fprintf (stderr, "ERROR: stop_point idx %d was unreached by walking.\n", sp_index); return false; } - walk_stop = stop; - stop = router->states_walk_from[i_walk]; /* follow the chain of states backward */ + walk_stop_point = sp_index; + sp_index = router->states_walk_from[i_walk]; /* follow the chain of states backward */ /* Ride phase */ - i_ride = i_state + stop; + i_ride = i_state + sp_index; if (router->states_time[i_ride] == UNREACHED) { - fprintf (stderr, "ERROR: stop %d was unreached by riding.\n", stop); + fprintf (stderr, "ERROR: sp %d was unreached by riding.\n", sp_index); return false; } - ride_stop = stop; - stop = router->states_ride_from[i_ride]; /* follow the chain of states backward */ + ride_stop_point = sp_index; + sp_index = router->states_ride_from[i_ride]; /* follow the chain of states backward */ /* Walk phase */ - l->s0 = router->states_walk_from[i_walk]; - l->s1 = walk_stop; + l->sp_from = router->states_walk_from[i_walk]; + l->sp_to = walk_stop_point; l->t0 = router->states_time[i_ride]; /* Rendering the walk requires already having the ride arrival time */ l->t1 = router->states_walk_time[i_walk]; l->journey_pattern = WALK; @@ -174,8 +175,8 @@ bool router_result_to_plan (struct plan *plan, router_t *router, router_request_ l += (req->arrive_by ? 1 : -1); /* next leg */ /* Ride phase */ - l->s0 = router->states_ride_from[i_ride]; - l->s1 = ride_stop; + l->sp_from = router->states_ride_from[i_ride]; + l->sp_to = ride_stop_point; l->t0 = router->states_board_time[i_ride]; l->t1 = router->states_time[i_ride]; l->journey_pattern = router->states_back_journey_pattern[i_ride]; @@ -188,7 +189,7 @@ bool router_result_to_plan (struct plan *plan, router_t *router, router_request_ uint32_t vj_index; jp = router->tdata->journey_patterns + router->states_back_journey_pattern[i_ride]; - vj_index = jp->vj_ids_offset + router->states_back_vehicle_journey[i_ride]; + vj_index = jp->vj_offset + router->states_back_vehicle_journey[i_ride]; vj = router->tdata->vjs + vj_index; if (router->tdata->vj_stoptimes[vj_index] && @@ -210,11 +211,11 @@ bool router_result_to_plan (struct plan *plan, router_t *router, router_request_ if (req->onboard_journey_pattern_offset != NONE) { if (!req->arrive_by) { /* Results starting on board do not have an initial walk leg. */ - l->s0 = l->s1 = ONBOARD; + l->sp_from = l->sp_to = ONBOARD; l->t0 = l->t1 = req->time; l->journey_pattern = l->vj = WALK; l += 1; /* move back to first transit leg */ - l->s0 = ONBOARD; + l->sp_from = ONBOARD; l->t0 = req->time; } else { #ifdef RRRR_DEBUG @@ -224,14 +225,14 @@ bool router_result_to_plan (struct plan *plan, router_t *router, router_request_ } } else { /* The initial walk leg leading out of the search origin. This is inferred, not stored explicitly. */ - uint32_t origin_stop = (req->arrive_by ? req->to : req->from); + spidx_t origin_stop_point = (req->arrive_by ? req->to_stop_point : req->from_stop_point); rtime_t duration; - l->s0 = origin_stop; - l->s1 = stop; + l->sp_from = origin_stop_point; + l->sp_to = sp_index; /* It would also be possible to work from s1 to s0 and compress out the wait time. */ - l->t0 = router->states_time[origin_stop]; - duration = transfer_duration (router->tdata, req, l->s0, l->s1); + l->t0 = router->states_time[origin_stop_point]; + duration = transfer_duration (router->tdata, req, l->sp_from, l->sp_to); l->t1 = l->t0 + (req->arrive_by ? -duration : +duration); l->journey_pattern = WALK; l->vj = WALK; @@ -256,8 +257,8 @@ plan_render_itinerary (struct itinerary *itin, tdata_t *tdata, char *b, char *b_ char ct1[16]; const char *agency_name, *short_name, *headsign, *productcategory, *leg_mode = NULL; char *alert_msg = NULL; - const char *s0_id = tdata_stop_name_for_index(tdata, leg->s0); - const char *s1_id = tdata_stop_name_for_index(tdata, leg->s1); + const char *s0_id = tdata_stop_point_name_for_index(tdata, leg->sp_from); + const char *s1_id = tdata_stop_point_name_for_index(tdata, leg->sp_to); float d0 = 0.0, d1 = 0.0; btimetext(leg->t0, ct0); @@ -272,8 +273,8 @@ plan_render_itinerary (struct itinerary *itin, tdata_t *tdata, char *b, char *b_ productcategory = ""; /* Skip uninformative legs that just tell you to stay in the same place. if (leg->s0 == leg->s1) continue; */ - if (leg->s0 == ONBOARD) continue; - if (leg->s0 == leg->s1) leg_mode = "WAIT"; + if (leg->sp_from == ONBOARD) continue; + if (leg->sp_from == leg->sp_to) leg_mode = "WAIT"; else leg_mode = "WALK"; } else { agency_name = tdata_agency_name_for_journey_pattern(tdata, leg->journey_pattern); @@ -309,7 +310,7 @@ plan_render_itinerary (struct itinerary *itin, tdata_t *tdata, char *b, char *b_ TransitRealtime__EntitySelector *informed_entity = alert->informed_entity[i_informed_entity]; if ( ( (!informed_entity->route_id) || ((uint32_t) *(informed_entity->route_id) == leg->journey_pattern) ) && - ( (!informed_entity->stop_id) || ((uint32_t) *(informed_entity->stop_id) == leg->s0) ) && + ( (!informed_entity->stop_id) || ((uint32_t) *(informed_entity->stop_id) == leg->sp_from) ) && ( (!informed_entity->trip) || (!informed_entity->trip->trip_id) || ((uint32_t) *(informed_entity->trip->trip_id) == leg->vj) ) /* TODO: need to have rtime_to_date for informed_entity->vj->start_date */ /* TODO: need to have rtime_to_epoch for informed_entity->active_period */ @@ -331,7 +332,7 @@ plan_render_itinerary (struct itinerary *itin, tdata_t *tdata, char *b, char *b_ /* TODO: we are able to calculate the maximum length required for each line * therefore we could prevent a buffer overflow from happening. */ b += sprintf (b, "%s %5d %3d %5d %5d %s %+3.1f %s %+3.1f ;%s;%s;%s;%s;%s;%s;%s\n", - leg_mode, leg->journey_pattern, leg->vj, leg->s0, leg->s1, ct0, d0, ct1, d1, agency_name, short_name, headsign, productcategory, s0_id, s1_id, + leg_mode, leg->journey_pattern, leg->vj, leg->sp_from, leg->sp_to, ct0, d0, ct1, d1, agency_name, short_name, headsign, productcategory, s0_id, s1_id, (alert_msg ? alert_msg : "")); /* EXAMPLE diff --git a/router_result.h b/router_result.h index e31aacb..b94bf18 100644 --- a/router_result.h +++ b/router_result.h @@ -15,11 +15,11 @@ struct leg { /* vj index */ uint32_t vj; - /* from stop index */ - spidx_t s0; + /* from stop_point index */ + spidx_t sp_from; - /* to stop index */ - spidx_t s1; + /* to stop_point index */ + spidx_t sp_to; /* start time */ rtime_t t0; diff --git a/rrrr_types.h b/rrrr_types.h index e23055b..c97f187 100644 --- a/rrrr_types.h +++ b/rrrr_types.h @@ -85,14 +85,14 @@ struct router_request { latlon_t via_latlon; hashgrid_result_t via_hg_result; #endif - /* (nearest) start stop index from the users perspective */ - spidx_t from; + /* (nearest) start stop_point index from the users perspective */ + spidx_t from_stop_point; - /* (nearest) destination stop index from the users perspective */ - spidx_t to; + /* (nearest) destination stop_point index from the users perspective */ + spidx_t to_stop_point; - /* preferred transfer stop index from the users perspective */ - spidx_t via; + /* preferred transfer stop_point index from the users perspective */ + spidx_t via_stop_point; /* onboard departure, journey_pattern index from the users perspective */ uint32_t onboard_vj_journey_pattern; @@ -104,11 +104,11 @@ struct router_request { #if RRRR_MAX_BANNED_JOURNEY_PATTERNS > 0 uint32_t banned_journey_patterns[RRRR_MAX_BANNED_JOURNEY_PATTERNS]; #endif - #if RRRR_MAX_BANNED_STOPS > 0 - spidx_t banned_stops[RRRR_MAX_BANNED_STOPS]; + #if RRRR_MAX_BANNED_STOP_POINTS > 0 + spidx_t banned_stops[RRRR_MAX_BANNED_STOP_POINTS]; #endif - #if RRRR_MAX_BANNED_STOPS_HARD > 0 - spidx_t banned_stops_hard[RRRR_MAX_BANNED_STOPS_HARD]; + #if RRRR_MAX_BANNED_STOP_POINTS_HARD > 0 + spidx_t banned_stop_points_hard[RRRR_MAX_BANNED_STOP_POINTS_HARD]; #endif #if RRRR_MAX_BANNED_VEHICLE_JOURNEYS > 0 uint32_t banned_vjs_journey_pattern[RRRR_MAX_BANNED_VEHICLE_JOURNEYS]; @@ -151,11 +151,11 @@ struct router_request { #if RRRR_MAX_BANNED_JOURNEY_PATTERNS > 0 uint8_t n_banned_journey_patterns; #endif - #if RRRR_MAX_BANNED_STOPS > 0 + #if RRRR_MAX_BANNED_STOP_POINTS > 0 uint8_t n_banned_stops; #endif - #if RRRR_MAX_BANNED_STOPS_HARD > 0 - uint8_t n_banned_stops_hard; + #if RRRR_MAX_BANNED_STOP_POINTS_HARD > 0 + uint8_t n_banned_stop_points_hard; #endif #if RRRR_MAX_BANNED_VEHICLE_JOURNEYS > 0 uint8_t n_banned_vjs; diff --git a/stubs.h b/stubs.h index fefac0f..15aac9b 100644 --- a/stubs.h +++ b/stubs.h @@ -32,7 +32,7 @@ void memset32(uint32_t *s, uint32_t u, size_t n); char * strcasestr(const char *s, const char *find); uint32_t rrrrandom(uint32_t limit); -char *tdata_stop_name_for_index(tdata_t *td, uint32_t stop_index); +char *tdata_stop_name_for_index(tdata_t *td, uint32_t sp_index); char *btimetext(rtime_t t, char *buf); void router_request_randomize (router_request_t *req, tdata_t *tdata); diff --git a/tdata.c b/tdata.c index caaeac1..11b885f 100644 --- a/tdata.c +++ b/tdata.c @@ -39,12 +39,12 @@ const char *tdata_line_id_for_journey_pattern(tdata_t *td, uint32_t jp_index) { return td->line_ids + (td->line_ids_width * jp_index); } -const char *tdata_stop_id_for_index(tdata_t *td, spidx_t stop_index) { - return td->stop_ids + (td->stop_ids_width * stop_index); +const char *tdata_stop_point_id_for_index(tdata_t *td, spidx_t sp_index) { + return td->stop_point_ids + (td->stop_point_ids_width * sp_index); } -uint8_t *tdata_stop_attributes_for_index(tdata_t *td, spidx_t stop_index) { - return td->stop_attributes + stop_index; +uint8_t *tdata_stop_point_attributes_for_index(tdata_t *td, spidx_t sp_index) { + return td->stop_point_attributes + sp_index; } const char *tdata_vehicle_journey_id_for_index(tdata_t *td, uint32_t vj_index) { @@ -52,7 +52,7 @@ const char *tdata_vehicle_journey_id_for_index(tdata_t *td, uint32_t vj_index) { } const char *tdata_vehicle_journey_id_for_jp_vj_index(tdata_t *td, uint32_t jp_index, uint32_t vj_index) { - return td->vj_ids + (td->vj_ids_width * (td->journey_patterns[jp_index].vj_ids_offset + vj_index)); + return td->vj_ids + (td->vj_ids_width * (td->journey_patterns[jp_index].vj_offset + vj_index)); } const char *tdata_agency_id_for_index(tdata_t *td, uint32_t agency_index) { @@ -79,44 +79,44 @@ const char *tdata_productcategory_for_index(tdata_t *td, uint32_t productcategor return td->productcategories + (td->productcategories_width * productcategory_index); } -const char *tdata_platformcode_for_index(tdata_t *td, spidx_t stop_index) { - switch (stop_index) { +const char *tdata_platformcode_for_index(tdata_t *td, spidx_t sp_index) { + switch (sp_index) { case STOP_NONE : return NULL; case ONBOARD : return NULL; default : - return td->platformcodes + (td->platformcodes_width * stop_index); + return td->platformcodes + (td->platformcodes_width * sp_index); } } -spidx_t tdata_stopidx_by_stop_name(tdata_t *td, char* stop_name, spidx_t stop_index_offset) { - spidx_t stop_index; - for (stop_index = stop_index_offset; - stop_index < td->n_stops; - ++stop_index) { - if (strcasestr(td->stop_names + td->stop_nameidx[stop_index], - stop_name)) { - return stop_index; +spidx_t tdata_stop_pointidx_by_stop_point_name(tdata_t *td, char *stop_point_name, spidx_t sp_index_offset) { + spidx_t sp_index; + for (sp_index = sp_index_offset; + sp_index < td->n_stop_points; + ++sp_index) { + if (strcasestr(td->stop_point_names + td->stop_point_nameidx[sp_index], + stop_point_name)) { + return sp_index; } } return STOP_NONE; } -spidx_t tdata_stopidx_by_stop_id(tdata_t *td, char* stop_id, spidx_t stop_index_offset) { - spidx_t stop_index; - for (stop_index = stop_index_offset; - stop_index < td->n_stops; - ++stop_index) { - if (strcasestr(td->stop_ids + (td->stop_ids_width * stop_index), - stop_id)) { - return stop_index; +spidx_t tdata_stop_pointidx_by_stop_point_idx(tdata_t *td, char *stop_point_id, spidx_t sp_index_offset) { + spidx_t sp_index; + for (sp_index = sp_index_offset; + sp_index < td->n_stop_points; + ++sp_index) { + if (strcasestr(td->stop_point_ids + (td->stop_point_ids_width * sp_index), + stop_point_id)) { + return sp_index; } } return STOP_NONE; } -#define tdata_stopidx_by_stop_id(td, stop_id) tdata_stopidx_by_stop_id(td, stop_id, 0) +#define tdata_stop_pointidx_by_stop_point_id(td, stop_id) tdata_stopidx_by_stop_id(td, stop_id, 0) uint32_t tdata_journey_pattern_idx_by_line_id(tdata_t *td, char *line_id, uint32_t jp_index_offset) { uint32_t jp_index; @@ -135,13 +135,13 @@ uint32_t tdata_journey_pattern_idx_by_line_id(tdata_t *td, char *line_id, uint32 const char *tdata_vehicle_journey_ids_in_journey_pattern(tdata_t *td, uint32_t jp_index) { journey_pattern_t *jp = &(td->journey_patterns[jp_index]); - uint32_t char_offset = jp->vj_ids_offset * td->vj_ids_width; + uint32_t char_offset = jp->vj_offset * td->vj_ids_width; return td->vj_ids + char_offset; } calendar_t *tdata_vj_masks_for_journey_pattern(tdata_t *td, uint32_t jp_index) { journey_pattern_t *jp = &(td->journey_patterns[jp_index]); - return td->vj_active + jp->vj_ids_offset; + return td->vj_active + jp->vj_offset; } const char *tdata_headsign_for_journey_pattern(tdata_t *td, uint32_t jp_index) { @@ -223,45 +223,45 @@ spidx_t *tdata_points_for_journey_pattern(tdata_t *td, uint32_t jp_index) { return td->journey_pattern_points + td->journey_patterns[jp_index].journey_pattern_point_offset; } -uint8_t *tdata_stop_attributes_for_journey_pattern(tdata_t *td, uint32_t jp_index) { +uint8_t *tdata_stop_point_attributes_for_journey_pattern(tdata_t *td, uint32_t jp_index) { journey_pattern_t *jp = &(td->journey_patterns[jp_index]); return td->journey_pattern_point_attributes + jp->journey_pattern_point_offset; } -uint32_t tdata_journey_patterns_for_stop(tdata_t *td, spidx_t stop_index, uint32_t **jp_ret) { - stop_t *stop0 = &(td->stops[stop_index]); - stop_t *stop1 = &(td->stops[stop_index + 1]); - *jp_ret = td->journey_patterns_at_stop + stop0->journey_patterns_at_stop_offset; - return stop1->journey_patterns_at_stop_offset - stop0->journey_patterns_at_stop_offset; +uint32_t tdata_journey_patterns_for_stop_point(tdata_t *td, spidx_t sp_index, uint32_t **jp_ret) { + stop_point_t *stop0 = &(td->stop_points[sp_index]); + stop_point_t *stop1 = &(td->stop_points[sp_index + 1]); + *jp_ret = td->journey_patterns_at_stop + stop0->journey_patterns_at_stop_point_offset; + return stop1->journey_patterns_at_stop_point_offset - stop0->journey_patterns_at_stop_point_offset; } stoptime_t *tdata_timedemand_type(tdata_t *td, uint32_t jp_index, uint32_t vj_index) { - return td->stop_times + td->vjs[td->journey_patterns[jp_index].vj_ids_offset + vj_index].stop_times_offset; + return td->stop_times + td->vjs[td->journey_patterns[jp_index].vj_offset + vj_index].stop_times_offset; } vehicle_journey_t *tdata_vehicle_journeys_in_journey_pattern(tdata_t *td, uint32_t jp_index) { - return td->vjs + td->journey_patterns[jp_index].vj_ids_offset; + return td->vjs + td->journey_patterns[jp_index].vj_offset; } -const char *tdata_stop_name_for_index(tdata_t *td, spidx_t stop_index) { - switch (stop_index) { +const char *tdata_stop_point_name_for_index(tdata_t *td, spidx_t sp_index) { + switch (sp_index) { case STOP_NONE : return "NONE"; case ONBOARD : return "ONBOARD"; default : - return td->stop_names + td->stop_nameidx[stop_index]; + return td->stop_point_names + td->stop_point_nameidx[sp_index]; } } /* Rather than reserving a place to store the transfers used to create the initial state, we look them up as needed. */ -rtime_t transfer_duration (tdata_t *tdata, router_request_t *req, spidx_t stop_index_from, spidx_t stop_index_to) { +rtime_t transfer_duration (tdata_t *tdata, router_request_t *req, spidx_t sp_index_from, spidx_t sp_index_to) { UNUSED(req); - if (stop_index_from != stop_index_to) { - uint32_t t = tdata->stops[stop_index_from ].transfers_offset; - uint32_t tN = tdata->stops[stop_index_from + 1].transfers_offset; + if (sp_index_from != sp_index_to) { + uint32_t t = tdata->stop_points[sp_index_from ].transfers_offset; + uint32_t tN = tdata->stop_points[sp_index_from + 1].transfers_offset; for ( ; t < tN ; ++t) { - if (tdata->transfer_target_stops[t] == stop_index_to) { + if (tdata->transfer_target_stops[t] == sp_index_to) { return (rtime_t) tdata->transfer_dist_meters[t] + req->walk_slack; } } @@ -294,20 +294,20 @@ void tdata_dump_journey_pattern(tdata_t *td, uint32_t jp_index, uint32_t vj_inde /* TODO should this really be a 2D array ? stoptime_t (*times)[jp.n_stops] = (void*) tdata_timedemand_type(td, jp_index, ti); */ - printf("%s\n", tdata_vehicle_journey_id_for_index(td, jp.vj_ids_offset + ti)); + printf("%s\n", tdata_vehicle_journey_id_for_index(td, jp.vj_offset + ti)); for (si = 0; si < jp.n_stops; ++si) { - const char *stop_id = tdata_stop_name_for_index (td, stops[si]); + const char *stop_id = tdata_stop_point_name_for_index (td, stops[si]); char arrival[13], departure[13]; printf("%4d %35s [%06d] : %s %s", si, stop_id, stops[si], - btimetext(times[si].arrival + td->vjs[jp.vj_ids_offset + ti].begin_time + RTIME_ONE_DAY, arrival), - btimetext(times[si].departure + td->vjs[jp.vj_ids_offset + ti].begin_time + RTIME_ONE_DAY, departure)); + btimetext(times[si].arrival + td->vjs[jp.vj_offset + ti].begin_time + RTIME_ONE_DAY, arrival), + btimetext(times[si].departure + td->vjs[jp.vj_offset + ti].begin_time + RTIME_ONE_DAY, departure)); #ifdef RRRR_FEATURE_REALTIME_EXPANDED - if (td->vj_stoptimes && td->vj_stoptimes[jp.vj_ids_offset + ti]) { + if (td->vj_stoptimes && td->vj_stoptimes[jp.vj_offset + ti]) { printf (" %s %s", - btimetext(td->vj_stoptimes[jp.vj_ids_offset + ti][si].arrival + RTIME_ONE_DAY, arrival), - btimetext(td->vj_stoptimes[jp.vj_ids_offset + ti][si].departure + RTIME_ONE_DAY, departure)); + btimetext(td->vj_stoptimes[jp.vj_offset + ti][si].arrival + RTIME_ONE_DAY, arrival), + btimetext(td->vj_stoptimes[jp.vj_offset + ti][si].departure + RTIME_ONE_DAY, departure)); } #endif @@ -322,18 +322,18 @@ void tdata_dump(tdata_t *td) { uint32_t i; printf("\nCONTEXT\n" - "n_stops: %d\n" - "n_journey_patterns: %d\n", td->n_stops, td->n_journey_patterns); + "n_stop_points: %d\n" + "n_journey_patterns: %d\n", td->n_stop_points, td->n_journey_patterns); printf("\nSTOPS\n"); - for (i = 0; i < td->n_stops; i++) { - stop_t s0 = td->stops[i]; - stop_t s1 = td->stops[i+1]; - uint32_t j0 = s0.journey_patterns_at_stop_offset; - uint32_t j1 = s1.journey_patterns_at_stop_offset; + for (i = 0; i < td->n_stop_points; i++) { + stop_point_t s0 = td->stop_points[i]; + stop_point_t s1 = td->stop_points[i+1]; + uint32_t j0 = s0.journey_patterns_at_stop_point_offset; + uint32_t j1 = s1.journey_patterns_at_stop_point_offset; uint32_t j; printf("stop %d at lat %f lon %f\n", - i, td->stop_coords[i].lat, td->stop_coords[i].lon); + i, td->stop_point_coords[i].lat, td->stop_point_coords[i].lon); printf("served by journey_patterns "); for (j=j0; jjourney_patterns_at_stop[j]); @@ -357,8 +357,8 @@ void tdata_dump(tdata_t *td) { printf("\n"); } printf("\nSTOPIDS\n"); - for (i = 0; i < td->n_stops; i++) { - printf("stop %03d has id %s \n", i, tdata_stop_name_for_index(td, i)); + for (i = 0; i < td->n_stop_points; i++) { + printf("stop %03d has id %s \n", i, tdata_stop_point_name_for_index(td, i)); } for (i = 0; i < td->n_journey_patterns; i++) { /* TODO: Remove? diff --git a/tdata.h b/tdata.h index eba15a0..11cb426 100644 --- a/tdata.h +++ b/tdata.h @@ -17,9 +17,9 @@ #include #include -typedef struct stop stop_t; -struct stop { - uint32_t journey_patterns_at_stop_offset; +typedef struct stop_point stop_point_t; +struct stop_point { + uint32_t journey_patterns_at_stop_point_offset; uint32_t transfers_offset; }; @@ -29,7 +29,7 @@ struct stop { typedef struct journey_pattern journey_pattern_t; struct journey_pattern { uint32_t journey_pattern_point_offset; - uint32_t vj_ids_offset; + uint32_t vj_offset; uint32_t headsign_offset; uint16_t n_stops; uint16_t n_vjs; @@ -108,9 +108,9 @@ struct tdata { /* Dates within the active calendar which have DST. */ calendar_t dst_active; - uint32_t n_stops; - uint32_t n_stop_attributes; - uint32_t n_stop_coords; + uint32_t n_stop_points; + uint32_t n_stop_point_attributes; + uint32_t n_stop_point_coords; uint32_t n_journey_patterns; uint32_t n_journey_pattern_points; uint32_t n_journey_pattern_point_attributes; @@ -122,8 +122,8 @@ struct tdata { uint32_t n_vj_active; uint32_t n_journey_pattern_active; uint32_t n_platformcodes; - uint32_t n_stop_names; - uint32_t n_stop_nameidx; + uint32_t n_stop_point_names; + uint32_t n_stop_point_nameidx; uint32_t n_agency_ids; uint32_t n_agency_names; uint32_t n_agency_urls; @@ -131,10 +131,10 @@ struct tdata { uint32_t n_line_codes; uint32_t n_productcategories; uint32_t n_line_ids; - uint32_t n_stop_ids; + uint32_t n_stop_point_ids; uint32_t n_vj_ids; - stop_t *stops; - uint8_t *stop_attributes; + stop_point_t *stop_points; + uint8_t *stop_point_attributes; journey_pattern_t *journey_patterns; spidx_t *journey_pattern_points; uint8_t *journey_pattern_point_attributes; @@ -146,11 +146,11 @@ struct tdata { rtime_t max_time; /* optional data: * NULL pointer means it is not available */ - latlon_t *stop_coords; + latlon_t *stop_point_coords; uint32_t platformcodes_width; char *platformcodes; - char *stop_names; - uint32_t *stop_nameidx; + char *stop_point_names; + uint32_t *stop_point_nameidx; uint32_t agency_ids_width; char *agency_ids; uint32_t agency_names_width; @@ -166,8 +166,8 @@ struct tdata { calendar_t *journey_pattern_active; uint32_t line_ids_width; char *line_ids; - uint32_t stop_ids_width; - char *stop_ids; + uint32_t stop_point_ids_width; + char *stop_point_ids; uint32_t vj_ids_width; char *vj_ids; #ifdef RRRR_FEATURE_REALTIME @@ -177,7 +177,7 @@ struct tdata { #ifdef RRRR_FEATURE_REALTIME_EXPANDED stoptime_t **vj_stoptimes; uint32_t *vjs_in_journey_pattern; - list_t **rt_journey_patterns_at_stop; + list_t **rt_journey_patterns_at_stop_point; calendar_t *vj_active_orig; calendar_t *journey_pattern_active_orig; #endif @@ -195,10 +195,10 @@ void tdata_dump(tdata_t *td); spidx_t *tdata_points_for_journey_pattern(tdata_t *td, uint32_t jp_index); -uint8_t *tdata_stop_attributes_for_journey_pattern(tdata_t *td, uint32_t jp_index); +uint8_t *tdata_stop_point_attributes_for_journey_pattern(tdata_t *td, uint32_t jp_index); /* TODO: return number of items and store pointer to beginning, to allow restricted pointers */ -uint32_t tdata_journey_patterns_for_stop(tdata_t *td, spidx_t stop_index, uint32_t **jp_ret); +uint32_t tdata_journey_patterns_for_stop_point(tdata_t *td, spidx_t sp_index, uint32_t **jp_ret); stoptime_t *tdata_stoptimes_for_journey_pattern(tdata_t *td, uint32_t jp_index); @@ -206,9 +206,9 @@ void tdata_dump_journey_pattern(tdata_t *td, uint32_t jp_index, uint32_t vj_inde const char *tdata_line_id_for_journey_pattern(tdata_t *td, uint32_t jp_index); -const char *tdata_stop_id_for_index(tdata_t *td, spidx_t stop_index); +const char *tdata_stop_point_id_for_index(tdata_t *td, spidx_t sp_index); -uint8_t *tdata_stop_attributes_for_index(tdata_t *td, spidx_t stop_index); +uint8_t *tdata_stop_point_attributes_for_index(tdata_t *td, spidx_t sp_index); const char *tdata_vehicle_journey_id_for_index(tdata_t *td, uint32_t vj_index); @@ -228,13 +228,13 @@ const char *tdata_line_code_for_index(tdata_t *td, uint32_t line_code_index); const char *tdata_productcategory_for_index(tdata_t *td, uint32_t productcategory_index); -const char *tdata_stop_name_for_index(tdata_t *td, spidx_t stop_index); +const char *tdata_stop_point_name_for_index(tdata_t *td, spidx_t sp_index); -const char *tdata_platformcode_for_index(tdata_t *td, spidx_t stop_index); +const char *tdata_platformcode_for_index(tdata_t *td, spidx_t sp_index); -spidx_t tdata_stopidx_by_stop_name(tdata_t *td, char* stop_name, spidx_t start_index); +spidx_t tdata_stop_pointidx_by_stop_point_name(tdata_t *td, char *stop_point_name, spidx_t sp_index_offset); -spidx_t tdata_stopidx_by_stop_id(tdata_t *td, char* stop_id, spidx_t start_index); +spidx_t tdata_stop_pointidx_by_stop_point_idx(tdata_t *td, char *stop_point_id, spidx_t sp_index_offset); uint32_t tdata_journey_pattern_idx_by_line_id(tdata_t *td, char *line_id, uint32_t start_index); @@ -261,10 +261,10 @@ stoptime_t *tdata_timedemand_type(tdata_t *td, uint32_t jp_index, uint32_t vj_in /* Get a pointer to the array of vehicle_journeys for this journey_pattern. */ vehicle_journey_t *tdata_vehicle_journeys_in_journey_pattern(tdata_t *td, uint32_t jp_index); -const char *tdata_stop_desc_for_index(tdata_t *td, spidx_t stop_index); +const char *tdata_stop_desc_for_index(tdata_t *td, spidx_t sp_index); -rtime_t transfer_duration (tdata_t *tdata, router_request_t *req, spidx_t stop_index_from, spidx_t stop_index_to); +rtime_t transfer_duration (tdata_t *tdata, router_request_t *req, spidx_t sp_index_from, spidx_t sp_index_to); -const char *tdata_stop_name_for_index(tdata_t *td, spidx_t stop_index); +const char *tdata_stop_point_name_for_index(tdata_t *td, spidx_t sp_index); #endif /* _TDATA_H */ diff --git a/tdata_io_v3.h b/tdata_io_v3.h index e1b1b0f..00bf57f 100644 --- a/tdata_io_v3.h +++ b/tdata_io_v3.h @@ -8,9 +8,9 @@ struct tdata_header { char version_string[8]; uint64_t calendar_start_time; calendar_t dst_active; - uint32_t n_stops; - uint32_t n_stop_attributes; - uint32_t n_stop_coords; + uint32_t n_stop_points; + uint32_t n_stop_point_attributes; + uint32_t n_stop_point_coords; uint32_t n_journey_patterns; uint32_t n_journey_pattern_points; uint32_t n_journey_pattern_point_attributes; @@ -23,8 +23,8 @@ struct tdata_header { uint32_t n_journey_pattern_active; uint32_t n_platformcodes; /* length of the object in bytes */ - uint32_t n_stop_names; - uint32_t n_stop_nameidx; + uint32_t n_stop_point_names; + uint32_t n_stop_point_nameidx; uint32_t n_agency_ids; uint32_t n_agency_names; uint32_t n_agency_urls; @@ -35,11 +35,11 @@ struct tdata_header { uint32_t n_line_codes; uint32_t n_productcategories; uint32_t n_line_ids; - uint32_t n_stop_ids; + uint32_t n_stop_point_ids; uint32_t n_vj_ids; - uint32_t loc_stops; - uint32_t loc_stop_attributes; - uint32_t loc_stop_coords; + uint32_t loc_stop_points; + uint32_t loc_stop_point_attributes; + uint32_t loc_stop_point_coords; uint32_t loc_journey_patterns; uint32_t loc_journey_pattern_points; uint32_t loc_journey_pattern_point_attributes; @@ -51,8 +51,8 @@ struct tdata_header { uint32_t loc_vj_active; uint32_t loc_journey_pattern_active; uint32_t loc_platformcodes; - uint32_t loc_stop_names; - uint32_t loc_stop_nameidx; + uint32_t loc_stop_point_names; + uint32_t loc_stop_point_nameidx; uint32_t loc_agency_ids; uint32_t loc_agency_names; uint32_t loc_agency_urls; @@ -60,7 +60,7 @@ struct tdata_header { uint32_t loc_line_codes; uint32_t loc_productcategories; uint32_t loc_line_ids; - uint32_t loc_stop_ids; + uint32_t loc_stop_point_ids; uint32_t loc_vj_ids; }; diff --git a/tdata_io_v3_dynamic.c b/tdata_io_v3_dynamic.c index c281886..73c39d7 100644 --- a/tdata_io_v3_dynamic.c +++ b/tdata_io_v3_dynamic.c @@ -69,9 +69,9 @@ bool tdata_io_v3_load(tdata_t *td, char *filename) { } /* More input validation in the dynamic loading case. */ - if ( !( header->n_stops < ((spidx_t) -2) && - header->n_stop_attributes < ((spidx_t) -2) && - header->n_stop_coords < ((spidx_t) -2) && + if ( !( header->n_stop_points < ((spidx_t) -2) && + header->n_stop_point_attributes < ((spidx_t) -2) && + header->n_stop_point_coords < ((spidx_t) -2) && header->n_journey_patterns < (UINT32_MAX - 1) && header->n_journey_pattern_points < (UINT32_MAX) && header->n_journey_pattern_point_attributes < (UINT32_MAX) && @@ -83,8 +83,8 @@ bool tdata_io_v3_load(tdata_t *td, char *filename) { header->n_vj_active < (UINT32_MAX) && header->n_journey_pattern_active < (UINT32_MAX) && header->n_platformcodes < (UINT32_MAX) && - header->n_stop_names < (UINT32_MAX) && - header->n_stop_nameidx < ((spidx_t) -2) && + header->n_stop_point_names < (UINT32_MAX) && + header->n_stop_point_nameidx < ((spidx_t) -2) && header->n_agency_ids < (UINT16_MAX) && header->n_agency_names < (UINT16_MAX) && header->n_agency_urls < (UINT16_MAX) && @@ -92,7 +92,7 @@ bool tdata_io_v3_load(tdata_t *td, char *filename) { header->n_line_codes < (UINT16_MAX) && header->n_productcategories < (UINT16_MAX) && header->n_line_ids < (UINT32_MAX) && - header->n_stop_ids < ((spidx_t) -2) && + header->n_stop_point_ids < ((spidx_t) -2) && header->n_vj_ids < (UINT32_MAX) ) ) { fprintf(stderr, "The input file %s does not appear to be a valid timetable.\n", filename); @@ -102,9 +102,9 @@ bool tdata_io_v3_load(tdata_t *td, char *filename) { td->calendar_start_time = header->calendar_start_time; td->dst_active = header->dst_active; - load_dynamic (fd, stops, stop_t); - load_dynamic (fd, stop_attributes, uint8_t); - load_dynamic (fd, stop_coords, latlon_t); + load_dynamic (fd, stop_points, stop_point_t); + load_dynamic (fd, stop_point_attributes, uint8_t); + load_dynamic (fd, stop_point_coords, latlon_t); load_dynamic (fd, journey_patterns, journey_pattern_t); load_dynamic (fd, journey_pattern_points, spidx_t); load_dynamic (fd, journey_pattern_point_attributes, uint8_t); @@ -116,11 +116,11 @@ bool tdata_io_v3_load(tdata_t *td, char *filename) { load_dynamic (fd, vj_active, calendar_t); load_dynamic (fd, journey_pattern_active, calendar_t); load_dynamic (fd, headsigns, char); - load_dynamic (fd, stop_names, char); - load_dynamic (fd, stop_nameidx, uint32_t); + load_dynamic (fd, stop_point_names, char); + load_dynamic (fd, stop_point_nameidx, uint32_t); load_dynamic_string (fd, platformcodes); - load_dynamic_string (fd, stop_ids); + load_dynamic_string (fd, stop_point_ids); load_dynamic_string (fd, vj_ids); load_dynamic_string (fd, agency_ids); load_dynamic_string (fd, agency_names); @@ -141,9 +141,9 @@ bool tdata_io_v3_load(tdata_t *td, char *filename) { } void tdata_io_v3_close(tdata_t *td) { - free (td->stops); - free (td->stop_attributes); - free (td->stop_coords); + free (td->stop_points); + free (td->stop_point_attributes); + free (td->stop_point_coords); free (td->journey_patterns); free (td->journey_pattern_points); free (td->journey_pattern_point_attributes); @@ -155,11 +155,11 @@ void tdata_io_v3_close(tdata_t *td) { free (td->vj_active); free (td->journey_pattern_active); free (td->headsigns); - free (td->stop_names); - free (td->stop_nameidx); + free (td->stop_point_names); + free (td->stop_point_nameidx); free (td->platformcodes); - free (td->stop_ids); + free (td->stop_point_ids); free (td->vj_ids); free (td->agency_ids); free (td->agency_names); diff --git a/tdata_io_v3_mmap.c b/tdata_io_v3_mmap.c index 602a2bc..fd96248 100644 --- a/tdata_io_v3_mmap.c +++ b/tdata_io_v3_mmap.c @@ -72,9 +72,9 @@ bool tdata_io_v3_load(tdata_t *td, char *filename) { td->calendar_start_time = header->calendar_start_time; td->dst_active = header->dst_active; - load_mmap (td->base, stops, stop_t); - load_mmap (td->base, stop_attributes, uint8_t); - load_mmap (td->base, stop_coords, latlon_t); + load_mmap (td->base, stop_points, stop_point_t); + load_mmap (td->base, stop_point_attributes, uint8_t); + load_mmap (td->base, stop_point_coords, latlon_t); load_mmap (td->base, journey_patterns, journey_pattern_t); load_mmap (td->base, journey_pattern_points, spidx_t); load_mmap (td->base, journey_pattern_point_attributes, uint8_t); @@ -86,11 +86,11 @@ bool tdata_io_v3_load(tdata_t *td, char *filename) { load_mmap (td->base, vj_active, calendar_t); load_mmap (td->base, journey_pattern_active, calendar_t); load_mmap (td->base, headsigns, char); - load_mmap (td->base, stop_names, char); - load_mmap (td->base, stop_nameidx, uint32_t); + load_mmap (td->base, stop_point_names, char); + load_mmap (td->base, stop_point_nameidx, uint32_t); load_mmap_string (td->base, platformcodes); - load_mmap_string (td->base, stop_ids); + load_mmap_string (td->base, stop_point_ids); load_mmap_string (td->base, vj_ids); load_mmap_string (td->base, agency_ids); load_mmap_string (td->base, agency_names); diff --git a/tdata_realtime_alerts.c b/tdata_realtime_alerts.c index 714283f..6b5a59a 100644 --- a/tdata_realtime_alerts.c +++ b/tdata_realtime_alerts.c @@ -67,16 +67,16 @@ void tdata_apply_gtfsrt_alerts (tdata_t *tdata, uint8_t *buf, size_t len) { } if (informed_entity->stop_id) { - uint32_t stop_index = radixtree_find (tdata->stopid_index, + uint32_t sp_index = radixtree_find (tdata->stopid_index, informed_entity->stop_id); #ifdef RRRR_DEBUG - if (stop_index == RADIXTREE_NONE) { + if (sp_index == RADIXTREE_NONE) { fprintf (stderr, " stop id was not found in the radix tree.\n"); } #endif - *(informed_entity->stop_id) = stop_index; + *(informed_entity->stop_id) = sp_index; } if (informed_entity->trip && informed_entity->trip->trip_id) { diff --git a/tdata_realtime_expanded.c b/tdata_realtime_expanded.c index 51f2a2d..89b0712 100644 --- a/tdata_realtime_expanded.c +++ b/tdata_realtime_expanded.c @@ -24,44 +24,44 @@ #include #include -/* rt_journey_patterns_at_stop store the delta to the planned journey_patterns_at_stop */ -static void tdata_rt_journey_patterns_at_stop_append(tdata_t *tdata, - uint32_t stop_index, +/* rt_journey_patterns_at_stop_point store the delta to the planned journey_patterns_at_stop_point */ +static void tdata_rt_journey_patterns_at_stop_point_append(tdata_t *tdata, + uint32_t sp_index, uint32_t jp_index) { uint32_t i; - if (tdata->rt_journey_patterns_at_stop[stop_index]) { - for (i = 0; i < tdata->rt_journey_patterns_at_stop[stop_index]->len; ++i) { - if (((uint32_t *) tdata->rt_journey_patterns_at_stop[stop_index]->list)[i] == + if (tdata->rt_journey_patterns_at_stop_point[sp_index]) { + for (i = 0; i < tdata->rt_journey_patterns_at_stop_point[sp_index]->len; ++i) { + if (((uint32_t *) tdata->rt_journey_patterns_at_stop_point[sp_index]->list)[i] == jp_index) return; } } else { - tdata->rt_journey_patterns_at_stop[stop_index] = + tdata->rt_journey_patterns_at_stop_point[sp_index] = (list_t *) calloc(1, sizeof(list_t)); } - if (tdata->rt_journey_patterns_at_stop[stop_index]->len == - tdata->rt_journey_patterns_at_stop[stop_index]->size) { - tdata->rt_journey_patterns_at_stop[stop_index]->list = - realloc(tdata->rt_journey_patterns_at_stop[stop_index]->list, + if (tdata->rt_journey_patterns_at_stop_point[sp_index]->len == + tdata->rt_journey_patterns_at_stop_point[sp_index]->size) { + tdata->rt_journey_patterns_at_stop_point[sp_index]->list = + realloc(tdata->rt_journey_patterns_at_stop_point[sp_index]->list, sizeof(uint32_t) * - (tdata->rt_journey_patterns_at_stop[stop_index]->size + 8)); - tdata->rt_journey_patterns_at_stop[stop_index]->size += 8; + (tdata->rt_journey_patterns_at_stop_point[sp_index]->size + 8)); + tdata->rt_journey_patterns_at_stop_point[sp_index]->size += 8; } - ((uint32_t *) tdata->rt_journey_patterns_at_stop[stop_index]->list)[tdata->rt_journey_patterns_at_stop[stop_index]->len++] = jp_index; + ((uint32_t *) tdata->rt_journey_patterns_at_stop_point[sp_index]->list)[tdata->rt_journey_patterns_at_stop_point[sp_index]->len++] = jp_index; } -static void tdata_rt_journey_patterns_at_stop_remove(tdata_t *tdata, - uint32_t stop_index, +static void tdata_rt_journey_patterns_at_stop_point_remove(tdata_t *tdata, + uint32_t sp_index, uint32_t jp_index) { uint32_t i; - for (i = 0; i < tdata->rt_journey_patterns_at_stop[stop_index]->len; ++i) { - if (((uint32_t *) tdata->rt_journey_patterns_at_stop[stop_index]->list)[i] == + for (i = 0; i < tdata->rt_journey_patterns_at_stop_point[sp_index]->len; ++i) { + if (((uint32_t *) tdata->rt_journey_patterns_at_stop_point[sp_index]->list)[i] == jp_index) { - tdata->rt_journey_patterns_at_stop[stop_index]->len--; - ((uint32_t *) tdata->rt_journey_patterns_at_stop[stop_index]->list)[i] = - ((uint32_t *) tdata->rt_journey_patterns_at_stop[stop_index]->list)[tdata->rt_journey_patterns_at_stop[stop_index]->len]; + tdata->rt_journey_patterns_at_stop_point[sp_index]->len--; + ((uint32_t *) tdata->rt_journey_patterns_at_stop_point[sp_index]->list)[i] = + ((uint32_t *) tdata->rt_journey_patterns_at_stop_point[sp_index]->list)[tdata->rt_journey_patterns_at_stop_point[sp_index]->len]; return; } } @@ -104,12 +104,12 @@ static void tdata_realtime_free_vj_index(tdata_t *tdata, uint32_t vj_index) { /* Our datastructure requires us to commit on a fixed number of - * vehicle_journeys and a fixed number of stops in the journey_pattern. + * vehicle_journeys and a fixed number of stop_points in the journey_pattern. * Generally speaking, when a new journey_pattern is dynamically added, - * we will have only one vj, a list of stops in the journey_pattern. + * we will have only one vj, a list of stop_points in the journey_pattern. * * This call will preallocate, and fill the journey_pattern and matching - * vehicle_journeys, and wire them together. Stops and times will be added + * vehicle_journeys, and wire them together. stop_points and times will be added * later, they can be completely dynamic up to the allocated * length. * @@ -120,7 +120,7 @@ static void tdata_realtime_free_vj_index(tdata_t *tdata, uint32_t vj_index) { */ static uint32_t tdata_new_journey_pattern(tdata_t *tdata, char *vj_ids, - uint16_t n_stops, uint16_t n_vjs, + uint16_t n_sp, uint16_t n_vjs, uint16_t attributes, uint32_t headsign_offset, uint16_t agency_index, uint16_t line_code_index, uint16_t productcategory_index) { @@ -128,15 +128,15 @@ static uint32_t tdata_new_journey_pattern(tdata_t *tdata, char *vj_ids, uint32_t journey_pattern_point_offset = tdata->n_journey_pattern_points; uint32_t stop_times_offset = tdata->n_stop_times; uint32_t vj_index = tdata->n_vjs; - uint16_t i_stop; + uint16_t sp_index; uint16_t i_vj; new = &tdata->journey_patterns[tdata->n_journey_patterns]; new->journey_pattern_point_offset = journey_pattern_point_offset; - new->vj_ids_offset = vj_index; + new->vj_offset = vj_index; new->headsign_offset = headsign_offset; - new->n_stops = n_stops; + new->n_stops = n_sp; new->n_vjs = n_vjs; new->attributes = attributes; new->agency_index = agency_index; @@ -145,7 +145,7 @@ static uint32_t tdata_new_journey_pattern(tdata_t *tdata, char *vj_ids, tdata->vjs[vj_index].stop_times_offset = stop_times_offset; - for (i_stop = 0; i_stop < n_stops; ++i_stop) { + for (sp_index = 0; sp_index < n_sp; ++sp_index) { tdata->journey_pattern_points[journey_pattern_point_offset] = NONE; journey_pattern_point_offset++; @@ -162,12 +162,12 @@ static uint32_t tdata_new_journey_pattern(tdata_t *tdata, char *vj_ids, /* add the last journey_pattern index to the lookup table */ for (i_vj = 0; i_vj < n_vjs; ++i_vj) { - tdata->vj_stoptimes[vj_index] = (stoptime_t *) malloc(sizeof(stoptime_t) * n_stops); + tdata->vj_stoptimes[vj_index] = (stoptime_t *) malloc(sizeof(stoptime_t) * n_sp); - for (i_stop = 0; i_stop < n_stops; ++i_stop) { + for (sp_index = 0; sp_index < n_sp; ++sp_index) { /* Initialise the realtime stoptimes */ - tdata->vj_stoptimes[vj_index][i_stop].arrival = UNREACHED; - tdata->vj_stoptimes[vj_index][i_stop].departure = UNREACHED; + tdata->vj_stoptimes[vj_index][sp_index].arrival = UNREACHED; + tdata->vj_stoptimes[vj_index][sp_index].departure = UNREACHED; } tdata->vjs[vj_index].begin_time = UNREACHED; @@ -180,9 +180,9 @@ static uint32_t tdata_new_journey_pattern(tdata_t *tdata, char *vj_ids, } /* housekeeping in tdata: increment for each new element */ - tdata->n_stop_times += n_stops; - tdata->n_journey_pattern_points += n_stops; - tdata->n_journey_pattern_point_attributes += n_stops; + tdata->n_stop_times += n_sp; + tdata->n_journey_pattern_points += n_sp; + tdata->n_journey_pattern_point_attributes += n_sp; tdata->n_vjs += n_vjs; tdata->n_vj_ids += n_vjs; tdata->n_vj_active += n_vjs; @@ -208,38 +208,38 @@ void tdata_apply_stop_time_update (tdata_t *tdata, uint32_t jp_index, uint32_t v char *stop_id = rt_stop_time_update->stop_id; if (stop_id) { - uint32_t stop_index = radixtree_find (tdata->stopid_index, stop_id); - if (tdata->journey_pattern_points[journey_pattern_point_offset] != stop_index && + uint32_t sp_index = radixtree_find (tdata->stopid_index, stop_id); + if (tdata->journey_pattern_points[journey_pattern_point_offset] != sp_index && tdata->journey_pattern_points[journey_pattern_point_offset] != NONE) { - tdata_rt_journey_patterns_at_stop_remove(tdata, tdata->journey_pattern_points[journey_pattern_point_offset], jp_index); + tdata_rt_journey_patterns_at_stop_point_remove(tdata, tdata->journey_pattern_points[journey_pattern_point_offset], jp_index); } /* TODO: Should this be communicated in GTFS-RT? */ tdata->journey_pattern_point_attributes[journey_pattern_point_offset] = (rsa_boarding | rsa_alighting); - tdata->journey_pattern_points[journey_pattern_point_offset] = stop_index; + tdata->journey_pattern_points[journey_pattern_point_offset] = sp_index; tdata_apply_gtfsrt_time (rt_stop_time_update, &tdata->vj_stoptimes[vj_index][rs]); - tdata_rt_journey_patterns_at_stop_append(tdata, stop_index, jp_index); + tdata_rt_journey_patterns_at_stop_point_append(tdata, sp_index, jp_index); journey_pattern_point_offset++; rs++; } } } - /* update the last stop to be alighting only */ + /* update the last stop_point to be alighting only */ tdata->journey_pattern_point_attributes[--journey_pattern_point_offset] = rsa_alighting; - /* update the first stop to be boarding only */ + /* update the first stop_point to be boarding only */ journey_pattern_point_offset = tdata->journey_patterns[jp_index].journey_pattern_point_offset; tdata->journey_pattern_point_attributes[journey_pattern_point_offset] = rsa_boarding; } -static void tdata_realtime_changed_journey_pattern(tdata_t *tdata, uint32_t vj_index, int16_t cal_day, uint16_t n_stops, TransitRealtime__TripUpdate *rt_trip_update) { +static void tdata_realtime_changed_journey_pattern(tdata_t *tdata, uint32_t vj_index, int16_t cal_day, uint16_t n_sp, TransitRealtime__TripUpdate *rt_trip_update) { TransitRealtime__TripDescriptor *rt_trip = rt_trip_update->trip; journey_pattern_t *jp_new = NULL; char *vj_id_new; uint32_t jp_index; - /* Don't ever continue if we found that n_stops == 0. */ - if (n_stops == 0) return; + /* Don't ever continue if we found that n_sp == 0. */ + if (n_sp == 0) return; #ifdef RRRR_DEBUG fprintf (stderr, "WARNING: this is a changed journey_pattern!\n"); @@ -257,21 +257,21 @@ static void tdata_realtime_changed_journey_pattern(tdata_t *tdata, uint32_t vj_i if (jp_index != RADIXTREE_NONE) { /* Fixes the case where a vj changes a second time */ jp_new = &tdata->journey_patterns[jp_index]; - if (jp_new->n_stops != n_stops) { - uint32_t i_stop_index; + if (jp_new->n_stops != n_sp) { + uint32_t sp_index; #ifdef RRRR_DEBUG fprintf (stderr, "WARNING: this is changed vehicle_journey %s being CHANGED again!\n", vj_id_new); #endif - tdata->vj_stoptimes[jp_new->vj_ids_offset] = (stoptime_t *) realloc(tdata->vj_stoptimes[jp_new->vj_ids_offset], sizeof(stoptime_t) * n_stops); + tdata->vj_stoptimes[jp_new->vj_offset] = (stoptime_t *) realloc(tdata->vj_stoptimes[jp_new->vj_offset], sizeof(stoptime_t) * n_sp); /* Only initialises if the length of the list increased */ - for (i_stop_index = jp_new->n_stops; - i_stop_index < n_stops; - ++i_stop_index) { - tdata->journey_pattern_points[jp_new->journey_pattern_point_offset + i_stop_index] = NONE; + for (sp_index = jp_new->n_stops; + sp_index < n_sp; + ++sp_index) { + tdata->journey_pattern_points[jp_new->journey_pattern_point_offset + sp_index] = NONE; } - jp_new->n_stops = n_stops; + jp_new->n_stops = n_sp; } } @@ -286,7 +286,7 @@ static void tdata_realtime_changed_journey_pattern(tdata_t *tdata, uint32_t vj_i /* we fork a new journey_pattern with all of its old properties * having one single vj, which is the modification. */ - jp_index = tdata_new_journey_pattern(tdata, vj_id_new, n_stops, 1, + jp_index = tdata_new_journey_pattern(tdata, vj_id_new, n_sp, 1, jp->attributes, jp->headsign_offset, jp->agency_index, @@ -299,7 +299,7 @@ static void tdata_realtime_changed_journey_pattern(tdata_t *tdata, uint32_t vj_i * NOTE: if we would have allocated multiple vehicle_journeys this * should be a for loop over n_vjs. */ - vj_index = jp_new->vj_ids_offset; + vj_index = jp_new->vj_offset; for (i_vj = 0; i_vj < 1; ++i_vj) { tdata->vjs[vj_index].vj_attributes = vj->vj_attributes; @@ -309,7 +309,7 @@ static void tdata_realtime_changed_journey_pattern(tdata_t *tdata, uint32_t vj_i } /* Restore the first vj_index again */ - vj_index = jp_new->vj_ids_offset; + vj_index = jp_new->vj_offset; } tdata_apply_stop_time_update (tdata, jp_index, vj_index, rt_trip_update); @@ -317,14 +317,14 @@ static void tdata_realtime_changed_journey_pattern(tdata_t *tdata, uint32_t vj_i /* being blissfully naive, a journey_pattern having only one vehicle_journey, * will have the same start and end time as its vehicle_journey */ - jp_new->min_time = tdata->vj_stoptimes[jp_new->vj_ids_offset][0].arrival; + jp_new->min_time = tdata->vj_stoptimes[jp_new->vj_offset][0].arrival; jp_new->max_time = tdata->vj_stoptimes[vj_index][jp_new->n_stops - 1].departure; } -static void tdata_realtime_journey_pattern_type(TransitRealtime__TripUpdate *rt_trip_update, uint16_t *n_stops, bool *changed_jp, bool *nodata_jp) { +static void tdata_realtime_journey_pattern_type(TransitRealtime__TripUpdate *rt_trip_update, uint16_t *n_sp, bool *changed_jp, bool *nodata_jp) { size_t i_stu; - *n_stops = 0; + *n_sp = 0; *changed_jp = false; *nodata_jp = true; @@ -337,7 +337,7 @@ static void tdata_realtime_journey_pattern_type(TransitRealtime__TripUpdate *rt_ rt_stop_time_update->schedule_relationship == TRANSIT_REALTIME__TRIP_UPDATE__STOP_TIME_UPDATE__SCHEDULE_RELATIONSHIP__SKIPPED); *nodata_jp &= (rt_stop_time_update->schedule_relationship == TRANSIT_REALTIME__TRIP_UPDATE__STOP_TIME_UPDATE__SCHEDULE_RELATIONSHIP__NO_DATA); - *n_stops += (rt_stop_time_update->schedule_relationship != TRANSIT_REALTIME__TRIP_UPDATE__STOP_TIME_UPDATE__SCHEDULE_RELATIONSHIP__SKIPPED && + *n_sp += (rt_stop_time_update->schedule_relationship != TRANSIT_REALTIME__TRIP_UPDATE__STOP_TIME_UPDATE__SCHEDULE_RELATIONSHIP__SKIPPED && rt_stop_time_update->stop_id != NULL); } } @@ -375,14 +375,14 @@ static void tdata_realtime_apply_tripupdates (tdata_t *tdata, uint32_t vj_index, for (i_stu = 0; i_stu < rt_trip_update->n_stop_time_update; ++i_stu) { spidx_t *journey_pattern_points = tdata->journey_pattern_points + jp->journey_pattern_point_offset; char *stop_id; - uint32_t stop_index; + uint32_t sp_index; rt_stop_time_update = rt_trip_update->stop_time_update[i_stu]; stop_id = rt_stop_time_update->stop_id; - stop_index = radixtree_find (tdata->stopid_index, stop_id); + sp_index = radixtree_find (tdata->stopid_index, stop_id); - if (journey_pattern_points[rs] == stop_index) { + if (journey_pattern_points[rs] == sp_index) { if (rt_stop_time_update->schedule_relationship == TRANSIT_REALTIME__TRIP_UPDATE__STOP_TIME_UPDATE__SCHEDULE_RELATIONSHIP__SCHEDULED) { tdata_apply_gtfsrt_time (rt_stop_time_update, &tdata->vj_stoptimes[vj_index][rs]); } @@ -393,8 +393,8 @@ static void tdata_realtime_apply_tripupdates (tdata_t *tdata, uint32_t vj_index, /* we do not align up with the realtime messages */ if (rt_stop_time_update->schedule_relationship == TRANSIT_REALTIME__TRIP_UPDATE__STOP_TIME_UPDATE__SCHEDULE_RELATIONSHIP__SCHEDULED) { uint32_t propagate = rs; - while (journey_pattern_points[++rs] != stop_index && rs < jp->n_stops); - if (journey_pattern_points[rs] == stop_index) { + while (journey_pattern_points[++rs] != sp_index && rs < jp->n_stops); + if (journey_pattern_points[rs] == sp_index) { if (rt_stop_time_update_prev) { if (rt_stop_time_update_prev->schedule_relationship == TRANSIT_REALTIME__TRIP_UPDATE__STOP_TIME_UPDATE__SCHEDULE_RELATIONSHIP__SCHEDULED && rt_stop_time_update_prev->departure && rt_stop_time_update_prev->departure->has_delay) { @@ -406,7 +406,7 @@ static void tdata_realtime_apply_tripupdates (tdata_t *tdata, uint32_t vj_index, } tdata_apply_gtfsrt_time (rt_stop_time_update, &tdata->vj_stoptimes[vj_index][rs]); } else { - /* we couldn't find the stop at all */ + /* we couldn't find the stop_point at all */ rs = propagate; } rs++; @@ -441,12 +441,12 @@ bool tdata_alloc_expanded(tdata_t *td) { for (i_jp = 0; i_jp < td->n_journey_patterns; ++i_jp) { uint32_t i_vj; for (i_vj = 0; i_vj < td->journey_patterns[i_jp].n_vjs; ++i_vj) { - td->vjs_in_journey_pattern[td->journey_patterns[i_jp].vj_ids_offset + i_vj] = + td->vjs_in_journey_pattern[td->journey_patterns[i_jp].vj_offset + i_vj] = i_jp; } } - td->rt_journey_patterns_at_stop = (list_t **) calloc(td->n_stops, sizeof(list_t *)); + td->rt_journey_patterns_at_stop_point = (list_t **) calloc(td->n_stop_points, sizeof(list_t *)); td->vj_active_orig = (calendar_t *) malloc(sizeof(calendar_t) * td->n_vjs); @@ -458,7 +458,7 @@ bool tdata_alloc_expanded(tdata_t *td) { memcpy (td->journey_pattern_active_orig, td->journey_pattern_active, sizeof(calendar_t) * td->n_journey_patterns); - if (!td->rt_journey_patterns_at_stop) return false; + if (!td->rt_journey_patterns_at_stop_point) return false; return true; } @@ -475,15 +475,15 @@ void tdata_free_expanded(tdata_t *td) { free (td->vj_stoptimes); } - if (td->rt_journey_patterns_at_stop) { - uint32_t i_stop; - for (i_stop = 0; i_stop < td->n_stops; ++i_stop) { - if (td->rt_journey_patterns_at_stop[i_stop]) { - free (td->rt_journey_patterns_at_stop[i_stop]->list); + if (td->rt_journey_patterns_at_stop_point) { + uint32_t i_sp; + for (i_sp = 0; i_sp < td->n_stop_points; ++i_sp) { + if (td->rt_journey_patterns_at_stop_point[i_sp]) { + free (td->rt_journey_patterns_at_stop_point[i_sp]->list); } } - free (td->rt_journey_patterns_at_stop); + free (td->rt_journey_patterns_at_stop_point); } free (td->vj_active_orig); diff --git a/tdata_validation.c b/tdata_validation.c index 7c5e219..78a9004 100644 --- a/tdata_validation.c +++ b/tdata_validation.c @@ -65,21 +65,21 @@ int tdata_validation_coordinates(tdata_t *tdata) { int32_t ret_invalid = 0; - uint32_t i_stop = tdata->n_stops; + uint32_t sp_index = tdata->n_stop_points; do { latlon_t ll; - i_stop--; + sp_index--; - ll = tdata->stop_coords[i_stop]; + ll = tdata->stop_point_coords[sp_index]; if (ll.lat < min_lat || ll.lat > max_lat || ll.lon < min_lon || ll.lon > max_lon) { fprintf (stderr, "stop lat/lon out of range: lat=%f, lon=%f \n", ll.lat, ll.lon); ret_invalid--; } - } while (i_stop); + } while (sp_index); return ret_invalid; } @@ -89,11 +89,11 @@ int tdata_validation_coordinates(tdata_t *tdata) { */ int tdata_validation_increasing_times(tdata_t *tdata) { - uint32_t jp_index, stop_index, vj_index; + uint32_t jp_index, sp_index, vj_index; int ret_nonincreasing = 0; for (jp_index = 0; jp_index < tdata->n_journey_patterns; ++jp_index) { journey_pattern_t jp = tdata->journey_patterns[jp_index]; - vehicle_journey_t *vjs = tdata->vjs + jp.vj_ids_offset; + vehicle_journey_t *vjs = tdata->vjs + jp.vj_offset; #ifdef RRRR_DEBUG /* statistics on errors, instead of early bail out */ @@ -104,8 +104,8 @@ int tdata_validation_increasing_times(tdata_t *tdata) { vehicle_journey_t vj = vjs[vj_index]; stoptime_t *st = tdata->stop_times + vj.stop_times_offset; stoptime_t *prev_st = NULL; - for (stop_index = 0; stop_index < jp.n_stops; ++stop_index) { - if (stop_index == 0 && st->arrival != 0) { + for (sp_index = 0; sp_index < jp.n_stops; ++sp_index) { + if (sp_index == 0 && st->arrival != 0) { fprintf (stderr, "timedemand type begins at %d,%d not 0.\n", st->arrival, st->departure); @@ -117,7 +117,7 @@ int tdata_validation_increasing_times(tdata_t *tdata) { if (st->departure < st->arrival) { fprintf (stderr, "departure before arrival at " "journey_pattern %d, vj %d, stop %d.\n", - jp_index, vj_index, stop_index); + jp_index, vj_index, sp_index); #ifndef RRRR_DEBUG return -1; #endif @@ -133,7 +133,7 @@ int tdata_validation_increasing_times(tdata_t *tdata) { fprintf (stderr, "negative travel time arriving at " "journey_pattern %d, vj %d (%s), stop %d.\n", jp_index, vj_index, - vj_id, stop_index); + vj_id, sp_index); #if 0 fprintf (stderr, "(%d, %d) -> (%d, %d)\n", prev_st->arrival, prev_st->departure, @@ -149,7 +149,7 @@ int tdata_validation_increasing_times(tdata_t *tdata) { #if 0 fprintf (stderr, "last departure equals arrival at " "journey_pattern %d, vj %d, stop %d.\n", - jp_index, vj_index, stop_index); + jp_index, vj_index, sp_index); #ifdef RRRR_DEBUG n_nonincreasing_vjs += 1; @@ -179,41 +179,41 @@ int tdata_validation_increasing_times(tdata_t *tdata) { */ int tdata_validation_symmetric_transfers(tdata_t *tdata) { int n_transfers_checked = 0; - uint32_t stop_index_from; - for (stop_index_from = 0; - stop_index_from < tdata->n_stops; - ++stop_index_from) { - - /* Iterate over all transfers going out of this stop */ - uint32_t t = tdata->stops[stop_index_from ].transfers_offset; - uint32_t tN = tdata->stops[stop_index_from + 1].transfers_offset; + uint32_t sp_index_from; + for (sp_index_from = 0; + sp_index_from < tdata->n_stop_points; + ++sp_index_from) { + + /* Iterate over all transfers going out of this stop_point */ + uint32_t t = tdata->stop_points[sp_index_from].transfers_offset; + uint32_t tN = tdata->stop_points[sp_index_from + 1].transfers_offset; for ( ; t < tN ; ++t) { - uint32_t stop_index_to = tdata->transfer_target_stops[t]; + uint32_t sp_index_to = tdata->transfer_target_stops[t]; uint32_t forward_distance = tdata->transfer_dist_meters[t] << 4; /* actually in units of 2^4 == 16 meters */ - /* Find the reverse transfer (stop_index_to -> stop_index_from) */ - uint32_t u = tdata->stops[stop_index_to ].transfers_offset; - uint32_t uN = tdata->stops[stop_index_to + 1].transfers_offset; + /* Find the reverse transfer (sp_index_to -> sp_index_from) */ + uint32_t u = tdata->stop_points[sp_index_to].transfers_offset; + uint32_t uN = tdata->stop_points[sp_index_to + 1].transfers_offset; bool found_reverse = false; - if (stop_index_to == stop_index_from) { - fprintf (stderr, "loop transfer from/to stop %d.\n", - stop_index_from); + if (sp_index_to == sp_index_from) { + fprintf (stderr, "loop transfer from/to stop_point %d.\n", + sp_index_from); } for ( ; u < uN ; ++u) { n_transfers_checked += 1; - if (tdata->transfer_target_stops[u] == stop_index_from) { + if (tdata->transfer_target_stops[u] == sp_index_from) { /* this is the same transfer in reverse */ uint32_t reverse_distance = tdata->transfer_dist_meters[u] << 4; if (reverse_distance != forward_distance) { - fprintf (stderr, "transfer from %d to %d is " + fprintf (stderr, "transfer from_stop_point %d to %d is " "not symmetric. " "forward distance is %d, " "reverse distance is %d.\n", - stop_index_from, - stop_index_to, + sp_index_from, + sp_index_to, forward_distance, reverse_distance); } @@ -222,9 +222,9 @@ int tdata_validation_symmetric_transfers(tdata_t *tdata) { } } if ( ! found_reverse) { - fprintf (stderr, "transfer from %d to %d does not have " + fprintf (stderr, "transfer from_stop_point %d to %d does not have " "an equivalent reverse transfer.\n", - stop_index_from, stop_index_to); + sp_index_from, sp_index_to); return -1; } } @@ -235,13 +235,13 @@ int tdata_validation_symmetric_transfers(tdata_t *tdata) { return 0; } -static bool tdata_validation_check_nstops (tdata_t *tdata) { - if (tdata->n_stops < 2) { - fprintf (stderr, "n_stops should be at least two, %d found.\n", tdata->n_stops); +static bool tdata_validation_check_nstop_points(tdata_t *tdata) { + if (tdata->n_stop_points < 2) { + fprintf (stderr, "n_stop_points should be at least two, %d found.\n", tdata->n_stop_points); return false; } else - if (tdata->n_stops > ONBOARD) { - fprintf (stderr, "n_stops %d exceeds compiled spidx_t width.\n", tdata->n_stops); + if (tdata->n_stop_points > ONBOARD) { + fprintf (stderr, "n_stop_points %d exceeds compiled spidx_t width.\n", tdata->n_stop_points); return false; } @@ -251,7 +251,7 @@ static bool tdata_validation_check_nstops (tdata_t *tdata) { bool tdata_validation_check_coherent (tdata_t *tdata) { fprintf (stderr, "checking tdata coherency...\n"); - return (tdata_validation_check_nstops(tdata) && + return (tdata_validation_check_nstop_points(tdata) && tdata->n_journey_patterns > 0 && tdata_validation_boarding_alighting(tdata) == 0 && tdata_validation_coordinates(tdata) == 0 &&