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

few matrix serializer fixes #4366

Merged
merged 7 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* FIXED: only recost matrix pairs which have connections found [#4344](https://github.com/valhalla/valhalla/pull/4344)
* FIXED: arm builds. tons of errors due to floating point issues mostly [#4213](https://github.com/valhalla/valhalla/pull/4213)
* FIXED: respond with correlated edges for format=valhalla and matrix [#4335](https://github.com/valhalla/valhalla/pull/4335)
* FIXED: `sources` & `targets` for verbose matrix response was kinda broken due to #4335 above [#4366](https://github.com/valhalla/valhalla/pull/4366)
* FIXED: recover proper shortest path to ferry connections (when multiple edges exist between node pair) [#4361](https://github.com/valhalla/valhalla/pull/4361)
* FIXED: recover proper shortest path to ferry connections (make sure correct label index is used) [#4378](https://github.com/valhalla/valhalla/pull/4378)
* FIXED: Allow all roads for motorcycles [#4348](https://github.com/valhalla/valhalla/pull/4348)
Expand Down
2 changes: 1 addition & 1 deletion src/tyr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ set(sources
actor.cc
height_serializer.cc
isochrone_serializer.cc
matrix_serializer.cc
serializers.cc
transit_available_serializer.cc)

set(sources_with_warnings
locate_serializer.cc
matrix_serializer.cc
route_serializer.cc
route_serializer_osrm.cc
route_serializer_valhalla.cc
Expand Down
18 changes: 8 additions & 10 deletions src/tyr/matrix_serializer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ std::string serialize(const Api& request) {
json->emplace("sources", osrm::waypoints(options.sources()));
json->emplace("destinations", osrm::waypoints(options.targets()));

for (size_t source_index = 0; source_index < options.sources_size(); ++source_index) {
for (int source_index = 0; source_index < options.sources_size(); ++source_index) {
time->emplace_back(serialize_duration(request.matrix(), source_index * options.targets_size(),
options.targets_size()));
distance->emplace_back(serialize_distance(request.matrix(), source_index * options.targets_size(),
Expand Down Expand Up @@ -89,10 +89,9 @@ json::ArrayPtr locations(const google::protobuf::RepeatedPtrField<valhalla::Loca
if (location.correlation().edges().size() == 0) {
input_locs->emplace_back(nullptr);
} else {
for (const auto& corr_edge : location.correlation().edges()) {
input_locs->emplace_back(json::map({{"lat", json::fixed_t{corr_edge.ll().lat(), 6}},
{"lon", json::fixed_t{corr_edge.ll().lng(), 6}}}));
}
auto& corr_ll = location.correlation().edges(0).ll();
input_locs->emplace_back(json::map(
{{"lat", json::fixed_t{corr_ll.lat(), 6}}, {"lon", json::fixed_t{corr_ll.lng(), 6}}}));
Comment on lines +92 to +94
Copy link
Member Author

Choose a reason for hiding this comment

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

changing it to only one correlated edge in the sources & targets response arrays

}
}
return input_locs;
Expand Down Expand Up @@ -136,22 +135,22 @@ std::string serialize(const Api& request, double distance_scale) {

if (options.verbose()) {
json::ArrayPtr matrix = json::array({});
for (size_t source_index = 0; source_index < options.sources_size(); ++source_index) {
for (int source_index = 0; source_index < options.sources_size(); ++source_index) {
matrix->emplace_back(serialize_row(request.matrix(), source_index * options.targets_size(),
options.targets_size(), source_index, 0, distance_scale));
}

json->emplace("sources_to_targets", matrix);

json->emplace("targets", json::array({locations(options.targets())}));
json->emplace("sources", json::array({locations(options.sources())}));
json->emplace("targets", locations(options.targets()));
json->emplace("sources", locations(options.sources()));
} // slim it down
else {
auto matrix = json::map({});
auto time = json::array({});
auto distance = json::array({});

for (size_t source_index = 0; source_index < options.sources_size(); ++source_index) {
for (int source_index = 0; source_index < options.sources_size(); ++source_index) {
time->emplace_back(serialize_duration(request.matrix(), source_index * options.targets_size(),
options.targets_size()));
distance->emplace_back(
Expand Down Expand Up @@ -186,7 +185,6 @@ namespace valhalla {
namespace tyr {

std::string serializeMatrix(Api& request) {
auto format = request.options().format();
double distance_scale = (request.options().units() == Options::miles) ? kMilePerMeter : kKmPerMeter;
switch (request.options().format()) {
case Options_Format_osrm:
Expand Down
1 change: 1 addition & 0 deletions test/gurka/test_matrix_time_dependent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ TEST_F(MatrixTest, CostMatrixWithLiveTraffic) {
res_doc.Parse(res.c_str());
check_matrix(res_doc, {0.0f, 2.8f, 2.8f, 0.0f}, true, Matrix::CostMatrix);
ASSERT_EQ(result.info().warnings().size(), 0);
res.erase();

// forward tree, date_time on the locations, 2nd location has pointless date_time
options = {{"/sources/0/date_time", "current"},
Expand Down
Loading