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

Refactor matrix_action #4535

Merged
merged 15 commits into from Jan 31, 2024
Merged

Refactor matrix_action #4535

merged 15 commits into from Jan 31, 2024

Conversation

nilsnolde
Copy link
Member

@nilsnolde nilsnolde commented Jan 28, 2024

as a preparation to #4474

similar to routing algos, I created a base class for matrix algos and unified the main public SourceToTarget function. IMO the logic is a bit nicer now, but also it'll be much much easier to handle second passes this way.

I should add this is really a pure refactor, no functional change is intended.

kInitialEdgeLabelCountBidirDijkstra)),
clear_reserved_memory_(config.get<bool>("clear_reserved_memory", false)),
Copy link
Member Author

Choose a reason for hiding this comment

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

this is now in the base class

Comment on lines -136 to -138
const bool has_time,
const bool invariant,
const ShapeFormat& shape_format) {
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 pulled all these out of the signature and set them inside the function instead. was pointless to have them in the signature, it'll all in the request, except for has_time which is being set via the base class's set_has_time()

options.matrix_locations(),
options.date_time_type() == Options::invariant);
};
MatrixAlgorithm* thor_worker_t::get_matrix_algorithm(Api& request, const bool has_time) {
Copy link
Member Author

Choose a reason for hiding this comment

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

the diff in here is impossible to read. will show tmrw in code editor what's going on there. the basic gist is:

  • add a get_matrix_algorithm function to thor_worker_t (like for routing), to get the properties of that class
  • remove the lambdas for the matrix algos and decide here which one to use

&time_distance_matrix_,
&time_distance_bss_matrix_,
}) {
alg->set_interrupt(interrupt);
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 added the interrupt function now for all matrix algos finally

Comment on lines -11 to -13
namespace {
static bool IsTrivial(const uint64_t& edgeid,
const valhalla::Location& origin,
Copy link
Member Author

Choose a reason for hiding this comment

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

this was duplicated with the exact same function in PathAlgorithm

@@ -2,7 +2,7 @@

#include "baldr/json.h"
#include "proto_conversions.h"
#include "thor/matrix_common.h"
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 also remove this header and pulled out what was there into the new header

@@ -220,7 +220,7 @@ TEST(Matrix, test_matrix) {
CostMatrix cost_matrix;
cost_matrix.SourceToTarget(request, reader, mode_costing, sif::TravelMode::kDrive, 400000.0);
auto matrix = request.matrix();
for (uint32_t i = 0; i < matrix.times().size(); ++i) {
for (int i = 0; i < matrix.times().size(); ++i) {
Copy link
Member Author

Choose a reason for hiding this comment

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

made this file warning-free

* @param origin Origin path location information.
* @param destination Destination path location information.
*/
inline bool IsTrivial(const baldr::GraphId& edgeid,
Copy link
Member Author

Choose a reason for hiding this comment

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

this is changed from a member function to an inline function

@nilsnolde
Copy link
Member Author

Also, in a further step, we could think about somehow merging PathAlgorithm with MatrixAlgorithm and also add a bit more common functionality around expansion details if possible, so we don't have to maintain so many places doing the same thing. That needs a lot more thought though, but is still kinda my end goal.

// if `true` clean reserved memory for edge labels
bool clear_reserved_memory_;

// resizes all PBF sequences except for date_times
Copy link
Contributor

Choose a reason for hiding this comment

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

stale comment

kevinkreiser
kevinkreiser previously approved these changes Jan 29, 2024
@nilsnolde
Copy link
Member Author

fixed the build @kevinkreiser , if you have a sec to re-approve

@nilsnolde nilsnolde mentioned this pull request Jan 29, 2024
4 tasks
@nilsnolde nilsnolde merged commit 4d3d896 into master Jan 31, 2024
9 checks passed
@nilsnolde nilsnolde deleted the nn-matrix-refactor branch January 31, 2024 13:45
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

3 participants