2013-08-14 12:43:01 -04:00
|
|
|
// This class constructs the edge-expanded routing graph
|
2011-10-10 11:52:47 -04:00
|
|
|
|
2014-11-28 04:29:56 -05:00
|
|
|
#ifndef EDGE_BASED_GRAPH_FACTORY_HPP_
|
|
|
|
#define EDGE_BASED_GRAPH_FACTORY_HPP_
|
2011-10-10 11:52:47 -04:00
|
|
|
|
2016-01-02 11:13:44 -05:00
|
|
|
#include "extractor/compressed_edge_container.hpp"
|
2017-08-01 11:18:12 -04:00
|
|
|
#include "extractor/conditional_turn_penalty.hpp"
|
2016-04-26 07:27:40 -04:00
|
|
|
#include "extractor/edge_based_edge.hpp"
|
2017-05-16 13:22:41 -04:00
|
|
|
#include "extractor/edge_based_node_segment.hpp"
|
2016-05-12 12:50:10 -04:00
|
|
|
#include "extractor/extraction_turn.hpp"
|
2018-02-09 13:32:09 -05:00
|
|
|
#include "extractor/maneuver_override.hpp"
|
2018-03-21 07:10:02 -04:00
|
|
|
#include "extractor/name_table.hpp"
|
2017-03-15 10:30:12 -04:00
|
|
|
#include "extractor/nbg_to_ebg.hpp"
|
2017-05-11 03:13:59 -04:00
|
|
|
#include "extractor/node_data_container.hpp"
|
2016-01-02 11:13:44 -05:00
|
|
|
#include "extractor/query_node.hpp"
|
2017-08-01 11:18:12 -04:00
|
|
|
#include "extractor/restriction_index.hpp"
|
2018-01-05 08:33:53 -05:00
|
|
|
#include "extractor/turn_lane_types.hpp"
|
2017-07-11 08:22:28 -04:00
|
|
|
#include "extractor/way_restriction_map.hpp"
|
2017-03-15 10:30:12 -04:00
|
|
|
|
2017-06-07 00:31:07 -04:00
|
|
|
#include "util/concurrent_id_map.hpp"
|
2017-02-02 10:55:19 -05:00
|
|
|
#include "util/deallocating_vector.hpp"
|
2016-04-26 07:27:40 -04:00
|
|
|
#include "util/node_based_graph.hpp"
|
|
|
|
#include "util/typedefs.hpp"
|
2013-11-25 13:05:58 -05:00
|
|
|
|
2017-03-04 05:52:40 -05:00
|
|
|
#include "storage/io.hpp"
|
|
|
|
|
2013-06-26 09:49:00 -04:00
|
|
|
#include <algorithm>
|
2016-01-29 06:42:08 -05:00
|
|
|
#include <cstddef>
|
2016-04-26 07:27:40 -04:00
|
|
|
#include <cstdint>
|
2014-01-04 06:10:22 -05:00
|
|
|
#include <iosfwd>
|
2014-05-09 08:21:33 -04:00
|
|
|
#include <memory>
|
2013-06-26 09:49:00 -04:00
|
|
|
#include <queue>
|
2014-05-09 08:21:33 -04:00
|
|
|
#include <string>
|
2014-05-09 12:40:07 -04:00
|
|
|
#include <unordered_map>
|
|
|
|
#include <unordered_set>
|
2013-06-26 09:49:00 -04:00
|
|
|
#include <vector>
|
2013-02-23 02:33:33 -05:00
|
|
|
|
2016-01-05 10:51:13 -05:00
|
|
|
namespace osrm
|
|
|
|
{
|
|
|
|
namespace extractor
|
|
|
|
{
|
|
|
|
|
2016-07-11 11:44:58 -04:00
|
|
|
class ScriptingEnvironment;
|
|
|
|
|
2016-06-24 01:01:37 -04:00
|
|
|
namespace lookup
|
|
|
|
{
|
2016-05-12 12:50:10 -04:00
|
|
|
#pragma pack(push, 1)
|
|
|
|
struct TurnIndexBlock
|
2016-06-24 01:01:37 -04:00
|
|
|
{
|
2017-05-11 06:13:52 -04:00
|
|
|
NodeID from_id;
|
|
|
|
NodeID via_id;
|
|
|
|
NodeID to_id;
|
2016-07-06 13:11:56 -04:00
|
|
|
};
|
|
|
|
#pragma pack(pop)
|
2016-05-12 12:50:10 -04:00
|
|
|
static_assert(std::is_trivial<TurnIndexBlock>::value, "TurnIndexBlock is not trivial");
|
2017-05-11 06:13:52 -04:00
|
|
|
static_assert(sizeof(TurnIndexBlock) == 12, "TurnIndexBlock is not packed correctly");
|
2017-02-02 10:55:19 -05:00
|
|
|
} // ns lookup
|
|
|
|
|
|
|
|
struct NodeBasedGraphToEdgeBasedGraphMappingWriter; // fwd. decl
|
2016-06-24 01:01:37 -04:00
|
|
|
|
2014-05-09 08:21:33 -04:00
|
|
|
class EdgeBasedGraphFactory
|
2014-05-08 17:07:16 -04:00
|
|
|
{
|
|
|
|
public:
|
2014-05-09 08:21:33 -04:00
|
|
|
EdgeBasedGraphFactory(const EdgeBasedGraphFactory &) = delete;
|
Takes care of proper special member generation globally, fixes #1689
Phew, a lot of classes were affected by this. The rationale for the
changes are as follows:
- When a type X declares any constructor, the default constructor is
not declared, so there is no need for X() = delete there. In fact,
there is brutal difference between those two: deleted members
participate in overload resolution, but not-declared members do not!
- When a type X wants to be non-copyable (e.g. to be only movable, like
threads, unique_ptrs, and so on), you can either do it by inheriting
from boost::noncopyable (the old way), or better declare both (!) the
copy constructor _and_ the copy assignment operator as deleted:
X(X const&) = delete;
X& operator=(X const&) = delete;
We had tons of types with deleted copy constructors that were lacking
a corresponding deleted copy assignment operator, making them still
copyable and you wouldn't even notice (read: scary)!
References:
- http://accu.org/content/conf2014/Howard_Hinnant_Accu_2014.pdf
- http://www.boost.org/doc/libs/master/libs/core/doc/html/core/noncopyable.html
Note: I know, I'm quoting Hinnant's extraordinary slides a lot, but
getting the sematic right here is so incredibly important.
2016-01-27 05:20:55 -05:00
|
|
|
EdgeBasedGraphFactory &operator=(const EdgeBasedGraphFactory &) = delete;
|
2014-05-09 08:21:33 -04:00
|
|
|
|
2017-09-25 09:37:11 -04:00
|
|
|
explicit EdgeBasedGraphFactory(const util::NodeBasedDynamicGraph &node_based_graph,
|
|
|
|
EdgeBasedNodeDataContainer &node_data_container,
|
|
|
|
const CompressedEdgeContainer &compressed_edge_container,
|
2016-07-22 03:08:40 -04:00
|
|
|
const std::unordered_set<NodeID> &barrier_nodes,
|
|
|
|
const std::unordered_set<NodeID> &traffic_lights,
|
2017-04-02 19:58:06 -04:00
|
|
|
const std::vector<util::Coordinate> &coordinates,
|
2018-03-21 07:10:02 -04:00
|
|
|
const NameTable &name_table,
|
2017-11-09 08:37:16 -05:00
|
|
|
const std::unordered_set<EdgeID> &segregated_edges,
|
2018-01-08 13:12:06 -05:00
|
|
|
const LaneDescriptionMap &lane_description_map);
|
2014-05-08 17:07:16 -04:00
|
|
|
|
2016-07-11 11:44:58 -04:00
|
|
|
void Run(ScriptingEnvironment &scripting_environment,
|
2016-05-12 12:50:10 -04:00
|
|
|
const std::string &turn_weight_penalties_filename,
|
|
|
|
const std::string &turn_duration_penalties_filename,
|
|
|
|
const std::string &turn_penalties_index_filename,
|
2017-07-11 08:22:28 -04:00
|
|
|
const std::string &cnbg_ebg_mapping_path,
|
2017-08-01 11:18:12 -04:00
|
|
|
const std::string &conditional_penalties_filename,
|
2018-02-09 13:32:09 -05:00
|
|
|
const std::string &maneuver_overrides_filename,
|
2017-07-27 05:42:13 -04:00
|
|
|
const RestrictionMap &node_restriction_map,
|
2017-08-01 11:18:12 -04:00
|
|
|
const ConditionalRestrictionMap &conditional_restriction_map,
|
2018-02-09 13:32:09 -05:00
|
|
|
const WayRestrictionMap &way_restriction_map,
|
|
|
|
const std::vector<UnresolvedManeuverOverride> &maneuver_overrides);
|
2014-05-08 17:07:16 -04:00
|
|
|
|
Takes care of proper special member generation globally, fixes #1689
Phew, a lot of classes were affected by this. The rationale for the
changes are as follows:
- When a type X declares any constructor, the default constructor is
not declared, so there is no need for X() = delete there. In fact,
there is brutal difference between those two: deleted members
participate in overload resolution, but not-declared members do not!
- When a type X wants to be non-copyable (e.g. to be only movable, like
threads, unique_ptrs, and so on), you can either do it by inheriting
from boost::noncopyable (the old way), or better declare both (!) the
copy constructor _and_ the copy assignment operator as deleted:
X(X const&) = delete;
X& operator=(X const&) = delete;
We had tons of types with deleted copy constructors that were lacking
a corresponding deleted copy assignment operator, making them still
copyable and you wouldn't even notice (read: scary)!
References:
- http://accu.org/content/conf2014/Howard_Hinnant_Accu_2014.pdf
- http://www.boost.org/doc/libs/master/libs/core/doc/html/core/noncopyable.html
Note: I know, I'm quoting Hinnant's extraordinary slides a lot, but
getting the sematic right here is so incredibly important.
2016-01-27 05:20:55 -05:00
|
|
|
// The following get access functions destroy the content in the factory
|
2016-01-05 10:51:13 -05:00
|
|
|
void GetEdgeBasedEdges(util::DeallocatingVector<EdgeBasedEdge> &edges);
|
2017-05-16 13:22:41 -04:00
|
|
|
void GetEdgeBasedNodeSegments(std::vector<EdgeBasedNodeSegment> &nodes);
|
2015-12-11 17:11:04 -05:00
|
|
|
void GetStartPointMarkers(std::vector<bool> &node_is_startpoint);
|
2016-01-07 04:33:47 -05:00
|
|
|
void GetEdgeBasedNodeWeights(std::vector<EdgeWeight> &output_node_weights);
|
2018-02-01 10:00:15 -05:00
|
|
|
std::uint32_t GetConnectivityChecksum() const;
|
2014-05-08 17:07:16 -04:00
|
|
|
|
2017-07-11 08:22:28 -04:00
|
|
|
std::uint64_t GetNumberOfEdgeBasedNodes() const;
|
2015-07-01 11:55:54 -04:00
|
|
|
|
2014-05-08 17:07:16 -04:00
|
|
|
private:
|
2016-01-05 10:51:13 -05:00
|
|
|
using EdgeData = util::NodeBasedDynamicGraph::EdgeData;
|
2014-05-05 19:35:43 -04:00
|
|
|
|
2017-08-01 11:18:12 -04:00
|
|
|
struct Conditional
|
|
|
|
{
|
|
|
|
// the edge based nodes allow for a unique identification of conditionals
|
|
|
|
NodeID from_node;
|
|
|
|
NodeID to_node;
|
|
|
|
ConditionalTurnPenalty penalty;
|
|
|
|
};
|
|
|
|
|
|
|
|
// assign the correct index to the penalty value stored in the conditional
|
|
|
|
std::vector<ConditionalTurnPenalty>
|
|
|
|
IndexConditionals(std::vector<Conditional> &&conditionals) const;
|
|
|
|
|
2016-01-05 06:04:04 -05:00
|
|
|
//! maps index from m_edge_based_node_list to ture/false if the node is an entry point to the
|
|
|
|
//! graph
|
2015-12-11 17:11:04 -05:00
|
|
|
std::vector<bool> m_edge_based_node_is_startpoint;
|
2016-01-07 04:33:47 -05:00
|
|
|
|
|
|
|
//! node weights that indicate the length of the segment (node based) represented by the
|
|
|
|
//! edge-based node
|
|
|
|
std::vector<EdgeWeight> m_edge_based_node_weights;
|
|
|
|
|
2015-12-11 17:11:04 -05:00
|
|
|
//! list of edge based nodes (compressed segments)
|
2017-05-16 13:22:41 -04:00
|
|
|
std::vector<EdgeBasedNodeSegment> m_edge_based_node_segments;
|
2017-09-25 09:37:11 -04:00
|
|
|
EdgeBasedNodeDataContainer &m_edge_based_node_container;
|
2016-01-05 10:51:13 -05:00
|
|
|
util::DeallocatingVector<EdgeBasedEdge> m_edge_based_edge_list;
|
2018-02-01 10:00:15 -05:00
|
|
|
std::uint32_t m_connectivity_checksum;
|
2017-07-11 08:22:28 -04:00
|
|
|
|
2017-07-27 05:42:13 -04:00
|
|
|
// The number of edge-based nodes is mostly made up out of the edges in the node-based graph.
|
2017-07-11 08:22:28 -04:00
|
|
|
// 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.
|
2017-07-27 05:42:13 -04:00
|
|
|
// See https://github.com/Project-OSRM/osrm-backend/issues/2681#issuecomment-313080353 for
|
|
|
|
// reference
|
2017-07-11 08:22:28 -04:00
|
|
|
std::uint64_t m_number_of_edge_based_nodes;
|
2011-11-09 10:12:05 -05:00
|
|
|
|
2017-04-02 19:58:06 -04:00
|
|
|
const std::vector<util::Coordinate> &m_coordinates;
|
2017-09-25 09:37:11 -04:00
|
|
|
const util::NodeBasedDynamicGraph &m_node_based_graph;
|
2015-04-21 04:43:02 -04:00
|
|
|
|
2016-01-05 06:04:04 -05:00
|
|
|
const std::unordered_set<NodeID> &m_barrier_nodes;
|
|
|
|
const std::unordered_set<NodeID> &m_traffic_lights;
|
2017-09-25 09:37:11 -04:00
|
|
|
const CompressedEdgeContainer &m_compressed_edge_container;
|
2012-02-29 14:02:04 -05:00
|
|
|
|
2018-03-21 07:10:02 -04:00
|
|
|
const NameTable &name_table;
|
2017-11-09 08:37:16 -05:00
|
|
|
const std::unordered_set<EdgeID> &segregated_edges;
|
2018-01-08 13:12:06 -05:00
|
|
|
const LaneDescriptionMap &lane_description_map;
|
2016-03-16 10:47:33 -04:00
|
|
|
|
2017-09-25 09:37:11 -04:00
|
|
|
// In the edge based graph, any traversable (non reversed) edge of the node-based graph forms a
|
|
|
|
// node of the edge-based graph. To be able to name these nodes, we loop over the node-based
|
|
|
|
// graph and create a mapping from edges (node-based) to nodes (edge-based). The mapping is
|
|
|
|
// essentially a prefix-sum over all previous non-reversed edges of the node-based graph.
|
|
|
|
unsigned LabelEdgeBasedNodes();
|
2017-02-02 10:55:19 -05:00
|
|
|
|
2017-07-27 05:42:13 -04:00
|
|
|
// During the generation of the edge-expanded nodes, we need to also generate duplicates that
|
|
|
|
// represent state during via-way restrictions (see
|
|
|
|
// https://github.com/Project-OSRM/osrm-backend/issues/2681#issuecomment-313080353). Access to
|
|
|
|
// the information on what to duplicate and how is provided via the way_restriction_map
|
2017-07-11 08:22:28 -04:00
|
|
|
std::vector<NBGToEBG> GenerateEdgeExpandedNodes(const WayRestrictionMap &way_restriction_map);
|
2017-05-03 05:48:43 -04:00
|
|
|
|
2017-07-27 05:42:13 -04:00
|
|
|
// Edge-expanded edges are generate for all valid turns. The validity can be checked via the
|
|
|
|
// restriction maps
|
2018-02-09 13:32:09 -05:00
|
|
|
void
|
|
|
|
GenerateEdgeExpandedEdges(ScriptingEnvironment &scripting_environment,
|
|
|
|
const std::string &turn_weight_penalties_filename,
|
|
|
|
const std::string &turn_duration_penalties_filename,
|
|
|
|
const std::string &turn_penalties_index_filename,
|
|
|
|
const std::string &conditional_turn_penalties_filename,
|
|
|
|
const std::string &maneuver_overrides_filename,
|
|
|
|
const RestrictionMap &node_restriction_map,
|
|
|
|
const ConditionalRestrictionMap &conditional_restriction_map,
|
|
|
|
const WayRestrictionMap &way_restriction_map,
|
|
|
|
const std::vector<UnresolvedManeuverOverride> &maneuver_overrides);
|
2014-05-08 17:07:16 -04:00
|
|
|
|
2017-03-15 10:30:12 -04:00
|
|
|
NBGToEBG InsertEdgeBasedNode(const NodeID u, const NodeID v);
|
2014-05-08 17:07:16 -04:00
|
|
|
|
2017-09-25 09:37:11 -04:00
|
|
|
// mapping of node-based edges to edge-based nodes
|
|
|
|
std::vector<NodeID> nbe_to_ebn_mapping;
|
2011-10-10 11:52:47 -04:00
|
|
|
};
|
2016-01-29 06:42:08 -05:00
|
|
|
} // namespace extractor
|
|
|
|
} // namespace osrm
|
2016-01-05 10:51:13 -05:00
|
|
|
|
2014-11-28 04:29:56 -05:00
|
|
|
#endif /* EDGE_BASED_GRAPH_FACTORY_HPP_ */
|