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

Add support for closure annotations #2816

Merged
merged 7 commits into from
Feb 23, 2021
Merged

Conversation

mandeepsandhu
Copy link
Contributor

Adds a new shape attribute filter for getting closure locations in the
directions response. Similar to incidents, each closure annotation has
a start & end geometry index, which indexes into the coordinates list.

@mandeepsandhu mandeepsandhu changed the title Add support for closure annotations DNM: Add support for closure annotations Jan 28, 2021
@mandeepsandhu mandeepsandhu marked this pull request as draft January 28, 2021 01:22
@mandeepsandhu mandeepsandhu changed the title DNM: Add support for closure annotations Add support for closure annotations Jan 28, 2021
@mandeepsandhu mandeepsandhu marked this pull request as ready for review January 28, 2021 08:01
// is still within an existing closure)
::valhalla::TripLeg_Closure* closure = fetch_or_create_closure_annotation(leg);
if (!closure->has_begin_shape_index()) {
closure->set_begin_shape_index(i - 1);
Copy link
Contributor

Choose a reason for hiding this comment

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

How come it's i - 1 and not just i?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since this loops starts from the 2nd shape index. It does that since we create cuts only if speed changes in subsequent shape segments.


namespace {

inline void SetLiveSpeedFrom(baldr::TrafficSpeed* live_speed, uint64_t speed, uint8_t subsegment) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Any chance subsegment argument can be renamed to breakpoint1 just to decrease number of terms describing the same thing?

Also, you're not setting the speed of the first subsegment here even though you do set the breakpoint1, is that intended? You may want to set speed1 to either unknown or 0 (or something else) for clarity

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Any chance subsegment argument can be renamed to breakpoint1 just to decrease number of terms describing the same thing?

Yeah, I can change subsegment to breakpoint1 (this was just me trying to reverse engg the TrafficSpeed struct and trying to make sense of what breakpoint meant 😛 ).

Also, you're not setting the speed of the first subsegment here even though you do set the breakpoint1, is that intended? You may want to set speed1 to either unknown or 0 (or something else) for clarity

So this function intends to set live speed to 0 starting from a particular subsegment/breakpoint of the edge. Anything before that should remain whatever value it previously had. TBH I arrived at the vlaues being set after a few iterations. Let me know if there's a better/correct/simpler way to do it. I want to partially close edges upto/from a certain percentage of the edge.

live_speed->speed3 = UNKNOWN_TRAFFIC_SPEED_RAW;
}

inline void SetLiveSpeedUpto(baldr::TrafficSpeed* live_speed, uint64_t speed, uint8_t subsegment) {
Copy link
Contributor

Choose a reason for hiding this comment

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

same note about name here

Copy link
Contributor

Choose a reason for hiding this comment

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

The speed datatype should probably be uint8_t too

Copy link
Contributor

Choose a reason for hiding this comment

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

How about overall_speed?

Copy link
Contributor

Choose a reason for hiding this comment

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

SetLiveSpeed below can probably be collapsed into this function if you set subsegment/breakpoint1 argument to default to 255?

Copy link
Contributor Author

@mandeepsandhu mandeepsandhu Feb 22, 2021

Choose a reason for hiding this comment

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

I'm not sure what overall_speed should be set to if its already populated (I do that when constructing the gurka map in the setup function) and we want to close only part of the edge. Thats why I left it as is, and also why I have a separate function for setting speed for the entire edge as it sets the overall_speed too.

Copy link
Contributor

@purew purew Feb 23, 2021

Choose a reason for hiding this comment

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

The most important is probably to set overall_speed to 0 if any of the subsegments have zero speed. That marks the edge as closed if a subsegment is closed. Apart from that, it's not used if you have any unknown subsegment.

}
}

void close_partial_dir_edge_upto(baldr::GraphReader& reader,
Copy link
Contributor

@purew purew Feb 18, 2021

Choose a reason for hiding this comment

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

Just an FYI:

There are some utility functions already for customizing live traffic like test::customize_live_traffic_data(map.config, cb_setter_max); as used in https://github.com/valhalla/valhalla/blob/master/test/gurka/test_traffic.cc#L56

Copy link
Contributor

Choose a reason for hiding this comment

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

Ohh I see that you are in fact using that below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yup 🙂

I added these functions here since I wanted partial closures. If this is reused elsewhere in the future, we could move it to the gurka module itself.

@@ -0,0 +1,327 @@
#include "gurka.h"
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 apply more compiler warnings to this file at https://github.com/valhalla/valhalla/blob/master/test/gurka/CMakeLists.txt#L14 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

totally! will add it

purew
purew previously approved these changes Feb 23, 2021
Adds a new shape attribute filter for getting closure locations in the
directions response. Similar to incidents, each closure annotation has
a start & end geometry index, which indexes into the coordinates list.
@mandeepsandhu mandeepsandhu merged commit 1ff1856 into master Feb 23, 2021
@purew purew deleted the closure_annotations branch February 24, 2021 13:52
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.

2 participants