Skip to content

Commit

Permalink
refactor/cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Moritz Kobitzsch committed Jul 18, 2017
1 parent ba54874 commit 29e0cc7
Show file tree
Hide file tree
Showing 17 changed files with 413 additions and 441 deletions.
8 changes: 6 additions & 2 deletions include/extractor/edge_based_graph_factory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class EdgeBasedGraphFactory
std::vector<util::guidance::BearingClass> GetBearingClasses() const;
std::vector<util::guidance::EntryClass> GetEntryClasses() const;

unsigned GetHighestEdgeID();
std::uint64_t GetNumberOfEdgeBasedNodes() const;

// Basic analysis of a turn (u --(e1)-- v --(e2)-- w)
// with known angle.
Expand Down Expand Up @@ -136,7 +136,11 @@ class EdgeBasedGraphFactory
std::vector<EdgeBasedNodeSegment> m_edge_based_node_segments;
EdgeBasedNodeDataContainer m_edge_based_node_container;
util::DeallocatingVector<EdgeBasedEdge> m_edge_based_edge_list;
EdgeID m_max_edge_id;

// the number of edge-based nodes is mostly made up out of the edges in the node-based graph.
// Any edge in the node-based graph represents a node in the edge-based graph. In addition, we
// add a set of artificial edge-based nodes into the mix to model via-way turn restrictions.
std::uint64_t m_number_of_edge_based_nodes;

const std::vector<util::Coordinate> &m_coordinates;
const extractor::PackedOSMIDs &m_osm_node_ids;
Expand Down
9 changes: 8 additions & 1 deletion include/extractor/node_data_container.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,14 @@ template <storage::Ownership Ownership> class EdgeBasedNodeDataContainerImpl
}

// all containers have the exact same size
std::size_t Size() const { return geometry_ids.size(); }
std::size_t Size() const
{
BOOST_ASSERT(geometry_ids.size() == name_ids.size());
BOOST_ASSERT(geometry_ids.size() == component_ids.size());
BOOST_ASSERT(geometry_ids.size() == travel_modes.size());
BOOST_ASSERT(geometry_ids.size() == classes.size());
return geometry_ids.size();
}

private:
Vector<GeometryID> geometry_ids;
Expand Down
47 changes: 14 additions & 33 deletions include/extractor/restriction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ namespace extractor
// ab via b to bd
struct InputNodeRestriction
{
OSMEdgeID_weak from;
OSMNodeID_weak via;
OSMEdgeID_weak to;
OSMWayID from;
OSMNodeID via;
OSMWayID to;
};

// A restriction that uses a single via-way in between
Expand All @@ -39,9 +39,9 @@ struct InputNodeRestriction
// ab via be to ef -- no u turn
struct InputWayRestriction
{
OSMEdgeID_weak from;
OSMEdgeID_weak via;
OSMEdgeID_weak to;
OSMWayID from;
OSMWayID via;
OSMWayID to;
};

// Outside view of the variant, these are equal to the `which()` results
Expand All @@ -52,37 +52,20 @@ enum RestrictionType
NUM_RESTRICTION_TYPES = 2
};

namespace restriction_details
{

// currently these bits only hold an `is_only` value.
struct Bits
{ // mostly unused, initialised to false by default
Bits() : is_only(false) {}

bool is_only;
// when adding more bits, consider using bitfields just as in
// bool unused : 7;

bool operator==(const Bits &other) const { return is_only == other.is_only; }
};

} // namespace restriction

