-
Notifications
You must be signed in to change notification settings - Fork 661
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
Conversation
…e separate mmap for traffic.
namespace valhalla { | ||
namespace baldr { | ||
namespace traffic { | ||
struct Speed { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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
…exposed, and can be reset for test cases.
…binding generation with other languages.
@@ -390,8 +413,12 @@ const GraphTile* GraphReader::GetGraphTile(const GraphId& graphid) { | |||
return nullptr; | |||
} | |||
|
|||
auto traffic_ptr = tile_extract_->traffic_tiles.find(base); |
There was a problem hiding this comment.
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
src/sif/autocost.cc
Outdated
@@ -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)) |
There was a problem hiding this comment.
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
src/baldr/graphreader.cc
Outdated
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 |
There was a problem hiding this comment.
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?
…edgeid directly to reduce the work done by the check.
…why it's safe to do nothing on an exception here.
…t accidentally changed
// 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/ofer/over
@kevinkreiser That windows build failure looks like a compiler bug: Should I put some effort into working around it? |
@danpat at the very worst we can trivially implement those functions instead of using |
valhalla/baldr/traffictile.h
Outdated
const Speed getTrafficForDirectedEdge(const uint32_t directed_edge_offset) const { | ||
if (header == nullptr) | ||
return {}; | ||
assert(directed_edge_offset < header->directed_edge_count); |
There was a problem hiding this comment.
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.
valhalla/baldr/traffictile.h
Outdated
Tile(const Tile& other) = default; | ||
Tile& operator=(const Tile& other) = default; | ||
|
||
const Speed getTrafficForDirectedEdge(const uint32_t directed_edge_offset) const { |
There was a problem hiding this comment.
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
… into the Speed class for less repetitinon.
if (header == nullptr) | ||
return {}; | ||
return INVALID_SPEED; |
There was a problem hiding this comment.
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 😄
valhalla/baldr/graphtile.h
Outdated
@@ -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()); |
There was a problem hiding this comment.
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
…ems on x86_64), and add a couple more for future-proofing.
other than the |
Issue
These changes add support for looking at real-time traffic data when performing route calculations.
Tasklist
Requirements / Relations
Link any requirements here. Other pull requests this PR is based on?