Skip to content

Adjust speed penalty and add dimensions to autocost#5627

Merged
chrstnbwnkl merged 36 commits intovalhalla:masterfrom
johannes-no:jn-dimensions-to-autocost
Nov 24, 2025
Merged

Adjust speed penalty and add dimensions to autocost#5627
chrstnbwnkl merged 36 commits intovalhalla:masterfrom
johannes-no:jn-dimensions-to-autocost

Conversation

@johannes-no
Copy link
Copy Markdown
Contributor

As discussed in #5595, this pull request extends autocosting to include the dimensions of length and weight.
In addition, the speed penalty for set top speeds has been adjusted. This can now be controlled via the input parameter “speed_penalty_factor” so it can be ignored entirely by setting it to 0.

I am open for suggestions and also nitpicks as I am looking to improve my C++ coding.

Johannes Nonnenmacher on behalf of Mercedes-Benz Tech Innovation GmbH.
Provider Information

Comment thread src/sif/dynamiccost.cc

// Default speed penalty factor (increase the cost of an edge if the edge speed is faster than the top speed)
constexpr float kDefaultSpeedPenaltyFactor = 0.05f;
constexpr ranged_default_t<float> kSpeedPenaltyFactorRange{0.0f, kDefaultSpeedPenaltyFactor, 1.0f};
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.

the lower bound needs to be kMinFactor to avoid zero edge cost

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.

Ah nevermind, I was under the impression this was multiplied with the edge cost directly, but in this case we want to be able to set the speed penalty to 0.

Comment thread valhalla/sif/dynamiccost.h Outdated
midgard::ranged_default_t<float> height_;
midgard::ranged_default_t<float> width_;
midgard::ranged_default_t<float> length_;
midgard::ranged_default_t<float> weight_;
Copy link
Copy Markdown
Member

@chrstnbwnkl chrstnbwnkl Oct 21, 2025

Choose a reason for hiding this comment

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

If these are now present in the BaseCostingOptions, shouldn't they be removed from TruckCost, and then TruckCost would simply override the defaults?

BaseCostingOptionsConfig GetBaseCostOptsConfig() {
BaseCostingOptionsConfig cfg{};
// override defaults
cfg.service_penalty_.def = kDefaultServicePenalty;
cfg.use_tracks_.def = kDefaultUseTracks;
cfg.use_living_streets_.def = kDefaultUseLivingStreets;
return cfg;
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Wouldn't this prevent us from having different ranges? For example, TruckLength currenlty has a range of 0 to 50 m, while the range for cars is 0 to 20 m.
If this is not needed i can change it.

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.

Mh, I didn't think about that. But generally I favor opening up ranges, because it's hard to make assumptions about edge cases (makes me think of Falsehoods Programmers Believe About Names) . Also I'd say widening these ranges comes with hardly any performance penalty.

Comment thread src/sif/autocost.cc Outdated
constexpr float kDefaultAutoHeight = 1.6f; // Meters (62.9921 inches)
constexpr float kDefaultAutoWidth = 1.9f; // Meters (74.8031 inches)
constexpr float kDefaultAutoLength = 5.3f; // Meters (208,661 inches)
constexpr float kDefaultAutoWeight = 3.0f; // Metric Tons (6613,87 lbs)
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.

The default weight seems a little high maybe? I don't know too much about cars, but this looks more like the weight of a SUV. I think we'd be better off by setting it to an optimistically low value in order not to have routes failing that previously wouldn't have failed.

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.

Yeah agree. IMO we don't even need defaults at all (or very low ones, passing the smallest car). That'd keep it as it currently is. Roads with car access are 99.99% built with cars in mind. The main point is that now you can modify that for costing. If anyone drives a monster like the dimensions here, they'll need to pass them.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agree 100% ill change it to the size of a smaller car.

Comment thread docs/docs/api/turn-by-turn/api-reference.md Outdated
johannes-no and others added 2 commits October 24, 2025 14:44
Co-authored-by: Nils <nilsnolde@proton.me>
@chrstnbwnkl
Copy link
Copy Markdown
Member

For me this is good to go if you just format the code again and resolve the changelog conflicts (we just released 3.6.0, so this needs to go in the new section now)

Comment thread src/sif/dynamiccost.cc
Comment on lines +120 to +123
constexpr float kDefaultHeight = 1.6f; // Meters (62.9921 inches)
constexpr float kDefaultWidth = 1.9f; // Meters (74.8031 inches)
constexpr float kDefaultLength = 2.7f; // Meters (208,661 inches)
constexpr float kDefaultWeight = 0.8f; // Metric Tons (6613,87 lbs)
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.

just skimming again: is this the same default for truck? that'd be a change we probably shouldn't do. not that I really agree with the defaults there, but default truck should stay the same regardless

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The truck profile overwrites the defaults with the truck defaults, so the default values for trucks remain the same.

@nilsnolde
Copy link
Copy Markdown
Member

@johannes-no fyi, CI is failing, smth relevant to this PR on osx

@nilsnolde
Copy link
Copy Markdown
Member

and you'll need to run format.sh

@johannes-no
Copy link
Copy Markdown
Contributor Author

Hello, sorry, due to vacation, this has taken an unnecessarily long time.
I also had to talk to our FOSS representative again. We now have a new fork mercedes-employees-and-valhalla-maintainer and will contribute everything from there now. I have authorized @nilsnolde, @chrstnbwnkl & @kevinkreiser such that you can merge and adjust stuff more easy in your Thursday round.
Should we also move 5596 and 5679 to the new repo or would this be to much confussion for now?

@nilsnolde
Copy link
Copy Markdown
Member

Cool, thanks! For me it'd be easier to keep the other PRs on the old fork, so comments etc are preserved.

@johannes-no
Copy link
Copy Markdown
Contributor Author

@chrstnbwnkl do you guys have your sync today? Maybe we can merg this

Copy link
Copy Markdown
Member

@chrstnbwnkl chrstnbwnkl left a comment

Choose a reason for hiding this comment

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

I think the code looks good now, could you also move the costing parameters description from the truck section to the table above it ("Vehicle Options")?

@chrstnbwnkl
Copy link
Copy Markdown
Member

Can you update it as well (replace truck with vehicle and add diverging defaults for truck)?

Copy link
Copy Markdown
Member

@chrstnbwnkl chrstnbwnkl left a comment

Choose a reason for hiding this comment

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

I just realize I have edit privileges on this branch, so could've done this myself 😄 thanks!

@chrstnbwnkl chrstnbwnkl enabled auto-merge (squash) November 24, 2025 09:46
@chrstnbwnkl chrstnbwnkl merged commit 89a1d1b into valhalla:master Nov 24, 2025
18 checks passed
@johannes-no johannes-no deleted the jn-dimensions-to-autocost branch November 25, 2025 09:35
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.

4 participants