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

Support live traffic data #2268

Merged
merged 33 commits into from
Mar 30, 2020
Merged

Support live traffic data #2268

merged 33 commits into from
Mar 30, 2020

Conversation

danpat
Copy link
Member

@danpat danpat commented Mar 11, 2020

Issue

These changes add support for looking at real-time traffic data when performing route calculations.

Tasklist

  • Add tests
  • Add #fixes with the issue number that this PR addresses
  • Generally use squash merge to rebase and clean comments before merging
  • Update the changelog

Requirements / Relations

Link any requirements here. Other pull requests this PR is based on?

src/baldr/graphreader.cc Outdated Show resolved Hide resolved
valhalla/baldr/traffictile.h Outdated Show resolved Hide resolved
valhalla/baldr/traffictile.h Outdated Show resolved Hide resolved
valhalla/baldr/traffictile.h Outdated Show resolved Hide resolved
namespace valhalla {
namespace baldr {
namespace traffic {
struct Speed {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we have some warning comments about any changes to the data layout has to be made with great care.

Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be useful with a unittest to verify that it stays a POD? https://en.cppreference.com/w/cpp/types/is_pod

Copy link
Member

Choose a reason for hiding this comment

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

we have tests like this for the regular tiles as well and yeah valhalla only increments major version when we make breaking changes to the structurs. this would be subject to the same thing

};

// per-speed-tile header
struct TileHeader {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same about warning comments here.

…ugs in TrafficTile initialization that the test uncovered.
…hat tests live-updating of the mmapp-ed traffic tar file (still WIP, no routing speed lookups implemented yet)
…ds. Still very much WIP, but modifying the live speeds file will update the router in-situ
@danpat danpat marked this pull request as ready for review March 27, 2020 01:50
@@ -390,8 +413,12 @@ const GraphTile* GraphReader::GetGraphTile(const GraphId& graphid) {
return nullptr;
}

auto traffic_ptr = tile_extract_->traffic_tiles.find(base);
Copy link
Member

Choose a reason for hiding this comment

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

in the future we will probably need to decouple the idea of flat file and memory mapped for graph and traffic tiles. it would be nice to fall back to flat files for traffic tiles as well and then to fall back to network calls etc. but all that can come once we figure something out for cache invalidation for traffic tiles from file vs memmap. i just wanted to point out the future work here is all, not asking for changes

@@ -391,6 +391,10 @@ bool AutoCost::Allowed(const baldr::DirectedEdge* edge,
const uint64_t current_time,
const uint32_t tz_index,
bool& has_time_restrictions) const {

if (tile->IsClosedDueToTraffic(edge))
Copy link
Member

@kevinkreiser kevinkreiser Mar 27, 2020

Choose a reason for hiding this comment

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

we need to add this to many more costings, all the others in this file (unless they all call this function via inheritance) as well as all in motorcycle, motorscooter and truck

auto id = GraphTile::GetTileId(c.first);
tiles[id] = std::make_pair(const_cast<char*>(c.second.first), c.second.second);
} catch (...) {
// skip files we dont understand
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we at least warn about there being things we don't understand?

// Traffic data works like this:
// 1. There is a separate .tar file containing tile entries matching the main tiles
// 2. Each tile is a fixed-size, with a header, and entries
// This loop iterates ofer the routing tiles, and creates blank
Copy link
Contributor

Choose a reason for hiding this comment

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

s/ofer/over

@danpat
Copy link
Member Author

danpat commented Mar 28, 2020

@kevinkreiser That windows build failure looks like a compiler bug:

https://developercommunity.visualstudio.com/content/problem/468431/error-c2580-multiple-versions-of-a-defaulted-speci.html

Should I put some effort into working around it?

@kevinkreiser
Copy link
Member

@danpat at the very worst we can trivially implement those functions instead of using default. i actually wondered why we needed the functions in the structs at all. both speed and incident can be initialized with {}. in practice all of these data structures are read-only so it must be just for the tests?

const Speed getTrafficForDirectedEdge(const uint32_t directed_edge_offset) const {
if (header == nullptr)
return {};
assert(directed_edge_offset < header->directed_edge_count);
Copy link
Member

Choose a reason for hiding this comment

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

we should throw here that way a running server will catch and return an error rather than crash and burn.

Tile(const Tile& other) = default;
Tile& operator=(const Tile& other) = default;

const Speed getTrafficForDirectedEdge(const uint32_t directed_edge_offset) const {
Copy link
Member

Choose a reason for hiding this comment

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

index would be a more consistent name than offset here

if (header == nullptr)
return {};
return INVALID_SPEED;
Copy link
Member

Choose a reason for hiding this comment

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

haha this is exactly what i did in my attempt earlier today to change this locally 😄

@@ -594,9 +594,9 @@ class GraphTile {
inline bool IsClosedDueToTraffic(const GraphId& edge_id) const {
if (!traffic_tile())
return false;
auto live_speed = traffic_tile.getTrafficForDirectedEdge(edge_id.id());
auto& live_speed = traffic_tile.getTrafficForDirectedEdge(edge_id.id());
Copy link
Member

Choose a reason for hiding this comment

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

technically this auto includes volatile right? nitpick but it wouldnt hurt to put it just for understandings sake or easy readabiltiy

@kevinkreiser
Copy link
Member

other than the assert this looks ready to go!

@danpat danpat merged commit 5f5588f into master Mar 30, 2020
@danpat danpat deleted the danpat_live_traffic branch March 30, 2020 17:49
yuzheyan added a commit that referenced this pull request Mar 31, 2020
* master:
  Support live traffic data (#2268)
  Update CHANGELOG.md
  Properly utilize CircleCI caches per build (#2288)
  Time allowed updates & Gurka Conditional Restrictions Test (#2286)
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

4 participants