2014-11-28 06:13:18 -05:00
|
|
|
#ifndef NODE_BASED_GRAPH_HPP
|
|
|
|
#define NODE_BASED_GRAPH_HPP
|
|
|
|
|
2017-06-27 18:01:05 -04:00
|
|
|
#include "extractor/class_data.hpp"
|
2016-06-24 10:06:45 -04:00
|
|
|
#include "extractor/guidance/road_classification.hpp"
|
2016-01-11 10:55:22 -05:00
|
|
|
#include "extractor/node_based_edge.hpp"
|
2017-09-25 09:37:11 -04:00
|
|
|
#include "extractor/node_data_container.hpp"
|
2016-05-27 15:05:04 -04:00
|
|
|
#include "util/dynamic_graph.hpp"
|
2016-01-02 11:13:44 -05:00
|
|
|
#include "util/graph_utils.hpp"
|
2014-05-05 19:35:43 -04:00
|
|
|
|
2014-05-22 13:07:29 -04:00
|
|
|
#include <tbb/parallel_sort.h>
|
|
|
|
|
2014-05-09 09:12:42 -04:00
|
|
|
#include <memory>
|
2017-09-25 09:37:11 -04:00
|
|
|
#include <utility>
|
2014-05-09 09:12:42 -04:00
|
|
|
|
2016-01-05 10:51:13 -05:00
|
|
|
namespace osrm
|
|
|
|
{
|
|
|
|
namespace util
|
|
|
|
{
|
|
|
|
|
2014-05-08 17:29:24 -04:00
|
|
|
struct NodeBasedEdgeData
|
|
|
|
{
|
|
|
|
NodeBasedEdgeData()
|
2017-09-25 09:37:11 -04:00
|
|
|
: weight(INVALID_EDGE_WEIGHT), duration(INVALID_EDGE_WEIGHT), geometry_id({0, false}),
|
2017-11-09 08:37:16 -05:00
|
|
|
reversed(false), annotation_data(-1)
|
2014-05-08 17:29:24 -04:00
|
|
|
{
|
|
|
|
}
|
2014-05-05 19:35:43 -04:00
|
|
|
|
2016-05-12 12:50:10 -04:00
|
|
|
NodeBasedEdgeData(EdgeWeight weight,
|
|
|
|
EdgeWeight duration,
|
2017-09-25 09:37:11 -04:00
|
|
|
GeometryID geometry_id,
|
2016-01-05 06:04:04 -05:00
|
|
|
bool reversed,
|
2017-09-25 09:37:11 -04:00
|
|
|
extractor::NodeBasedEdgeClassification flags,
|
|
|
|
AnnotationID annotation_data)
|
|
|
|
: weight(weight), duration(duration), geometry_id(geometry_id), reversed(reversed),
|
2017-11-09 08:37:16 -05:00
|
|
|
flags(flags), annotation_data(annotation_data)
|
2015-06-28 09:30:40 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-05-12 12:50:10 -04:00
|
|
|
EdgeWeight weight;
|
|
|
|
EdgeWeight duration;
|
2017-09-25 09:37:11 -04:00
|
|
|
GeometryID geometry_id;
|
2015-06-28 18:42:22 -04:00
|
|
|
bool reversed : 1;
|
2017-09-25 09:37:11 -04:00
|
|
|
extractor::NodeBasedEdgeClassification flags;
|
|
|
|
AnnotationID annotation_data;
|
2014-05-05 19:35:43 -04:00
|
|
|
};
|
|
|
|
|
2017-09-25 09:37:11 -04:00
|
|
|
// Check if two edge data elements can be compressed into a single edge (i.e. match in terms of
|
|
|
|
// their meta-data).
|
|
|
|
inline bool CanBeCompressed(const NodeBasedEdgeData &lhs,
|
|
|
|
const NodeBasedEdgeData &rhs,
|
|
|
|
const extractor::EdgeBasedNodeDataContainer &node_data_container)
|
|
|
|
{
|
|
|
|
if (!(lhs.flags == rhs.flags))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
auto const &lhs_annotation = node_data_container.GetAnnotation(lhs.annotation_data);
|
|
|
|
auto const &rhs_annotation = node_data_container.GetAnnotation(rhs.annotation_data);
|
|
|
|
|
|
|
|
if (lhs_annotation.is_left_hand_driving != rhs_annotation.is_left_hand_driving)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (lhs_annotation.travel_mode != rhs_annotation.travel_mode)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return lhs_annotation.classes == rhs_annotation.classes;
|
|
|
|
}
|
|
|
|
|
2014-08-19 07:01:38 -04:00
|
|
|
using NodeBasedDynamicGraph = DynamicGraph<NodeBasedEdgeData>;
|
2014-05-05 19:35:43 -04:00
|
|
|
|
2015-06-28 18:42:22 -04:00
|
|
|
/// Factory method to create NodeBasedDynamicGraph from NodeBasedEdges
|
2015-12-11 17:11:04 -05:00
|
|
|
/// Since DynamicGraph expects directed edges, we need to insert
|
2015-06-28 18:42:22 -04:00
|
|
|
/// two edges for undirected edges.
|
2017-09-25 09:37:11 -04:00
|
|
|
inline NodeBasedDynamicGraph
|
2016-06-11 11:23:29 -04:00
|
|
|
NodeBasedDynamicGraphFromEdges(NodeID number_of_nodes,
|
2016-01-05 10:51:13 -05:00
|
|
|
const std::vector<extractor::NodeBasedEdge> &input_edge_list)
|
2014-05-08 17:29:24 -04:00
|
|
|
{
|
2016-01-05 06:04:04 -05:00
|
|
|
auto edges_list = directedEdgesFromCompressed<NodeBasedDynamicGraph::InputEdge>(
|
2016-05-27 15:05:04 -04:00
|
|
|
input_edge_list,
|
|
|
|
[](NodeBasedDynamicGraph::InputEdge &output_edge,
|
|
|
|
const extractor::NodeBasedEdge &input_edge) {
|
2016-05-12 12:50:10 -04:00
|
|
|
output_edge.data.weight = input_edge.weight;
|
|
|
|
output_edge.data.duration = input_edge.duration;
|
2017-09-25 09:37:11 -04:00
|
|
|
output_edge.data.flags = input_edge.flags;
|
|
|
|
output_edge.data.annotation_data = input_edge.annotation_data;
|
2016-05-12 12:50:10 -04:00
|
|
|
|
|
|
|
BOOST_ASSERT(output_edge.data.weight > 0);
|
|
|
|
BOOST_ASSERT(output_edge.data.duration > 0);
|
2016-01-05 06:04:04 -05:00
|
|
|
});
|
2014-05-05 19:35:43 -04:00
|
|
|
|
2015-09-10 05:36:02 -04:00
|
|
|
tbb::parallel_sort(edges_list.begin(), edges_list.end());
|
2015-05-04 12:43:16 -04:00
|
|
|
|
2017-09-25 09:37:11 -04:00
|
|
|
return NodeBasedDynamicGraph(number_of_nodes, edges_list);
|
2014-05-05 19:35:43 -04:00
|
|
|
}
|
2016-01-05 10:51:13 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-28 06:13:18 -05:00
|
|
|
#endif // NODE_BASED_GRAPH_HPP
|