Add clipping for 20 bits to SegmentWeight/SegmentDuration

This commit is contained in:
Patrick Niklaus 2017-04-11 16:44:34 +00:00 committed by Patrick Niklaus
parent d6c6a262d8
commit 11d8b2ba5a
4 changed files with 53 additions and 18 deletions

View File

@ -21,8 +21,8 @@ class CompressedEdgeContainer
struct OnewayCompressedEdge struct OnewayCompressedEdge
{ {
public: public:
NodeID node_id; // refers to an internal node-based-node NodeID node_id; // refers to an internal node-based-node
SegmentWeight weight; // the weight of the edge leading to this node SegmentWeight weight; // the weight of the edge leading to this node
SegmentDuration duration; // the duration of the edge leading to this node SegmentDuration duration; // the duration of the edge leading to this node
}; };
@ -64,6 +64,8 @@ class CompressedEdgeContainer
private: private:
int free_list_maximum = 0; int free_list_maximum = 0;
std::atomic_size_t clipped_weights;
std::atomic_size_t clipped_durations;
void IncreaseFreeList(); void IncreaseFreeList();
std::vector<OnewayEdgeBucket> m_compressed_oneway_geometries; std::vector<OnewayEdgeBucket> m_compressed_oneway_geometries;

View File

@ -59,8 +59,8 @@ using EdgeID = std::uint32_t;
using NameID = std::uint32_t; using NameID = std::uint32_t;
using EdgeWeight = std::int32_t; using EdgeWeight = std::int32_t;
using EdgeDuration = std::int32_t; using EdgeDuration = std::int32_t;
using SegmentWeight = std::uint16_t; using SegmentWeight = std::int32_t;
using SegmentDuration = std::uint16_t; using SegmentDuration = std::int32_t;
using TurnPenalty = std::int16_t; // turn penalty in 100ms units using TurnPenalty = std::int16_t; // turn penalty in 100ms units
static const std::size_t INVALID_INDEX = std::numeric_limits<std::size_t>::max(); static const std::size_t INVALID_INDEX = std::numeric_limits<std::size_t>::max();
@ -88,8 +88,8 @@ static const EdgeID SPECIAL_EDGEID = std::numeric_limits<EdgeID>::max();
static const NameID INVALID_NAMEID = std::numeric_limits<NameID>::max(); static const NameID INVALID_NAMEID = std::numeric_limits<NameID>::max();
static const NameID EMPTY_NAMEID = 0; static const NameID EMPTY_NAMEID = 0;
static const unsigned INVALID_COMPONENTID = 0; static const unsigned INVALID_COMPONENTID = 0;
static const SegmentWeight INVALID_SEGMENT_WEIGHT = std::numeric_limits<SegmentWeight>::max(); static const SegmentWeight INVALID_SEGMENT_WEIGHT = (1u << 20) - 1;
static const SegmentDuration INVALID_SEGMENT_DURATION = std::numeric_limits<SegmentDuration>::max(); static const SegmentDuration INVALID_SEGMENT_DURATION = (1u << 20) - 1;
static const EdgeWeight INVALID_EDGE_WEIGHT = std::numeric_limits<EdgeWeight>::max(); static const EdgeWeight INVALID_EDGE_WEIGHT = std::numeric_limits<EdgeWeight>::max();
static const EdgeDuration MAXIMAL_EDGE_DURATION = std::numeric_limits<EdgeDuration>::max(); static const EdgeDuration MAXIMAL_EDGE_DURATION = std::numeric_limits<EdgeDuration>::max();
static const TurnPenalty INVALID_TURN_PENALTY = std::numeric_limits<TurnPenalty>::max(); static const TurnPenalty INVALID_TURN_PENALTY = std::numeric_limits<TurnPenalty>::max();

View File

