Skip to content

Conversation

mjjbell
Copy link
Member

@mjjbell mjjbell commented Oct 23, 2022

Issue

This change takes the existing typedefs for weight, duration and distance, and makes them proper types, using the existing Alias functionality.

Primarily this is to prevent bugs where the metrics are switched, but it also adds additional documentation. For example, it now makes it clear (despite the naming of variables) that most of the trip algorithm is running on the duration metric.

I've not made any changes to the casts performed between metrics and numeric types, they are now just more explicit.

Tasklist

Requirements / Relations

Closes #3601

return (word & ~mask) | ((static_cast<WordT>(value) >> offset) & mask);
}

template <typename WordT, typename T>
Copy link
Member Author

Choose a reason for hiding this comment

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

These are needed to allow PackedVectors of Alias types to be correctly serialized.

}

// FIXME: This is needed for tests on Boost ranges to correctly compare Alias values.
template <typename F, typename U> bool operator!=(const osrm::Alias<F, U> value) const
Copy link
Member Author

Choose a reason for hiding this comment

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

This is a bit of a hack. The unit tests compare PackedVector ranges of Alias types against normal vectors of Alias types. Boost seems to know what to do for integral types, but this was the only way to get the comparison to work. Open to suggestion of how to do this in a better way.

TurnPenalty{std::numeric_limits<TurnPenalty::value_type>::max()};
static const EdgeDistance INVALID_FALLBACK_SPEED =
EdgeDistance{std::numeric_limits<EdgeDistance::value_type>::max()};
// TODO: These are the same as the invalid values. Do we need both?
Copy link
Member Author

@mjjbell mjjbell Oct 23, 2022

Choose a reason for hiding this comment

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

Potentially worth revisiting. We have invalid and maximal constants for the same numeric max. Could be consolidated.

return getPathDistance(facade, unpacked_path, source_phantom, target_phantom);
}

std::tuple<EdgeWeight, EdgeDistance> getLoopWeight(const DataFacade<Algorithm> &facade, NodeID node)
Copy link
Member Author

@mjjbell mjjbell Oct 23, 2022

Choose a reason for hiding this comment

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

getLoopWeight had to be split into two functions, as it's now returning different types depending on the input.

Copy link
Member

Choose a reason for hiding this comment

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

I bet we can unify them using some metaprogramming magic, but up to you

Copy link
Member Author

Choose a reason for hiding this comment

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

I think I've figured out how to do it.

static_cast<const typename FromAlias::value_type>(from))};
}

template <typename ToNumeric, typename FromAlias> inline ToNumeric from_alias(const FromAlias &from)
Copy link
Member Author

Choose a reason for hiding this comment

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

Open to better naming suggestions for these functions.

@mjjbell
Copy link
Member Author

mjjbell commented Oct 23, 2022

#3601 (comment) seems to imply that there will be no performance hit, but I'll do some testing to confirm.

@mjjbell mjjbell force-pushed the mbell/fix_compress_penalty branch from b81044a to 29a1bbd Compare October 24, 2022 19:43
@DennisOSRM
Copy link
Collaborator

LGTM

This change takes the existing typedefs for weight, duration and
distance, and makes them proper types, using the existing Alias
functionality.

Primarily this is to prevent bugs where the metrics are switched,
but it also adds additional documentation. For example, it now
makes it clear (despite the naming of variables) that most of the
trip algorithm is running on the duration metric.

I've not made any changes to the casts performed between metrics
and numeric types, they now just more explicit.
@mjjbell mjjbell force-pushed the mbell/fix_compress_penalty branch from 29a1bbd to 19fef70 Compare October 25, 2022 20:36
@mjjbell
Copy link
Member Author

mjjbell commented Oct 27, 2022

Timed the processing steps using the great-britain extract and the node tests on my 12 core dev machine. Not particularly scientific, but I think it's sufficient to show it's had no adverse effects on performance.

osrm-extract

Run Alias Types Master
1 3m48.758s 4m11.823s
2 3m57.277s 4m16.485s
3 4m1.521s 4m16.758s

osrm-partition

Run Alias Types Master
1 3m5.425s 3m3.904s
2 3m2.662s 2m58.658s
3 3m1.520s 3m2.046s

osrm-customize

Run Alias Types Master
1 0m25.398s 0m26.014s
2 0m25.881s 0m25.533s
3 0m26.066s 0m25.177s

osrm-contract

Run Alias Types Master
1 11m10.813s 11m31.428s
2 11m30.680s 11m56.144s
3 12m0.610s 11m9.938s

npm test (cached)

Run Alias Types Master
1 4m34.890s 4m37.677s

@mjjbell mjjbell merged commit 5d468f2 into Project-OSRM:master Oct 28, 2022
mattwigway pushed a commit to mattwigway/osrm-backend that referenced this pull request Jul 20, 2023
This change takes the existing typedefs for weight, duration and
distance, and makes them proper types, using the existing Alias
functionality.

Primarily this is to prevent bugs where the metrics are switched,
but it also adds additional documentation. For example, it now
makes it clear (despite the naming of variables) that most of the
trip algorithm is running on the duration metric.

I've not made any changes to the casts performed between metrics
and numeric types, they now just more explicit.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make edge weight a strongly defined type
3 participants