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

Landmark Routing 6 PR: Update narrative generation with landmarks #4301

Open
wants to merge 15 commits into
base: master
Choose a base branch
from

Conversation

vesperlou
Copy link
Contributor

@vesperlou vesperlou commented Sep 19, 2023

Issue

Update narrative generation process to support the use of landmarks in text guidance.

Tasklist

  • Update the maneuver types in locales to support landmark replacements. (update the en-us one, and wait for translations)
  • Update the narrative generation to pick phrases that support the use of landmarks.
  • Update tests and the changelog accordingly.

Requirements / Relations

Landmark Routing 6: Narrative Generation Updates #4138

@nilsnolde
Copy link
Member

nilsnolde commented Sep 20, 2023

Reminder to ourselves: since we're updating (possibly) stale translation files here, we should first pull whatever transifex has currently, merge to master, then merge master in this PR, to avoid tons of conflicts. Let's do that right before merging in a few weeks.

@@ -2036,6 +2188,7 @@
"6": "Make a <RELATIVE_DIRECTION> U-turn at <JUNCTION_NAME>.",
"7": "Make a <RELATIVE_DIRECTION> U-turn toward <TOWARD_SIGN>."
},
"landmark_types": [],
Copy link
Member

Choose a reason for hiding this comment

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

for u-turn we also want landmark narratives

@@ -4531,6 +4581,52 @@ NarrativeBuilder::FormRelativeThreeDirection(DirectionsLeg_Maneuver_Type type,
}
}

std::string NarrativeBuilder::FormLandmarkType(RouteLandmark_Type type,
Copy link
Member

Choose a reason for hiding this comment

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

instead of this function, we can cast the RouteLandmark_Type to uint8_t and index into the phrases directly

// close, than we pick the nearest left handed one.
valhalla::RouteLandmark select_landmark(const std::vector<valhalla::RouteLandmark>& landmarks,
const std::string& relative_direction) {
bool direction = relative_direction == "right" ? 1 : 0;
Copy link
Member

@nilsnolde nilsnolde Sep 20, 2023

Choose a reason for hiding this comment

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

Suggested change
bool direction = relative_direction == "right" ? 1 : 0;
bool turn_direction = relative_direction == "right";

Comment on lines 54 to 70
int idx = -1;
double min_dist = -1;
for (auto i = 0; i < landmarks.size(); ++i) {
// adjust landmark distance with compensation based on their direction
auto dist = landmarks[i].right() == direction
? landmarks[i].distance()
: (landmarks[i].distance() + kLandmarkOppositeDirectionCompensation);
if (idx == -1) {
idx = i;
min_dist = dist;
} else if (dist < min_dist) {
idx = i;
min_dist = dist;
}
}
return landmarks[idx];
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
int idx = -1;
double min_dist = -1;
for (auto i = 0; i < landmarks.size(); ++i) {
// adjust landmark distance with compensation based on their direction
auto dist = landmarks[i].right() == direction
? landmarks[i].distance()
: (landmarks[i].distance() + kLandmarkOppositeDirectionCompensation);
if (idx == -1) {
idx = i;
min_dist = dist;
} else if (dist < min_dist) {
idx = i;
min_dist = dist;
}
}
return landmarks[idx];
}
size_t idx = 0;
double min_dist = std::numeric_limits<double>::max();
for (auto i = 0; i < landmarks.size(); i++) {
// adjust landmark distance with compensation based on their direction
auto dist = landmarks[i].right() == direction
? landmarks[i].distance()
: (landmarks[i].distance() + kLandmarkOppositeDirectionCompensation);
if (dist < min_dist) {
idx = i;
min_dist = dist;
}
}
return landmarks[idx];
}

Comment on lines 1205 to 1210
// Make sure the landmark type is legal
if (static_cast<int>(landmark.type()) > 0 &&
static_cast<int>(landmark.type()) < subset->landmark_types.size()) {
// increment the phrase id by 6 to get the corresponding landmark phrase
phrase_id += 6;
}
Copy link
Member

Choose a reason for hiding this comment

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

IMO we don't need a check like this, bcs we're in full control of the landmark types and we do make sure in the data building pipeline that nothing enters that's outside of the type bounds. If we want to check this at this point, then let's throw an exception, bcs that'd be a very serious flaw.

…ot added in case of lack of vacancy, and inconsistent input in valhalla_add_landmarks and AddLandmarks
@vesperlou vesperlou changed the title Update narrative generation with landmarks Landmark Routing 6 PR: Update narrative generation with landmarks Sep 21, 2023
@nilsnolde
Copy link
Member

One thing we noticed is that the overall graph size is shrinking after adding landmarks.

@@ -51,7 +49,7 @@ int main(int argc, char** argv) {
valhalla::midgard::logging::Configure(logging_config);
}

if (!valhalla::mjolnir::AddLandmarks(pt.get_child("mjolnir"))) {
if (!valhalla::mjolnir::AddLandmarks(pt)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Suggested change
if (!valhalla::mjolnir::AddLandmarks(pt)) {
if (!valhalla::mjolnir::AddLandmarks(pt.get_child("mjolnir"))) {

I've edited AddLandmarks to handle the input as child mjolnir, maybe we want to change this back to get child mjolnir. it works for me :)

Copy link
Member

Choose a reason for hiding this comment

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

Yeah I must not've seen that for some reason. Weird though that I could push at all if I didn't pull your changes before.. I'll revert this!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess you can push because there is no conflict caused by this commit

@nilsnolde nilsnolde mentioned this pull request Oct 21, 2023
9 tasks
@nilsnolde
Copy link
Member

I started looking at this again, but didn't get very far yet. When I tried a route request, it wouldn't work, because we mess smth up when adding landmarks and make the tiles invalid somehow (as said before, tile size shrinks when adding landmarks!). It's not much code, but still annoying to debug.

@kevinkreiser
Copy link
Member

yeah i was hoping we could patch it up to the point that it could somewhat work sometimes and be a thing we opt into. maybe in the coming weeks we can pair on it for an hour at a time a couple times a week

@nilsnolde
Copy link
Member

my shortcut PR to remove names/speed is just tripping over the landmarks stuff: @kevinkreiser reminder for us to check how shortcuts are behaving with landmarks.. might be very well the key..

@kevinkreiser
Copy link
Member

kevinkreiser commented Feb 25, 2024

interesting hypothesis. imho we shouldn't put them on shortcuts anyway its a duplication without purpose

@nilsnolde
Copy link
Member

nilsnolde commented Feb 25, 2024

Yeah we don’t want that. But seems like we are, and while not being aware of it, maybe we’re forgetting about the base edges in the process and they get lost.. meeh, that’s very unlikely

@kevinkreiser
Copy link
Member

also we use loki search iirc which doesn't return shortcuts

@nilsnolde
Copy link
Member

Right, I think that was a fluke.. the test was going over the tileset and exactly, didn’t expect to see shortcuts, so all good there

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

None yet

3 participants