reduce size of InternalExtractorEdge by using single-precision values
This commit is contained in:
parent
5f1c7efd41
commit
c48fc58eb2
@ -20,23 +20,37 @@ namespace extractor
|
||||
|
||||
namespace detail
|
||||
{
|
||||
// these are used for duration based mode of transportations like ferries
|
||||
OSRM_STRONG_TYPEDEF(double, ValueByEdge)
|
||||
OSRM_STRONG_TYPEDEF(double, ValueByMeter)
|
||||
using ByEdgeOrByMeterValue = mapbox::util::variant<detail::ValueByEdge, detail::ValueByMeter>;
|
||||
|
||||
struct ToValueByEdge
|
||||
// Use a single float to pack two positive values:
|
||||
// * by_edge: + sign, value >= 0, value used as the edge weight
|
||||
// * by_meter: - sign, value > 0, value used as a denominator in distance / value
|
||||
struct ByEdgeOrByMeterValue
|
||||
{
|
||||
ToValueByEdge(double distance_) : distance(distance_) {}
|
||||
|
||||
ValueByEdge operator()(const ValueByMeter by_meter) const
|
||||
struct ValueByEdge
|
||||
{
|
||||
return ValueByEdge{distance / static_cast<double>(by_meter)};
|
||||
} static const by_edge;
|
||||
struct ValueByMeter
|
||||
{
|
||||
} static const by_meter;
|
||||
|
||||
ByEdgeOrByMeterValue() : value(0.f) {}
|
||||
|
||||
ByEdgeOrByMeterValue(ValueByEdge, double input)
|
||||
{
|
||||
BOOST_ASSERT(input >= 0.f);
|
||||
value = static_cast<value_type>(input);
|
||||
}
|
||||
|
||||
ValueByEdge operator()(const ValueByEdge by_edge) const { return by_edge; }
|
||||
ByEdgeOrByMeterValue(ValueByMeter, double input)
|
||||
{
|
||||
BOOST_ASSERT(input > 0.f);
|
||||
value = -static_cast<value_type>(input);
|
||||
}
|
||||
|
||||
double distance;
|
||||
double operator()(double distance) { return value >= 0 ? value : -distance / value; }
|
||||
|
||||
private:
|
||||
using value_type = float;
|
||||
value_type value;
|
||||
};
|
||||
}
|
||||
|
||||
@ -60,7 +74,7 @@ struct InternalExtractorEdge
|
||||
false,
|
||||
guidance::TurnLaneType::empty,
|
||||
guidance::RoadClassification()),
|
||||
weight_data(detail::ValueByMeter{0.0}), duration_data(detail::ValueByMeter{0.0})
|
||||
weight_data(), duration_data()
|
||||
{
|
||||
}
|
||||
|
||||
@ -113,8 +127,8 @@ struct InternalExtractorEdge
|
||||
return InternalExtractorEdge(MIN_OSM_NODEID,
|
||||
MIN_OSM_NODEID,
|
||||
SPECIAL_NODEID,
|
||||
detail::ValueByMeter{0.0},
|
||||
detail::ValueByMeter{0.0},
|
||||
WeightData(),
|
||||
DurationData(),
|
||||
false, // forward
|
||||
false, // backward
|
||||
false, // roundabout
|
||||
@ -131,8 +145,8 @@ struct InternalExtractorEdge
|
||||
return InternalExtractorEdge(MAX_OSM_NODEID,
|
||||
MAX_OSM_NODEID,
|
||||
SPECIAL_NODEID,
|
||||
detail::ValueByMeter{0.0},
|
||||
detail::ValueByMeter{0.0},
|
||||
WeightData(),
|
||||
DurationData(),
|
||||
false, // forward
|
||||
false, // backward
|
||||
false, // roundabout
|
||||
|
@ -48,6 +48,7 @@ struct NodeBasedEdge
|
||||
guidance::RoadClassification road_classification;
|
||||
};
|
||||
|
||||
#pragma pack(push, 4)
|
||||
struct NodeBasedEdgeWithOSM : NodeBasedEdge
|
||||
{
|
||||
NodeBasedEdgeWithOSM(OSMNodeID source,
|
||||
@ -68,6 +69,7 @@ struct NodeBasedEdgeWithOSM : NodeBasedEdge
|
||||
OSMNodeID osm_source_id;
|
||||
OSMNodeID osm_target_id;
|
||||
};
|
||||
#pragma pack(pop)
|
||||
|
||||
// Impl.
|
||||
|
||||
|
@ -427,10 +427,8 @@ void ExtractionContainers::PrepareEdges(ScriptingEnvironment &scripting_environm
|
||||
const double distance = util::coordinate_calculation::greatCircleDistance(
|
||||
edge_iterator->source_coordinate, target_coord);
|
||||
|
||||
double weight = static_cast<double>(mapbox::util::apply_visitor(
|
||||
detail::ToValueByEdge(distance), edge_iterator->weight_data));
|
||||
double duration = static_cast<double>(mapbox::util::apply_visitor(
|
||||
detail::ToValueByEdge(distance), edge_iterator->duration_data));
|
||||
auto weight = edge_iterator->weight_data(distance);
|
||||
auto duration = edge_iterator->duration_data(distance);
|
||||
|
||||
ExtractionSegment extracted_segment(
|
||||
edge_iterator->source_coordinate, target_coord, distance, weight, duration);
|
||||
|
@ -119,20 +119,20 @@ void ExtractorCallbacks::ProcessWay(const osmium::Way &input_way, const Extracti
|
||||
InternalExtractorEdge::WeightData forward_weight_data;
|
||||
InternalExtractorEdge::WeightData backward_weight_data;
|
||||
|
||||
const auto toValueByEdgeOrByMeter =
|
||||
[&nodes](const double by_way, const double by_meter) -> detail::ByEdgeOrByMeterValue {
|
||||
if (by_way > 0)
|
||||
const auto toValueByEdgeOrByMeter = [&nodes](const double by_way, const double by_meter) {
|
||||
using Value = detail::ByEdgeOrByMeterValue;
|
||||
if (by_way >= 0)
|
||||
{
|
||||
// FIXME We divide by the number of edges here, but should rather consider
|
||||
// the length of each segment. We would either have to compute the length
|
||||
// of the whole way here (we can't: no node coordinates) or push that back
|
||||
// to the container and keep a reference to the way.
|
||||
const unsigned num_edges = (nodes.size() - 1);
|
||||
return detail::ValueByEdge{by_way / num_edges};
|
||||
const std::size_t num_edges = (nodes.size() - 1);
|
||||
return Value(Value::by_edge, by_way / num_edges);
|
||||
}
|
||||
else
|
||||
{
|
||||
return detail::ValueByMeter{by_meter};
|
||||
return Value(Value::by_meter, by_meter);
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user