Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes bug with inverted time-restriction parsing #2167

Merged
merged 2 commits into from
Jan 23, 2020
Merged

Conversation

purew
Copy link
Contributor

@purew purew commented Jan 16, 2020

The time-restriction parsing had a logic bug that meant permission
was allowed at restricted times and vice versa.

This commit also adds a unit-test to verify this functionality.

@purew purew force-pushed the test-time-restrictions branch 2 times, most recently from 9a4ad47 to 54641da Compare January 16, 2020 23:16
gknisely
gknisely previously approved these changes Jan 16, 2020
@@ -145,7 +145,8 @@ class ComplexRestrictionBuilder : public baldr::ComplexRestriction {

/**
* Set the dow mask. indicates days of week to apply the restriction
* @param dow day of week - This is a mask (e.g., Mo-Fr = 62).
* @param dow day of week - This is a mask with first day of week being sunday e.g., Mo-Fr = 62
* (111110).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think showing 1 bit for each day of week here will be a tad more helpful (0111110). Its easy to correlate days to bits then. Also, can we state which bit is Sunday, the MSB or LSB?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 @mandeepsandhu Updated

@purew
Copy link
Contributor Author

purew commented Jan 17, 2020

Hmm found something wonky with the logic. Investigating.

Ah it's not testing the kTimeAllowed branch. Let me fix that.

@kdiluca
Copy link
Member

kdiluca commented Jan 17, 2020

👍 Would love to get this merged so that I can pull into my branch! Thanks @purew

kdiluca
kdiluca previously approved these changes Jan 17, 2020
@purew purew dismissed kdiluca’s stale review January 17, 2020 16:07

(test) Logic still broken, working on fix

const uint8_t end_day_dow,
const uint64_t current_time,
const date::time_zone* time_zone) {
bool is_conditional_active(const bool type,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I renamed this function to better portray what it is actually doing.

@@ -78,8 +78,9 @@ add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/test/data/whitelion_tiles_reverse/
add_custom_target(reversed_whitelion_tiles DEPENDS ${CMAKE_BINARY_DIR}/test/data/whitelion_tiles_reverse/2/000/814/309.gph)

add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/test/data/roma_tiles/1/047/352.gph
COMMAND ${VALHALLA_SOURCE_DIR}/scripts/valhalla_build_timezones 2>/dev/null > test/data/roma_tiles/tz.sqlite
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure we add timezone information to the Roma tiles

// <tag k="auto" v="yes"/>
// <tag k="motor_vehicle:conditional" v="no @ (Mo-Sa 07:00-16:00)"/>
// <tag k="pedestrian" v="no"/>
// <tag k="pedestrian:conditional" v="yes @ (Mo-Sa 08:00-15:00)"/>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to tweak the tags manually in the osm-file in order to get the permutations of test-cases I needed.

Conditionals dropped here for clarity.

cr->end_day_dow(), current_time,
baldr::DateTime::get_tz_db().from_index(tz_index))) {
LOGLN_WARN("Restricted: " + std::to_string(cr->begin_hrs()));
// TODO Possibly a bug here. Shouldn't both kTimedDenied and kTimedAllowed
Copy link
Contributor Author

@purew purew Jan 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There may be a latent bug here. I haven't dug too closely but I would assume we should be handling both cases as is done in IsRestricted here.

cr->begin_day_dow(), cr->end_week(), cr->end_month(),
cr->end_day_dow(), current_time,
baldr::DateTime::get_tz_db().from_index(tz_index))) {
LOGLN_WARN("Restricted: " + std::to_string(cr->begin_hrs()));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO Remove stray debug log line.

gknisely
gknisely previously approved these changes Jan 17, 2020
@purew
Copy link
Contributor Author

purew commented Jan 17, 2020

Hmm there is some race condition in the tile building stage that occurs in CI but almost never locally...

@@ -148,8 +148,6 @@ inline bool TimeDepForward::ExpandForwardInner(GraphReader& graphreader,
const valhalla::Location& destination,
std::pair<int32_t, float>& best_path) {

LOG_WARN(std::string("Expanding edge_id ") + std::to_string(meta.edge_id.id()) + " from node " +
std::to_string(pred.endnode().id()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh man! that was unfortunate!

@purew purew force-pushed the test-time-restrictions branch 2 times, most recently from bdeb106 to 1c42234 Compare January 22, 2020 21:47
@purew
Copy link
Contributor Author

purew commented Jan 22, 2020

I removed the changes to the scripts/valhalla_build_timezones and now the circleci osx tests pass. Other osx environments seem to not exhibit the same bug.

${VALHALLA_SOURCE_DIR}/test/data/utrecht_netherlands.osm.pbf
COMMAND ${CMAKE_BINARY_DIR}/valhalla_add_predicted_traffic
--inline-config '{"mjolnir":{"tile_dir":"test/data/utrecht_tiles","concurrency":4,"logging":{"type":""}}}'
--inline-config '{"mjolnir":{"tile_dir":"test/data/utrecht_tiles","concurrency":1,"logging":{"type":""}}}'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was setting the concurrency to 1 needed to get the tests to build?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm This was a leftover from trying out all the various things.

That said, we are now building 5 different tile-sets on a full test-run and there are more pbf's being added in a different PR. 5 tilesets with 4 threads each results in 20 running threads.

It may just be best to do this single threaded.


void test_route_allowed(std::string costing_str, int16_t hour) {
auto response = route_on_timerestricted(costing_str, hour);
const auto& legs = response.trip().routes(0).legs();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like legs is unused here. Did you plan to add an assertion here like legs.size() == 1 ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this throwing a warning for unused variable? Or maybe it is and its getting lost in the noise?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pushed new code to test for legs.size() == 1

Copy link
Contributor Author

@purew purew Jan 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this throwing a warning for unused variable? Or maybe it is and its getting lost in the noise?

We're not yet treating all warnings as errors unfortunately.

The time-restriction parsing had a logic bug that meant permission
was allowed at restricted times and vice versa.

This commit also adds a unit-test to verify this functionality.
to only do the generation work once
Copy link
Collaborator

@danpaz danpaz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@purew purew merged commit d2e656b into master Jan 23, 2020
@purew purew deleted the test-time-restrictions branch February 13, 2020 19:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants