Skip to content

feat: partial gurka tile build - #6136

Merged
nilsnolde merged 10 commits into
masterfrom
nn-partial-gurka-tile-build
Jun 18, 2026
Merged

nilsnolde merged 10 commits into
masterfrom
nn-partial-gurka-tile-build

Conversation

@nilsnolde

@nilsnolde nilsnolde commented Jun 12, 2026 •

Copy link
Copy Markdown
Member

closes #6135

first changes I tried with the new claude fable model. it's much better, but one thing I realized: it's trying a lot harder to emulate "my/our style", e.g. inline comments don't start with capital letter, both great and eery. the gurka tests I asked it to do were right on point!

adds:

  • starting/stopping the gurka tile build at arbitrary stages, supports running multi-stage in a single test
  • gurka::findWay: reads ways.bin and finds a way by OSM ID
  • gurka::findWayNodes: reads way_nodes.bin and finds a vector of way_nodes matching the input node's OSM ID
  • 2 test examples, where 1 actually surfaced strange lua-c++ interaction (I'm sure not the only one we have :D)

fixes:

  • lua processing used to toss maxspeed >= 150 entirely, instead of letting c++ clamp it to 140

@nilsnolde
nilsnolde marked this pull request as ready for review June 12, 2026 18:46
Comment thread lua/graph.lua Outdated
--if num > 150kph or num < 10kph....toss
if num > 150 or num < 10 then
--toss unusably low speeds and values at/above the "unlimited" sentinel (255)
if num < 10 or num >= 255 then

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

we can't allow 255, that's signal "unlimited" in c++.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

btw. MAX_TRAFFIC_SPEED_KPH is 252

constexpr uint32_t UNKNOWN_TRAFFIC_SPEED_RAW = (1 << 7) - 1;
constexpr uint32_t MAX_TRAFFIC_SPEED_KPH = (UNKNOWN_TRAFFIC_SPEED_RAW - 1) << 1;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

which is only interesting for live traffic but not max_speed right? we cap it at 140 before it enters tiles.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

also, I think that change doesn't makes much sense because speeds are capped by kMaxOSMSpeed in

// Sets the speed in KPH.
void OSMWay::set_speed(const float speed) {
if (speed > kMaxOSMSpeed) {
LOG_DEBUG("Exceeded max speed for way id: " + std::to_string(osmwayid_));
build_stats::get().increment(build_stats::kExceededMaxOSMSpeed);
speed_ = kMaxOSMSpeed;
} else {
speed_ = static_cast<unsigned char>(speed + 0.5f);
}
}
// Sets the speed limit in KPH.
void OSMWay::set_speed_limit(const float speed_limit) {
if (speed_limit == kUnlimitedOSMSpeed) {
speed_limit_ = kUnlimitedOSMSpeed;
} else if (speed_limit > kMaxOSMSpeed) {
LOG_DEBUG("Exceeded max speed for way id: " + std::to_string(osmwayid_));
build_stats::get().increment(build_stats::kExceededMaxOSMSpeedLimit);
speed_limit_ = kMaxOSMSpeed;
} else {
speed_limit_ = static_cast<unsigned char>(speed_limit + 0.5f);
}
}

@kinkard kinkard Jun 13, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

my point is that this PR adds one more magic number around max speed and this time it's 254

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

ah thanks, didn't see that set_speed.. brings me to my point: our current speeds handling is ridiculously distributed among the codebase. needs a cleanup really

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

indeed this change is then redundant

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

done in aba62ee

Comment thread test/gurka/test_parse_osm.cc Outdated
{{"mjolnir.concurrency", "1"}}, mjolnir::BuildStage::kInitialize,
mjolnir::BuildStage::kParseWays);

auto way = gurka::findWay(map, 100);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

it would probably be simpler to search ways by name so each test could be enhanced with additional checks without changing too much like this

auto way = gurka::findWay(map, "BC");

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

yep, sounds like a good overload:)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

oh, and it is simpler in this scenario, so I'll change to use that pattern instead of manual osm_ids

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