struct InputTurnRestriction
{
// keep in the same order as the turn restrictions below
boost::variant<InputNodeRestriction, InputWayRestriction> node_or_way;
restriction_details::Bits flags;
bool is_only;

OSMEdgeID_weak From() const
OSMWayID From() const
{
return node_or_way.which() == RestrictionType::NODE_RESTRICTION
? boost::get<InputNodeRestriction>(node_or_way).from
: boost::get<InputWayRestriction>(node_or_way).from;
}

OSMEdgeID_weak To() const
OSMWayID To() const
{
return node_or_way.which() == RestrictionType::NODE_RESTRICTION
? boost::get<InputNodeRestriction>(node_or_way).to
Expand Down Expand Up @@ -186,20 +169,18 @@ struct TurnRestriction
{
// keep in the same order as the turn restrictions above
boost::variant<NodeRestriction, WayRestriction> node_or_way;
restriction_details::Bits flags;
bool is_only;

// construction for NodeRestrictions
explicit TurnRestriction(NodeRestriction node_restriction, bool is_only = false)
: node_or_way(node_restriction)
: node_or_way(node_restriction), is_only(is_only)
{
flags.is_only = is_only;
}

// construction for WayRestrictions
explicit TurnRestriction(WayRestriction way_restriction, bool is_only = false)
: node_or_way(way_restriction)
: node_or_way(way_restriction), is_only(is_only)
{
flags.is_only = is_only;
}

explicit TurnRestriction()
Expand Down Expand Up @@ -254,7 +235,7 @@ struct TurnRestriction

bool operator==(const TurnRestriction &other) const
{
if (!(flags == other.flags))
if (is_only != other.is_only)
return false;

if (Type() != other.Type())
Expand Down Expand Up @@ -284,7 +265,7 @@ struct TurnRestriction
auto const &node = AsNodeRestriction();
representation = node.ToString();
}
representation += " is_only: " + std::to_string(flags.is_only);
representation += " is_only: " + std::to_string(is_only);
return representation;
}
};
Expand Down
1 change: 0 additions & 1 deletion include/extractor/restriction_map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ namespace osrm
{
namespace extractor
{

/**
\brief Efficent look up if an edge is the start + via node of a TurnRestriction
EdgeBasedEdgeFactory decides by it if edges are inserted or geometry is compressed
Expand Down
4 changes: 2 additions & 2 deletions include/extractor/restriction_parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

#include "extractor/restriction.hpp"

#include <boost/optional.hpp>
#include <boost/optional/optional.hpp>

#include <string>
#include <vector>

Expand Down Expand Up @@ -37,7 +38,6 @@ class ScriptingEnvironment;
* ...----(a)-----(via)------(b)----...
* So it can be represented by the tripe (a, via, b).
*/

class RestrictionParser
{
public:
Expand Down
20 changes: 9 additions & 11 deletions include/extractor/serialization.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ inline void write(storage::io::FileWriter &writer, const WayRestriction &restric

inline void read(storage::io::FileReader &reader, TurnRestriction &restriction)
{
reader.ReadInto(restriction.flags);
reader.ReadInto(restriction.is_only);
if (restriction.Type() == RestrictionType::WAY_RESTRICTION)
{
WayRestriction way_restriction;
Expand All @@ -181,7 +181,7 @@ inline void read(storage::io::FileReader &reader, TurnRestriction &restriction)

inline void write(storage::io::FileWriter &writer, const TurnRestriction &restriction)
{
writer.WriteOne(restriction.flags);
writer.WriteOne(restriction.is_only);
if (restriction.Type() == RestrictionType::WAY_RESTRICTION)
{
write(writer, boost::get<WayRestriction>(restriction.node_or_way));
Expand Down Expand Up @@ -211,7 +211,7 @@ inline void read(storage::io::FileReader &reader, ConditionalTurnRestriction &re
TurnRestriction base;
read(reader, base);
reinterpret_cast<TurnRestriction &>(restriction) = std::move(base);
auto num_conditions = reader.ReadElementCount64();
const auto num_conditions = reader.ReadElementCount64();
restriction.condition.resize(num_conditions);
for (uint64_t i = 0; i < num_conditions; i++)
{
Expand All @@ -228,19 +228,18 @@ inline void read(storage::io::FileReader &reader, std::vector<TurnRestriction> &
auto num_indices = reader.ReadElementCount64();
restrictions.reserve(num_indices);
TurnRestriction restriction;
while (num_indices > 0)
while (num_indices-- > 0)
{
read(reader, restriction);
restrictions.push_back(std::move(restriction));
num_indices--;
}
}

inline void write(storage::io::FileWriter &writer, const std::vector<TurnRestriction> &restrictions)
{
std::uint64_t num_indices = restrictions.size();
const auto num_indices = restrictions.size();
writer.WriteElementCount64(num_indices);
auto const write_restriction = [&writer](const auto &restriction) {
const auto write_restriction = [&writer](const auto &restriction) {
write(writer, restriction);
};
std::for_each(restrictions.begin(), restrictions.end(), write_restriction);
Expand All @@ -253,20 +252,19 @@ inline void read(storage::io::FileReader &reader,
auto num_indices = reader.ReadElementCount64();
restrictions.reserve(num_indices);
ConditionalTurnRestriction restriction;
while (num_indices > 0)
while (num_indices-- > 0)
{
read(reader, restriction);
restrictions.push_back(std::move(restriction));
num_indices--;
}
}

inline void write(storage::io::FileWriter &writer,
const std::vector<ConditionalTurnRestriction> &restrictions)
{
std::uint64_t num_indices = restrictions.size();
const auto num_indices = restrictions.size();
writer.WriteElementCount64(num_indices);
auto const write_restriction = [&writer](const auto &restriction) {
const auto write_restriction = [&writer](const auto &restriction) {
write(writer, restriction);
};
std::for_each(restrictions.begin(), restrictions.end(), write_restriction);
Expand Down
40 changes: 29 additions & 11 deletions include/extractor/way_restriction_map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <boost/unordered_map.hpp>

#include "extractor/restriction.hpp"
#include "util/integer_range.hpp"
#include "util/typedefs.hpp"

// Given the compressed representation of via-way turn restrictions, we provide a fast access into
Expand All @@ -28,39 +29,56 @@ class WayRestrictionMap
};
WayRestrictionMap(const std::vector<TurnRestriction> &turn_restrictions);

// check if an edge between two nodes is a restricted turn. The check needs to be performed
bool IsViaWay(const NodeID from, const NodeID to) const;

// check if an edge between two nodes is a restricted turn
bool IsStart(const NodeID from, const NodeID to) const;
bool IsEnd(const NodeID from, const NodeID to) const;

std::size_t Size() const;

// number of duplicated nodes
std::size_t NumberOfDuplicatedNodes() const;

// find the ID of the duplicated node (zero based) for a given restriction id
std::size_t DuplicatedNodeID(const std::size_t restriction_id) const;

// returns a representative for the duplicated way, consisting of the representative ID (first
// ID of the nodes restrictions) and the from/to vertices of the via-way
// This is used to construct edge based nodes that act as intermediate nodes.
std::vector<ViaWay> DuplicatedNodeRepresentatives() const;

std::vector<std::size_t> GetIDs(const NodeID from, const NodeID to) const;
// Access all duplicated NodeIDs for a set of nodes indicating a via way
util::range<std::size_t> DuplicatedNodeIDs(const NodeID from, const NodeID to) const;

// check whether a turn onto a given node is restricted, when coming from a duplicated node
bool IsRestricted(std::size_t duplicated_node, const NodeID to) const;

TurnRestriction const &GetRestriction(std::size_t) const;

// changes edge_based_node to the correct duplicated_node_id in case node_based_from,
// node_based_via, node_based_to can be identified with a restriction group
NodeID RemapIfRestricted(const NodeID edge_based_node,
const NodeID node_based_from,
const NodeID node_based_via,
const NodeID node_based_to,
const NodeID number_of_edge_based_nodes) const;

private:
std::size_t AsDuplicatedNodeID(const std::size_t restriction_id) const;

// access all restrictions that have the same starting way and via way. Any duplicated node
// represents the same in-way + via-way combination. This vector contains data about all
// restrictions and their assigned duplicated nodes. It indicates the minimum restriciton ID
// that is represented by the next node. The ID of a node is defined as the position of the
// lower bound of the restrictions ID within this array
//
// a - b
// |
// y - c - x
//
// restriction nodes | restriction id
// a - b - c - x : 5
// a - b - c - y : 6
//
// EBN: 0 . | 2 | 3 | 4 ...
// duplicated node groups: ... | 5 | 7 | ...
std::vector<std::size_t> duplicated_node_groups;

boost::unordered_multimap<std::pair<NodeID, NodeID>, std::size_t> restriction_starts;
boost::unordered_multimap<std::pair<NodeID, NodeID>, std::size_t> restriction_ends;
boost::unordered_multimap<std::pair<NodeID, NodeID>, std::size_t> via_ways;

std::vector<TurnRestriction> restriction_data;
};
Expand Down
2 changes: 1 addition & 1 deletion include/util/serialization.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ template <typename EdgeDataT>
inline void read(storage::io::FileReader &reader, DynamicGraph<EdgeDataT> &graph)
{
storage::serialization::read(reader, graph.node_array);
auto num_edges = reader.ReadElementCount64();
const auto num_edges = reader.ReadElementCount64();
graph.edge_list.resize(num_edges);
for (auto index : irange<std::size_t>(0, num_edges))
{
Expand Down
21 changes: 11 additions & 10 deletions include/util/typedefs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,17 @@ static_assert(std::is_pod<OSMNodeID>(), "OSMNodeID is not a valid alias");
using OSMWayID = osrm::Alias<std::uint64_t, tag::osm_way_id>;
static_assert(std::is_pod<OSMWayID>(), "OSMWayID is not a valid alias");

static const OSMNodeID SPECIAL_OSM_NODEID = OSMNodeID{std::numeric_limits<std::uint64_t>::max()};
static const OSMWayID SPECIAL_OSM_WAYID = OSMWayID{std::numeric_limits<std::uint64_t>::max()};

static const OSMNodeID MAX_OSM_NODEID = OSMNodeID{std::numeric_limits<std::uint64_t>::max()};
static const OSMNodeID MIN_OSM_NODEID = OSMNodeID{std::numeric_limits<std::uint64_t>::min()};
static const OSMWayID MAX_OSM_WAYID = OSMWayID{std::numeric_limits<std::uint64_t>::max()};
static const OSMWayID MIN_OSM_WAYID = OSMWayID{std::numeric_limits<std::uint64_t>::min()};

using OSMNodeID_weak = std::uint64_t;
using OSMEdgeID_weak = std::uint64_t;
static const OSMNodeID SPECIAL_OSM_NODEID =
OSMNodeID{std::numeric_limits<OSMNodeID::value_type>::max()};
static const OSMWayID SPECIAL_OSM_WAYID =
OSMWayID{std::numeric_limits<OSMWayID::value_type>::max()};

static const OSMNodeID MAX_OSM_NODEID =
OSMNodeID{std::numeric_limits<OSMNodeID::value_type>::max()};
static const OSMNodeID MIN_OSM_NODEID =
OSMNodeID{std::numeric_limits<OSMNodeID::value_type>::min()};
static const OSMWayID MAX_OSM_WAYID = OSMWayID{std::numeric_limits<OSMWayID::value_type>::max()};
static const OSMWayID MIN_OSM_WAYID = OSMWayID{std::numeric_limits<OSMWayID::value_type>::min()};

using NodeID = std::uint32_t;
using EdgeID = std::uint32_t;
Expand Down
3 changes: 0 additions & 3 deletions src/engine/guidance/post_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
#include <limits>
#include <utility>

#include "util/debug.hpp"

using osrm::util::angularDeviation;
using osrm::extractor::guidance::getTurnDirection;
using osrm::extractor::guidance::hasRampType;
Expand Down Expand Up @@ -253,7 +251,6 @@ void closeOffRoundabout(const bool on_roundabout,
// that we come across.
std::vector<RouteStep> postProcess(std::vector<RouteStep> steps)
{
util::guidance::print(steps);
// the steps should always include the first/last step in form of a location
BOOST_ASSERT(steps.size() >= 2);
if (steps.size() == 2)
Expand Down
Loading

0 comments on commit 29e0cc7

Please sign in to comment.