@ -87,10 +87,10 @@ void CompressedEdgeContainer::CompressEdge(const EdgeID edge_id_1,
const EdgeID edge_id_2, const EdgeID edge_id_2,
const NodeID via_node_id, const NodeID via_node_id,
const NodeID target_node_id, const NodeID target_node_id,
const EdgeWeight weight1, EdgeWeight weight1,
const EdgeWeight weight2, EdgeWeight weight2,
const EdgeDuration duration1, EdgeDuration duration1,
const EdgeDuration duration2) EdgeDuration duration2)
{ {
// remove super-trivial geometries // remove super-trivial geometries
BOOST_ASSERT(SPECIAL_EDGEID != edge_id_1); BOOST_ASSERT(SPECIAL_EDGEID != edge_id_1);
@ -135,10 +135,21 @@ void CompressedEdgeContainer::CompressEdge(const EdgeID edge_id_1,
// weight1 is the distance to the (currently) last coordinate in the bucket // weight1 is the distance to the (currently) last coordinate in the bucket
if (edge_bucket_list1.empty()) if (edge_bucket_list1.empty())
{ {
if (weight1 >= INVALID_SEGMENT_WEIGHT)
{
weight1 = INVALID_SEGMENT_WEIGHT - 1;
clipped_weights++;
}
if (duration1 >= INVALID_SEGMENT_DURATION)
{
duration1 = INVALID_SEGMENT_DURATION - 1;
clipped_durations++;
}
edge_bucket_list1.emplace_back( edge_bucket_list1.emplace_back(
OnewayCompressedEdge{via_node_id, OnewayCompressedEdge{via_node_id,
boost::numeric_cast<SegmentWeight>(weight1), static_cast<SegmentWeight>(weight1),
boost::numeric_cast<SegmentDuration>(duration1)}); static_cast<SegmentDuration>(duration1)});
} }
BOOST_ASSERT(0 < edge_bucket_list1.size()); BOOST_ASSERT(0 < edge_bucket_list1.size());
@ -168,11 +179,22 @@ void CompressedEdgeContainer::CompressEdge(const EdgeID edge_id_1,
} }
else else
{ {
if (weight2 >= INVALID_SEGMENT_WEIGHT)
{
weight2 = INVALID_SEGMENT_WEIGHT - 1;
clipped_weights++;
}
if (duration2 >= INVALID_SEGMENT_DURATION)
{
duration2 = INVALID_SEGMENT_DURATION - 1;
clipped_durations++;
}
// we are certain that the second edge is atomic. // we are certain that the second edge is atomic.
edge_bucket_list1.emplace_back( edge_bucket_list1.emplace_back(
OnewayCompressedEdge{target_node_id, OnewayCompressedEdge{target_node_id,
boost::numeric_cast<SegmentWeight>(weight2), static_cast<SegmentWeight>(weight2),
boost::numeric_cast<SegmentDuration>(duration2)}); static_cast<SegmentDuration>(duration2)});
} }
} }
@ -296,6 +318,17 @@ void CompressedEdgeContainer::PrintStatistics() const
longest_chain_length = std::max(longest_chain_length, (uint64_t)current_vector.size()); longest_chain_length = std::max(longest_chain_length, (uint64_t)current_vector.size());
} }
if (clipped_weights > 0)
{
util::Log(logWARNING) << "Clipped " << clipped_weights << " segment weights to "
<< (INVALID_SEGMENT_WEIGHT - 1);
}
if (clipped_durations > 0)
{
util::Log(logWARNING) << "Clipped " << clipped_durations << " segment durations to "
<< (INVALID_SEGMENT_DURATION - 1);
}
util::Log() << "Geometry successfully removed:" util::Log() << "Geometry successfully removed:"
"\n compressed edges: " "\n compressed edges: "
<< compressed_edges << "\n compressed geometries: " << compressed_geometries << compressed_edges << "\n compressed geometries: " << compressed_geometries

View File

@ -341,13 +341,13 @@ void Storage::PopulateLayout(DataLayout &layout)
layout.SetBlockSize<NodeID>(DataLayout::GEOMETRIES_NODE_LIST, layout.SetBlockSize<NodeID>(DataLayout::GEOMETRIES_NODE_LIST,
number_of_compressed_geometries); number_of_compressed_geometries);
layout.SetBlockSize<SegmentWeight>(DataLayout::GEOMETRIES_FWD_WEIGHT_LIST, layout.SetBlockSize<SegmentWeight>(DataLayout::GEOMETRIES_FWD_WEIGHT_LIST,
number_of_compressed_geometries); number_of_compressed_geometries);
layout.SetBlockSize<SegmentWeight>(DataLayout::GEOMETRIES_REV_WEIGHT_LIST, layout.SetBlockSize<SegmentWeight>(DataLayout::GEOMETRIES_REV_WEIGHT_LIST,
number_of_compressed_geometries); number_of_compressed_geometries);
layout.SetBlockSize<SegmentDuration>(DataLayout::GEOMETRIES_FWD_DURATION_LIST, layout.SetBlockSize<SegmentDuration>(DataLayout::GEOMETRIES_FWD_DURATION_LIST,
number_of_compressed_geometries); number_of_compressed_geometries);
layout.SetBlockSize<SegmentDuration>(DataLayout::GEOMETRIES_REV_DURATION_LIST, layout.SetBlockSize<SegmentDuration>(DataLayout::GEOMETRIES_REV_DURATION_LIST,
number_of_compressed_geometries); number_of_compressed_geometries);
layout.SetBlockSize<DatasourceID>(DataLayout::DATASOURCES_LIST, layout.SetBlockSize<DatasourceID>(DataLayout::DATASOURCES_LIST,
number_of_compressed_geometries); number_of_compressed_geometries);
} }