2014-11-28 06:13:18 -05:00
|
|
|
#ifndef NODE_BASED_GRAPH_HPP
|
|
|
|
#define NODE_BASED_GRAPH_HPP
|
|
|
|
|
2016-01-02 11:13:44 -05:00
|
|
|
#include "util/dynamic_graph.hpp"
|
2016-01-11 10:55:22 -05:00
|
|
|
#include "extractor/node_based_edge.hpp"
|
2016-01-02 11:13:44 -05:00
|
|
|
#include "util/graph_utils.hpp"
|
2016-02-24 04:29:23 -05:00
|
|
|
#include "engine/guidance/classification_data.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>
|
|
|
|
|
2016-01-05 10:51:13 -05:00
|
|
|
namespace osrm
|
|
|
|
{
|
|
|
|
namespace util
|
|
|
|
{
|
|
|
|
|
2014-05-08 17:29:24 -04:00
|
|
|
struct NodeBasedEdgeData
|
|
|
|
{
|
|
|
|
NodeBasedEdgeData()
|
2015-06-28 16:13:54 -04:00
|
|
|
: distance(INVALID_EDGE_WEIGHT), edge_id(SPECIAL_NODEID),
|
2016-01-05 06:04:04 -05:00
|
|
|
name_id(std::numeric_limits<unsigned>::max()), access_restricted(false), reversed(false),
|
|
|
|
roundabout(false), travel_mode(TRAVEL_MODE_INACCESSIBLE)
|
2014-05-08 17:29:24 -04:00
|
|
|
{
|
|
|
|
}
|
2014-05-05 19:35:43 -04:00
|
|
|
|
2016-01-05 06:04:04 -05:00
|
|
|
NodeBasedEdgeData(int distance,
|
|
|
|
unsigned edge_id,
|
|
|
|
unsigned name_id,
|
|
|
|
bool access_restricted,
|
|
|
|
bool reversed,
|
|
|
|
bool roundabout,
|
|
|
|
bool startpoint,
|
2016-01-05 10:51:13 -05:00
|
|
|
extractor::TravelMode travel_mode)
|
2015-06-28 18:42:22 -04:00
|
|
|
: distance(distance), edge_id(edge_id), name_id(name_id),
|
2016-01-05 06:04:04 -05:00
|
|
|
access_restricted(access_restricted), reversed(reversed), roundabout(roundabout),
|
|
|
|
startpoint(startpoint), travel_mode(travel_mode)
|
2015-06-28 09:30:40 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-05-05 19:35:43 -04:00
|
|
|
int distance;
|
2015-06-28 16:13:54 -04:00
|
|
|
unsigned edge_id;
|
|
|
|
unsigned name_id;
|
|
|
|
bool access_restricted : 1;
|
2015-06-28 18:42:22 -04:00
|
|
|
bool reversed : 1;
|
2014-05-08 17:29:24 -04:00
|
|
|
bool roundabout : 1;
|
2015-12-11 17:11:04 -05:00
|
|
|
bool startpoint : 1;
|
2016-01-05 10:51:13 -05:00
|
|
|
extractor::TravelMode travel_mode : 4;
|
2016-02-24 04:29:23 -05:00
|
|
|
engine::guidance::RoadClassificationData road_classification;
|
2014-05-08 17:29:24 -04:00
|
|
|
|
2015-05-12 19:26:54 -04:00
|
|
|
bool IsCompatibleTo(const NodeBasedEdgeData &other) const
|
2014-05-08 17:29:24 -04:00
|
|
|
{
|
2016-02-29 10:24:42 -05:00
|
|
|
//TODO roundabout/startpoint/access_restricted should all be part of this??
|
2015-06-28 18:42:22 -04:00
|
|
|
return (reversed == other.reversed) && (name_id == other.name_id) &&
|
2016-02-26 11:33:18 -05:00
|
|
|
(travel_mode == other.travel_mode && road_classification == other.road_classification);
|
2014-05-05 19:35:43 -04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
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.
|
2014-10-21 12:34:50 -04:00
|
|
|
inline std::shared_ptr<NodeBasedDynamicGraph>
|
2016-01-05 06:04:04 -05:00
|
|
|
NodeBasedDynamicGraphFromEdges(std::size_t 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-01-07 19:31:57 -05:00
|
|
|
input_edge_list, [](NodeBasedDynamicGraph::InputEdge &output_edge,
|
|
|
|
const extractor::NodeBasedEdge &input_edge)
|
2014-05-08 17:29:24 -04:00
|
|
|
{
|
2015-06-28 18:42:22 -04:00
|
|
|
output_edge.data.distance = static_cast<int>(input_edge.weight);
|
|
|
|
BOOST_ASSERT(output_edge.data.distance > 0);
|
2014-05-05 19:35:43 -04:00
|
|
|
|
2015-06-28 18:42:22 -04:00
|
|
|
output_edge.data.roundabout = input_edge.roundabout;
|
|
|
|
output_edge.data.name_id = input_edge.name_id;
|
|
|
|
output_edge.data.access_restricted = input_edge.access_restricted;
|
|
|
|
output_edge.data.travel_mode = input_edge.travel_mode;
|
2015-12-11 17:11:04 -05:00
|
|
|
output_edge.data.startpoint = input_edge.startpoint;
|
2016-02-24 04:29:23 -05:00
|
|
|
output_edge.data.road_classification = input_edge.road_classification;
|
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
|
|
|
|
2015-05-24 11:25:38 -04:00
|
|
|
auto graph = std::make_shared<NodeBasedDynamicGraph>(
|
2015-01-27 11:44:46 -05:00
|
|
|
static_cast<NodeBasedDynamicGraph::NodeIterator>(number_of_nodes), edges_list);
|
2015-05-24 11:25:38 -04:00
|
|
|
|
|
|
|
return graph;
|
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
|