[osrm] Store node data to map osrm to mwm

This commit is contained in:
Denis Koronchik 2014-09-02 17:23:02 +03:00 committed by Alex Zolotarev
parent 634b5c52e1
commit 59214f805d
4 changed files with 107 additions and 0 deletions

View file

@ -77,6 +77,11 @@ void EdgeBasedGraphFactory::GetEdgeBasedNodes(std::vector<EdgeBasedNode> &nodes)
nodes.swap(m_edge_based_node_list);
}
void EdgeBasedGraphFactory::GetEdgeBasedNodeData(std::vector<NodeData> &data)
{
data.swap(m_edge_based_node_data);
}
void
EdgeBasedGraphFactory::InsertEdgeBasedNode(const NodeID u, const NodeID v, const bool belongs_to_tiny_cc)
{
@ -264,6 +269,10 @@ void EdgeBasedGraphFactory::Run(const std::string &original_edge_data_filename,
RenumberEdges();
TIMER_STOP(renumber);
TIMER_START(generate_node_data);
GenerateEdgeBasedNodeData();
TIMER_STOP(generate_node_data);
TIMER_START(generate_nodes);
GenerateEdgeExpandedNodes();
TIMER_STOP(generate_nodes);
@ -279,6 +288,7 @@ void EdgeBasedGraphFactory::Run(const std::string &original_edge_data_filename,
SimpleLogger().Write() << "Renumbering edges: " << TIMER_SEC(renumber) << "s";
SimpleLogger().Write() << "Generating nodes: " << TIMER_SEC(generate_nodes) << "s";
SimpleLogger().Write() << "Generating edges: " << TIMER_SEC(generate_edges) << "s";
SimpleLogger().Write() << "Generating node data: " << TIMER_SEC(generate_node_data) << "s";
}
void EdgeBasedGraphFactory::CompressGeometry()
@ -465,6 +475,60 @@ void EdgeBasedGraphFactory::RenumberEdges()
m_number_of_edge_based_nodes = numbered_edges_count;
}
void EdgeBasedGraphFactory::GenerateEdgeBasedNodeData()
{
m_edge_based_node_data.resize(m_number_of_edge_based_nodes);
std::vector<bool> found;
found.resize(m_number_of_edge_based_nodes, false);
for (NodeID current_node = 0; current_node < m_node_based_graph->GetNumberOfNodes();
++current_node)
{
for (EdgeID current_edge : m_node_based_graph->GetAdjacentEdgeRange(current_node))
{
EdgeData &edge_data = m_node_based_graph->GetEdgeData(current_edge);
if (!edge_data.forward)
{
continue;
}
NodeID target = m_node_based_graph->GetTarget(current_edge);
NodeData data;
data.lat1 = m_node_info_list[current_node].lat / COORDINATE_PRECISION;
data.lon1 = m_node_info_list[current_node].lon / COORDINATE_PRECISION;
data.lat2 = m_node_info_list[target].lat / COORDINATE_PRECISION;
data.lon2 = m_node_info_list[target].lon / COORDINATE_PRECISION;
data.way_id = edge_data.way_id;
if (found[edge_data.edgeBasedNodeID])
{
if (m_edge_based_node_data[edge_data.edgeBasedNodeID] != data)
{
std::cout << "Error!" << std::endl;
throw std::exception();
}
} else
{
found[edge_data.edgeBasedNodeID] = true;
m_edge_based_node_data[edge_data.edgeBasedNodeID] = data;
}
}
}
for (auto v : found)
{
if (!v)
{
std::cout << "Error2" << std::endl;
throw std::exception();
}
}
SimpleLogger().Write() << "Edge based node data count: " << m_edge_based_node_data.size();
}
/**
* Creates the nodes in the edge expanded graph from edges in the node-based graph.
*/

View file

@ -57,6 +57,24 @@ class EdgeBasedGraphFactory
EdgeBasedGraphFactory() = delete;
EdgeBasedGraphFactory(const EdgeBasedGraphFactory &) = delete;
struct NodeData
{
double lat1, lon1;
double lat2, lon2;
unsigned way_id;
bool operator == (NodeData const & other)
{
return (way_id == other.way_id) && (lat1 == other.lat1) && (lon1 == other.lon1)
&& (lat2 == other.lat2) && (lon2 == other.lon2);
}
bool operator != (NodeData const & other)
{
return !(*this == other);
}
};
struct SpeedProfileProperties;
explicit EdgeBasedGraphFactory(const std::shared_ptr<NodeBasedDynamicGraph> &node_based_graph,
@ -74,6 +92,8 @@ class EdgeBasedGraphFactory
void GetEdgeBasedNodes(std::vector<EdgeBasedNode> &nodes);
void GetEdgeBasedNodeData(std::vector<NodeData> &data);
TurnInstruction AnalyzeTurn(const NodeID u, const NodeID v, const NodeID w, double angle) const;
int GetTurnPenalty(double angle, lua_State *lua_state) const;
@ -106,11 +126,13 @@ class EdgeBasedGraphFactory
std::unordered_set<NodeID> m_traffic_lights;
std::unique_ptr<RestrictionMap> m_restriction_map;
std::vector<NodeData> m_edge_based_node_data;
GeometryCompressor m_geometry_compressor;
void CompressGeometry();
void RenumberEdges();
void GenerateEdgeBasedNodeData();
void GenerateEdgeExpandedNodes();
void GenerateEdgeExpandedEdges(const std::string &original_edge_data_filename,
lua_State *lua_state);

View file

@ -116,6 +116,7 @@ int Prepare::Process(int argc, char *argv[])
graph_out = input_path.string() + ".hsgr";
rtree_nodes_path = input_path.string() + ".ramIndex";
rtree_leafs_path = input_path.string() + ".fileIndex";
node_data_filename = input_path.string() + ".nodeData";
/*** Setup Scripting Environment ***/
// Create a new lua state
@ -521,6 +522,25 @@ void Prepare::BuildEdgeExpandedGraph(lua_State *lua_state,
edge_based_graph_factory->GetEdgeBasedEdges(edge_based_edge_list);
edge_based_graph_factory->GetEdgeBasedNodes(node_based_edge_list);
// serialize node data
std::vector<EdgeBasedGraphFactory::NodeData> data;
edge_based_graph_factory->GetEdgeBasedNodeData(data);
SimpleLogger().Write() << "Serialize node data";
std::ofstream stream;
stream.open(node_data_filename);
if (!stream.is_open())
{
SimpleLogger().Write() << "Can't open file " << node_data_filename;
throw std::exception();
}
uint32_t count = data.size();
stream.write((const char*)&count, sizeof(count));
stream.write((const char*)(&data[0]), data.size() * sizeof(EdgeBasedGraphFactory::NodeData));
stream.close();
delete edge_based_graph_factory;
node_based_graph.reset();

View file

@ -63,6 +63,7 @@ class Prepare
std::string graph_out;
std::string rtree_nodes_path;
std::string rtree_leafs_path;
std::string node_data_filename;
};
#endif // PREPARE_H