done in 5016a52

@nilsnolde
nilsnolde requested a review from kinkard June 14, 2026 07:14
Comment thread lua/graph.lua
end

--if num > 150kph or num < 10kph....toss
if num > 150 or num < 10 then

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ok this is a behavioral change hidden in here i guess. previously we would throw away anything this high but now it becomes 140 on the c++ side?

@nilsnolde nilsnolde Jun 17, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

ah right, that's correct. although "hidden" is not correct! it's clearly written in the PR description!

@@ -0,0 +1,107 @@
#include "baldr/graphconstants.h"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

damn there wasnt an existing test we could have squeezed this into? the number of targets is... too long already imho

@nilsnolde nilsnolde Jun 17, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I know, but my karma this week would be net-0. I did (or do?) remove a gurka test file in some other PR and a much heavier one.

@nilsnolde nilsnolde Jun 17, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'd be happy to really really dumb those gurka tests down to a (larger) handful very soon. it's hard to make those test files truly sensible! but we can definitely decrease the count by at least 75%!

EXPECT_EQ(clamped.speed(), 140);

auto clamped_high = gurka::findWay(map, "CD");
EXPECT_EQ(clamped_high.speed_limit(), 140);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ok so confirmed behavioral change, >150 now becomes 140, where it used to be 0, right?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

hm, IIRC (hahah, it's really old!), > 150 we simply tossed before. so not even 0. no edge at all.

Comment thread test/gurka/gurka.cc Resolved
Comment thread test/gurka/gurka.cc
Comment on lines +440 to +462
template <typename Pred>
mjolnir::OSMWay find_way(const map& map, const std::string& what, Pred pred) {
auto tile_dir = map.config.get<std::string>("mjolnir.tile_dir");
// linear scan as the file's sort order is not guaranteed, it's tiny in tests anyway
midgard::sequence<mjolnir::OSMWay> ways(tile_dir + "/ways.bin");
for (const auto& way : ways) {
if (pred(way))
return way;
}
throw std::runtime_error("Could not find way " + what);
}

template <typename Pred> std::vector<mjolnir::OSMWayNode> find_way_nodes(const map& map, Pred pred) {
auto tile_dir = map.config.get<std::string>("mjolnir.tile_dir");
// linear scan as the file's sort order changes between build stages
midgard::sequence<mjolnir::OSMWayNode> way_nodes(tile_dir + "/way_nodes.bin");
std::vector<mjolnir::OSMWayNode> found;
for (const auto& way_node : way_nodes) {
if (pred(way_node))
found.push_back(way_node);
}
return found;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: whats the significance of having these up here in the detail namespace with functors to do the matching? why not just put this down in the implementation? are there future uses we have planned with different predicates? seems like needless complication/indirection unless we have more uses planned or maybe a gut feeling that more use cases are around the corner

@nilsnolde nilsnolde Jun 17, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@kinkard (rightfully IMO) requested that we have overloads for either identifying osm ways by numerical ID or string name. hence the templated versions where you can pick the predicate to be what you want it to be (though I guess this'll be it). in the current tests I only use the "string overload", but I assume that numerical OSM ID lookup might become useful in the future.

the numerical one is the one what I started with. then @kinkard requested the string overload. which fit that particular test use case way better. @kevinkreiser if you want me to remove the numerical overload now, no problem. it's more for the future.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

just to be clear: the numerical one is implemented/specialized, just not used yet in tests.

@kevinkreiser kevinkreiser left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

some nits but looks good!

@nilsnolde
nilsnolde requested a review from kevinkreiser June 17, 2026 21:16
@nilsnolde
nilsnolde enabled auto-merge (squash) June 18, 2026 14:30
@nilsnolde
nilsnolde merged commit 8315d32 into master Jun 18, 2026
17 of 18 checks passed
@nilsnolde
nilsnolde deleted the nn-partial-gurka-tile-build branch June 18, 2026 14:47
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.

Enable partial tile build in gurka processing

3 participants