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

matrix pbf output #4121

Merged
merged 19 commits into from
Jul 4, 2023
Merged

matrix pbf output #4121

merged 19 commits into from
Jul 4, 2023

Conversation

nilsnolde
Copy link
Member

@nilsnolde nilsnolde commented May 21, 2023

fixes #3867
fixes #4153

Next up: isochrones.

}

MatrixType matrix_type = MatrixType::Cost;
Matrix::Algorithm matrix_algo = Matrix::CostMatrix;
Copy link
Member Author

Choose a reason for hiding this comment

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

I removed the MatrixType enum we kept around and replaced it with the PBF's one.

Comment on lines -283 to -287
/**
* Form a time/distance matrix from the results.
* @return Returns a time distance matrix among locations.
*/
std::vector<TimeDistance> FormTimeDistanceMatrix();
Copy link
Member Author

@nilsnolde nilsnolde May 21, 2023

Choose a reason for hiding this comment

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

it never had a function like this implemented (or well, at least after the recent PRs)

proto/matrix.proto Outdated Show resolved Hide resolved
@nilsnolde
Copy link
Member Author

I took @SiarheiFedartsou 's suggestion and changed the proto definition to be "flat" vectors of the matrix attributes (times, dists etc), instead of a TimeDistance message "wrapper", so the int vectors can be packed.

I also finished the forward vs reverse output order.

Comment on lines +579 to +581
auto date_time =
get_date_time(origin_dt, origin_tz, pred_id, reader, static_cast<uint64_t>(time));
out_date_times[pbf_idx] = date_time;
Copy link
Member Author

@nilsnolde nilsnolde Jun 8, 2023

Choose a reason for hiding this comment

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

this pisses me off a bit.. we can't use the Resize() and Set() syntax for the string repeated fields, protobuf has no such concept for those.. I didn't really know how to do it any better, so:

  • before we expand the sources or targets, we initialize an empty std::vector<std::string>, which we pass into this function for every source or target forming
  • here we set the date_time string on the right index
  • after we're all done with all expansions, we go over this vector and populate the PBF's date_times

Any suggestion on how to make it less ugly is welcome.

Comment on lines +176 to +179
std::vector<std::vector<uint32_t>> matrix_answers = {{28, 28}, {2027, 1837}, {2403, 2213}, {4163, 3838},
{1519, 1398}, {1808, 1638}, {2061, 1951}, {3944, 3639},
{2311, 2111}, {701, 641}, {0, 0}, {2821, 2626},
{5562, 5177}, {3952, 3707}, {4367, 4107}, {1825, 1680}};
Copy link
Member Author

Choose a reason for hiding this comment

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

some human-healthier formatting :)

Comment on lines +258 to +273
TEST(Matrix, test_timedistancematrix_forward) {
// Input request is the same as `test_request`, but without the last target
const auto test_request_more_sources = R"({
"sources":[
{"lat":52.106337,"lon":5.101728},
{"lat":52.111276,"lon":5.089717},
{"lat":52.103105,"lon":5.081005}
],
"targets":[
{"lat":52.106126,"lon":5.101497},
{"lat":52.100469,"lon":5.087099},
{"lat":52.103105,"lon":5.081005},
{"lat":52.094273,"lon":5.075254}
],
"costing":"auto"
})";
Copy link
Member Author

Choose a reason for hiding this comment

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

added a test for #4153

Choose a reason for hiding this comment

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

The bug in #4153 only occurred with the bicycle profile, the auto profile worked fine. Does that matter for your test/fix?

Copy link
Member Author

Choose a reason for hiding this comment

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

Jep that's fine. Over the API we decide internally which matrix algo to use. In your case that was TDMatrix, for auto it's always CostMatrix. This test uses TDMatrix deliberately. Good point though!

Comment on lines +345 to +348
std::vector<std::vector<uint32_t>> expected_results = {{28, 28}, {2027, 1837}, {2403, 2213},
{1519, 1398}, {1808, 1638}, {2061, 1951},
{2311, 2111}, {701, 641}, {0, 0},
{5562, 5177}, {3952, 3707}, {4367, 4107}};
Copy link
Member Author

Choose a reason for hiding this comment

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

only changed formatting

}
}

// TODO: it was commented before. Why?
TEST(Matrix, DISABLED_test_matrix_osrm) {
TEST(Matrix, test_matrix_osrm) {
Copy link
Member Author

@nilsnolde nilsnolde Jun 9, 2023

Choose a reason for hiding this comment

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

to increase coverage, I test the OSRM matrix format properly. I guess the reason why it disabled was because it wasn't set up to actually test OSRM format, it just looked at the raw time/distances, not at the json output

kevinkreiser
kevinkreiser previously approved these changes Jul 4, 2023
@nilsnolde nilsnolde merged commit d6d2d48 into master Jul 4, 2023
8 checks passed
@nilsnolde nilsnolde deleted the nn-matrix-pbf branch July 4, 2023 14:32
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.

Multiple sources to sources_to_targets only returns valid result for first source. Matrix output in PBF
4 participants