Skip to content

Legal max speed parameter - #2910

Closed
nilsnolde wants to merge 5 commits into
masterfrom
nn_legal_limit
Closed

nilsnolde wants to merge 5 commits into
masterfrom
nn_legal_limit

Conversation

@nilsnolde

Copy link
Copy Markdown
Member

fixes #2840

As described in the issue.. Pretty special use case I'd say, but since I implemented it for a client already, maybe you have some use for it too? The client's use case was e-(cargo-)bikes somewhere in Michigan, which are apparently not allowed on roads which have a max speed higher than ~50 KPH. No idea if that's a common thing anywhere else, but here it goes..

Tasklist

  • Add tests
  • Add #fixes with the issue number that this PR addresses
  • Update the docs with any new request parameters or changes to behavior described
  • Update the changelog

Comment thread lua/graph.lua
else
kv["max_speed"] = normalize_speed(kv["maxspeed"])
-- max speeds are allowed to be unlimited
local speeds_tags = { max_speed="maxspeed", forward_speed="maxspeed:forward", backward_speed="maxspeed:backward" }

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 think it'd be more consistent to also allow the directional variants to be unlimited.. Shouldn't really happen, but I've seen it in at least synthetic OSM data

Comment on lines +1130 to +1131
uint64_t max_speed_ : 8; // speed_ can be maxspeed:advisory or maxspeed:practical
uint64_t spare4_ : 1;

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.

oh man... this is really rough. i'm having a hard time making a case for this just because of advisory or practical. i'd almost rather just stop parsing advisory or practical so we can use speed_ instead.

@dnesbitt61 or @gknisely your thoughts?

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.

Haha no worries, I figured so! An alternative could be to change the SpeedType enum to kTagDefault, kTagPractical, kTagMax, kClassified:

https://github.com/valhalla/valhalla/blob/nn_legal_limit/valhalla/baldr/graphconstants.h#L365-L369

Plus the code to parse them from the PBF.. And reverse however speed was enhanced after parsing. That way we could at least detect if the tagged speed is from a maxspeed tag and not one of the others and not write too low speeds to max_speed_..

Or chop default & practical ;) Or a no-merge.. up to you.

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.

speed_type in DirectedEdge is only 1 bit so this doesn't seem practical.

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.

i had this thought too. actually i think we can do it by taking a single free bit, shifting it one and oring it with the existing bit. effectively making this speed type field 2 bits wide. it would almost be backwards compatible in that old data would work with the new code. but new data with old code would mean that anything that were advisory or practical speed types would look like categorized speed types. i feel like this is a livable compromise since since they are sparsely populated in the data.

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 feel like this is a livable compromise

totally agreed!

@nilsnolde nilsnolde Mar 3, 2021 •

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.

Ugh sorry, I'm getting confused here anyways.. With the new approach (2 bit SpeedType) speed is what will hold the maxspeed, not speed_limit (not accessible to DirectedEdge). So shortcuts are fine actually..

Tbh, I don't really understand why different speeds are a reason to not create a shortcut @dnesbitt61 .. Couldn't the top_speed costing work with average speeds on the accumulated shortcut? The same for setting a speed_ on the final shortcut DirectedEdge, no? Probably I'm missing a crucial step here, but I can't see it.. Supporting a legal speed limit for motorized costings would need some logic like that though, but it could be limited to maxspeed tagged ones.

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.

I take back my comment on truck routing and truck speed - it doesn't look like truck speed is used when doing truck routing which seems wrong.
Wouldn't any costing that uses some penalty or avoidance when speed is above some threshold need to make sure that shortcuts don't filter out such speeds? A connected set of edges that are 45MPH, then 55MPH, then back to 45MPH would need to keep the 55MPH section separate if any costing penalizes edges above 45MPH. Alternatively, any costing which penalizes or avoids edges by speed might need to avoid using shortcut edges.

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.

it doesn't look like truck speed is used when doing truck routing which seems wrong

actually it's used when GetSpeed() is called in the costing, there's a (fairly new I think) is_truck bool arg.

A connected set of edges that are 45MPH, then 55MPH, then back to 45MPH would need to keep the 55MPH section separate if any costing penalizes edges above 45MPH

yeah, of course..

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.

been doing only bicycle routing recently and haven't followed recent updates to speeds and their use (or shortcuts for that matter). Sorry for wading into this discussion without full knowledge!

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.

All good, you cleared up some misconceptions on my side:)

Comment on lines +328 to +329
min_speed_limit =
directededge->max_speed() < min_speed_limit ? directededge->max_speed() : min_speed_limit;

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.

this is bs anyways.. need to think about that again..

@dnesbitt61

dnesbitt61 commented Mar 2, 2021 •

Copy link
Copy Markdown
Member

I have a hard time approving adding yet another speed to DirectedEdge (speed, free-flow, constrained-flow, truck already exist) but I will defer to others. I've already used those bits for Mountain Bike attribution (so perhaps I'm just biased here).

When speed_type == SpeedType::kTagged isn't the speed value equal to the speed limit? It looks like there are a couple cases where speed is reduces on rough surfaces, but otherwise speed is usually the speed limit.

@dnesbitt61

Copy link
Copy Markdown
Member

Motor scooter costing has similar limitations but it seems that rather than not allowing on roads exceeding some speed limit, the approach was to penalize roads with speeds above the scooter's top speed. This perhaps could be revisited to use similar logic to e-bikes (which perhaps should be its own costing profile rather than adding yet another condition to bicycle costing).

@nilsnolde

Copy link
Copy Markdown
Member Author

When speed_type == SpeedType::kTagged isn't the speed value equal to the speed limit?

@dnesbitt61 in the case where practical_speed or default_speed are also set on a OSM way.

Motor scooter costing has similar limitations

actually we added it to all motorized vehicles a few PRs back. As you say, the logic is penalization, but if you're talking about a legal speed limit I think relevant edges should be absolutely avoided.

I'm hoping their project continues so we could look at developing a proper e-bike profile..

@nilsnolde

Copy link
Copy Markdown
Member Author

never heard back on this from the client, I'll remove it from the queue

@nilsnolde nilsnolde closed this Sep 13, 2022
@nilsnolde nilsnolde mentioned this pull request Jan 10, 2024
3 of 5 tasks
@nilsnolde
nilsnolde deleted the nn_legal_limit branch February 24, 2024 14:55
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.

Avoid streets entirely with (legal) maxspeed higher than threshold

3 participants