Allow users to specify a class for each way

This adds the ability to mark ways with a user-defined
class in the profile. This class information will be included
in the response as property of the RouteStep object.
This commit is contained in:
Patrick Niklaus
2017-06-27 22:01:05 +00:00
committed by Patrick Niklaus
parent d52d530cbe
commit 44739f2dc3
39 changed files with 614 additions and 57 deletions
+99
View File
@@ -0,0 +1,99 @@
#ifndef OSRM_UTIL_BIT_RANGE_HPP
#define OSRM_UTIL_BIT_RANGE_HPP
#include "util/msb.hpp"
#include <boost/iterator/iterator_facade.hpp>
#include <boost/range/iterator_range.hpp>
namespace osrm
{
namespace util
{
namespace detail
{
template <typename T> std::size_t countOnes(T value)
{
static_assert(std::is_unsigned<T>::value, "Only unsigned types allowed");
std::size_t number_of_ones = 0;
while (value > 0)
{
auto index = msb(value);
value = value & ~(T{1} << index);
number_of_ones++;
}
return number_of_ones;
}
#if (defined(__clang__) || defined(__GNUC__) || defined(__GNUG__))
inline std::size_t countOnes(std::uint8_t value)
{
return __builtin_popcount(std::uint32_t{value});
}
inline std::size_t countOnes(std::uint16_t value)
{
return __builtin_popcount(std::uint32_t{value});
}
inline std::size_t countOnes(unsigned int value) { return __builtin_popcount(value); }
inline std::size_t countOnes(unsigned long value) { return __builtin_popcountl(value); }
inline std::size_t countOnes(unsigned long long value) { return __builtin_popcountll(value); }
#endif
}
// Investigate if we can replace this with
// http://www.boost.org/doc/libs/1_64_0/libs/dynamic_bitset/dynamic_bitset.html
template <typename DataT>
class BitIterator : public boost::iterator_facade<BitIterator<DataT>,
const std::size_t,
boost::forward_traversal_tag,
const std::size_t>
{
typedef boost::iterator_facade<BitIterator<DataT>,
const std::size_t,
boost::forward_traversal_tag,
const std::size_t>
base_t;
public:
typedef typename base_t::value_type value_type;
typedef typename base_t::difference_type difference_type;
typedef typename base_t::reference reference;
typedef std::random_access_iterator_tag iterator_category;
explicit BitIterator() : m_value(0) {}
explicit BitIterator(const DataT x) : m_value(std::move(x)) {}
private:
void increment()
{
auto index = msb(m_value);
m_value = m_value & ~(DataT{1} << index);
}
difference_type distance_to(const BitIterator &other) const
{
return detail::countOnes(m_value) - detail::countOnes(other.m_value);
}
bool equal(const BitIterator &other) const { return m_value == other.m_value; }
reference dereference() const
{
BOOST_ASSERT(m_value > 0);
return msb(m_value);
}
friend class ::boost::iterator_core_access;
DataT m_value;
};
// Returns range over all 1 bits of value
template <typename T> auto makeBitRange(const T value)
{
return boost::make_iterator_range(BitIterator<T>{value}, BitIterator<T>{});
}
}
}
#endif
+14 -5
View File
@@ -3,6 +3,7 @@
#include <boost/assert.hpp>
#include <climits>
#include <cstdint>
#include <utility>
@@ -26,16 +27,24 @@ template <typename T> std::size_t msb(T value)
return msb - 1;
}
#if (defined(__clang__) || defined(__GNUC__) || defined(__GNUG__)) && __x86_64__
inline std::size_t msb(std::uint64_t v)
#if (defined(__clang__) || defined(__GNUC__) || defined(__GNUG__))
inline std::size_t msb(unsigned long long v)
{
BOOST_ASSERT(v > 0);
return 63UL - __builtin_clzl(v);
constexpr auto MSB_INDEX = CHAR_BIT * sizeof(unsigned long long) - 1;
return MSB_INDEX - __builtin_clzll(v);
}
inline std::size_t msb(std::uint32_t v)
inline std::size_t msb(unsigned long v)
{
BOOST_ASSERT(v > 0);
return 31UL - __builtin_clz(v);
constexpr auto MSB_INDEX = CHAR_BIT * sizeof(unsigned long) - 1;
return MSB_INDEX - __builtin_clzl(v);
}
inline std::size_t msb(unsigned int v)
{
BOOST_ASSERT(v > 0);
constexpr auto MSB_INDEX = CHAR_BIT * sizeof(unsigned int) - 1;
return MSB_INDEX - __builtin_clz(v);
}
#endif
}
+7 -2
View File
@@ -1,6 +1,7 @@
#ifndef NODE_BASED_GRAPH_HPP
#define NODE_BASED_GRAPH_HPP
#include "extractor/class_data.hpp"
#include "extractor/guidance/road_classification.hpp"
#include "extractor/node_based_edge.hpp"
#include "util/dynamic_graph.hpp"
@@ -35,10 +36,12 @@ struct NodeBasedEdgeData
bool startpoint,
bool restricted,
extractor::TravelMode travel_mode,
extractor::ClassData classes,
const LaneDescriptionID lane_description_id)
: weight(weight), duration(duration), edge_id(edge_id), name_id(name_id),
reversed(reversed), roundabout(roundabout), circular(circular), startpoint(startpoint),
restricted(restricted), travel_mode(travel_mode), lane_description_id(lane_description_id)
restricted(restricted), travel_mode(travel_mode), classes(classes),
lane_description_id(lane_description_id)
{
}
@@ -52,6 +55,7 @@ struct NodeBasedEdgeData
bool startpoint : 1;
bool restricted : 1;
extractor::TravelMode travel_mode : 4;
extractor::ClassData classes;
LaneDescriptionID lane_description_id;
extractor::guidance::RoadClassification road_classification;
@@ -59,7 +63,7 @@ struct NodeBasedEdgeData
{
return (reversed == other.reversed) && (roundabout == other.roundabout) &&
(circular == other.circular) && (startpoint == other.startpoint) &&
(travel_mode == other.travel_mode) &&
(travel_mode == other.travel_mode) && (classes == other.classes) &&
(road_classification == other.road_classification) &&
(restricted == other.restricted);
}
@@ -89,6 +93,7 @@ NodeBasedDynamicGraphFromEdges(NodeID number_of_nodes,
output_edge.data.circular = input_edge.circular;
output_edge.data.name_id = input_edge.name_id;
output_edge.data.travel_mode = input_edge.travel_mode;
output_edge.data.classes = input_edge.classes;
output_edge.data.startpoint = input_edge.startpoint;
output_edge.data.restricted = input_edge.restricted;
output_edge.data.road_classification = input_edge.road_classification;