Refactoring members of NodeInformationHelpDesk
This commit is contained in:
parent
d851dd7196
commit
161487d6c2
@ -40,70 +40,63 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
|||||||
typedef EdgeBasedGraphFactory::EdgeBasedNode RTreeLeaf;
|
typedef EdgeBasedGraphFactory::EdgeBasedNode RTreeLeaf;
|
||||||
|
|
||||||
class NodeInformationHelpDesk : boost::noncopyable {
|
class NodeInformationHelpDesk : boost::noncopyable {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
NodeInformationHelpDesk(
|
NodeInformationHelpDesk(
|
||||||
const std::string & ramIndexInput,
|
const std::string & ram_index_filename,
|
||||||
const std::string & fileIndexInput,
|
const std::string & mem_index_filename,
|
||||||
const std::string & nodes_filename,
|
const std::string & nodes_filename,
|
||||||
const std::string & edges_filename,
|
const std::string & edges_filename,
|
||||||
const unsigned number_of_nodes,
|
const unsigned m_number_of_nodes,
|
||||||
const unsigned check_sum
|
const unsigned m_check_sum
|
||||||
) : number_of_nodes(number_of_nodes), check_sum(check_sum)
|
) :
|
||||||
|
m_number_of_nodes(m_number_of_nodes),
|
||||||
|
m_check_sum(m_check_sum)
|
||||||
{
|
{
|
||||||
if ( ramIndexInput.empty() ) {
|
if ( ram_index_filename.empty() ) {
|
||||||
throw OSRMException("no ram index file name in server ini");
|
throw OSRMException("no ram index file name in server ini");
|
||||||
}
|
}
|
||||||
if ( fileIndexInput.empty() ) {
|
if ( mem_index_filename.empty() ) {
|
||||||
throw OSRMException("no mem index file name in server ini");
|
throw OSRMException("no mem index file name in server ini");
|
||||||
}
|
}
|
||||||
if ( nodes_filename.empty() ) {
|
if ( nodes_filename.empty() ) {
|
||||||
throw OSRMException("no nodes file name in server ini");
|
throw OSRMException("no nodes file name in server ini");
|
||||||
}
|
}
|
||||||
if ( edges_filename.empty() ) {
|
if ( edges_filename.empty() ) {
|
||||||
throw OSRMException("no edges file name in server ini");
|
throw OSRMException("no edges file name in server ini");
|
||||||
}
|
}
|
||||||
|
|
||||||
read_only_rtree = new StaticRTree<RTreeLeaf>(
|
m_ro_rtree_ptr = new StaticRTree<RTreeLeaf>(
|
||||||
ramIndexInput,
|
ram_index_filename,
|
||||||
fileIndexInput
|
mem_index_filename
|
||||||
);
|
);
|
||||||
BOOST_ASSERT_MSG(
|
BOOST_ASSERT_MSG(
|
||||||
0 == coordinateVector.size(),
|
0 == m_coordinate_list.size(),
|
||||||
"Coordinate vector not empty"
|
"Coordinate vector not empty"
|
||||||
);
|
);
|
||||||
|
|
||||||
LoadNodesAndEdges(nodes_filename, edges_filename);
|
LoadNodesAndEdges(nodes_filename, edges_filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Todo: Shared memory mechanism
|
|
||||||
~NodeInformationHelpDesk() {
|
~NodeInformationHelpDesk() {
|
||||||
delete read_only_rtree;
|
delete m_ro_rtree_ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int getLatitudeOfNode(const unsigned id) const {
|
inline FixedPointCoordinate GetCoordinateOfNode(const unsigned id) const {
|
||||||
const NodeID node = origEdgeData_viaNode.at(id);
|
const NodeID node = m_via_node_list.at(id);
|
||||||
return coordinateVector.at(node).lat;
|
return m_coordinate_list.at(node);
|
||||||
}
|
|
||||||
|
|
||||||
inline int getLongitudeOfNode(const unsigned id) const {
|
|
||||||
const NodeID node = origEdgeData_viaNode.at(id);
|
|
||||||
return coordinateVector.at(node).lon;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline unsigned getNameIndexFromEdgeID(const unsigned id) const {
|
|
||||||
return origEdgeData_nameID.at(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline TurnInstruction getTurnInstructionFromEdgeID(const unsigned id) const {
|
|
||||||
return origEdgeData_turnInstruction.at(id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline NodeID getNumberOfNodes() const {
|
inline unsigned GetNameIndexFromEdgeID(const unsigned id) const {
|
||||||
return number_of_nodes;
|
return m_name_ID_list.at(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline TurnInstruction GetTurnInstructionForEdgeID(const unsigned id) const {
|
||||||
|
return m_turn_instruction_list.at(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline NodeID getNumberOfNodes2() const {
|
inline NodeID GetNumberOfNodes() const {
|
||||||
return coordinateVector.size();
|
return m_number_of_nodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool FindNearestNodeCoordForLatLon(
|
inline bool FindNearestNodeCoordForLatLon(
|
||||||
@ -112,12 +105,12 @@ public:
|
|||||||
const unsigned zoom_level = 18
|
const unsigned zoom_level = 18
|
||||||
) const {
|
) const {
|
||||||
PhantomNode resulting_phantom_node;
|
PhantomNode resulting_phantom_node;
|
||||||
bool foundNode = FindPhantomNodeForCoordinate(
|
bool found_node = FindPhantomNodeForCoordinate(
|
||||||
input_coordinate,
|
input_coordinate,
|
||||||
resulting_phantom_node, zoom_level
|
resulting_phantom_node, zoom_level
|
||||||
);
|
);
|
||||||
result = resulting_phantom_node.location;
|
result = resulting_phantom_node.location;
|
||||||
return foundNode;
|
return found_node;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool FindPhantomNodeForCoordinate(
|
inline bool FindPhantomNodeForCoordinate(
|
||||||
@ -125,7 +118,7 @@ public:
|
|||||||
PhantomNode & resulting_phantom_node,
|
PhantomNode & resulting_phantom_node,
|
||||||
const unsigned zoom_level
|
const unsigned zoom_level
|
||||||
) const {
|
) const {
|
||||||
return read_only_rtree->FindPhantomNodeForCoordinate(
|
return m_ro_rtree_ptr->FindPhantomNodeForCoordinate(
|
||||||
input_coordinate,
|
input_coordinate,
|
||||||
resulting_phantom_node,
|
resulting_phantom_node,
|
||||||
zoom_level
|
zoom_level
|
||||||
@ -133,7 +126,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
inline unsigned GetCheckSum() const {
|
inline unsigned GetCheckSum() const {
|
||||||
return check_sum;
|
return m_check_sum;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -157,48 +150,63 @@ private:
|
|||||||
throw OSRMException("edges file is empty");
|
throw OSRMException("edges file is empty");
|
||||||
}
|
}
|
||||||
|
|
||||||
boost::filesystem::ifstream nodes_input_stream(nodes_file, std::ios::binary);
|
boost::filesystem::ifstream nodes_input_stream(
|
||||||
boost::filesystem::ifstream edges_input_stream(edges_file, std::ios::binary);
|
nodes_file,
|
||||||
|
std::ios::binary
|
||||||
|
);
|
||||||
|
|
||||||
SimpleLogger().Write(logDEBUG) << "Loading node data";
|
boost::filesystem::ifstream edges_input_stream(
|
||||||
NodeInfo b;
|
edges_file, std::ios::binary
|
||||||
|
);
|
||||||
|
|
||||||
|
SimpleLogger().Write(logDEBUG)
|
||||||
|
<< "Loading node data";
|
||||||
|
NodeInfo current_node;
|
||||||
while(!nodes_input_stream.eof()) {
|
while(!nodes_input_stream.eof()) {
|
||||||
nodes_input_stream.read((char *)&b, sizeof(NodeInfo));
|
nodes_input_stream.read((char *)¤t_node, sizeof(NodeInfo));
|
||||||
coordinateVector.push_back(FixedPointCoordinate(b.lat, b.lon));
|
m_coordinate_list.push_back(
|
||||||
|
FixedPointCoordinate(
|
||||||
|
current_node.lat,
|
||||||
|
current_node.lon
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
std::vector<FixedPointCoordinate>(coordinateVector).swap(coordinateVector);
|
std::vector<FixedPointCoordinate>(m_coordinate_list).swap(m_coordinate_list);
|
||||||
nodes_input_stream.close();
|
nodes_input_stream.close();
|
||||||
|
|
||||||
SimpleLogger().Write(logDEBUG) << "Loading edge data";
|
SimpleLogger().Write(logDEBUG)
|
||||||
unsigned numberOfOrigEdges(0);
|
<< "Loading edge data";
|
||||||
edges_input_stream.read((char*)&numberOfOrigEdges, sizeof(unsigned));
|
unsigned number_of_edges = 0;
|
||||||
origEdgeData_viaNode.resize(numberOfOrigEdges);
|
edges_input_stream.read((char*)&number_of_edges, sizeof(unsigned));
|
||||||
origEdgeData_nameID.resize(numberOfOrigEdges);
|
m_via_node_list.resize(number_of_edges);
|
||||||
origEdgeData_turnInstruction.resize(numberOfOrigEdges);
|
m_name_ID_list.resize(number_of_edges);
|
||||||
|
m_turn_instruction_list.resize(number_of_edges);
|
||||||
|
|
||||||
OriginalEdgeData deserialized_originalEdgeData;
|
OriginalEdgeData current_edge_data;
|
||||||
for(unsigned i = 0; i < numberOfOrigEdges; ++i) {
|
for(unsigned i = 0; i < number_of_edges; ++i) {
|
||||||
edges_input_stream.read(
|
edges_input_stream.read(
|
||||||
(char*)&(deserialized_originalEdgeData),
|
(char*)&(current_edge_data),
|
||||||
sizeof(OriginalEdgeData)
|
sizeof(OriginalEdgeData)
|
||||||
);
|
);
|
||||||
origEdgeData_viaNode[i] = deserialized_originalEdgeData.viaNode;
|
m_via_node_list[i] = current_edge_data.viaNode;
|
||||||
origEdgeData_nameID[i] = deserialized_originalEdgeData.nameID;
|
m_name_ID_list[i] = current_edge_data.nameID;
|
||||||
origEdgeData_turnInstruction[i] = deserialized_originalEdgeData.turnInstruction;
|
m_turn_instruction_list[i] = current_edge_data.turnInstruction;
|
||||||
}
|
}
|
||||||
edges_input_stream.close();
|
edges_input_stream.close();
|
||||||
SimpleLogger().Write(logDEBUG) << "Loaded " << numberOfOrigEdges << " orig edges";
|
SimpleLogger().Write(logDEBUG)
|
||||||
SimpleLogger().Write(logDEBUG) << "Opening NN indices";
|
<< "Loaded " << number_of_edges << " orig edges";
|
||||||
|
SimpleLogger().Write(logDEBUG)
|
||||||
|
<< "Opening NN indices";
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<FixedPointCoordinate> coordinateVector;
|
std::vector<FixedPointCoordinate> m_coordinate_list;
|
||||||
std::vector<NodeID> origEdgeData_viaNode;
|
std::vector<NodeID> m_via_node_list;
|
||||||
std::vector<unsigned> origEdgeData_nameID;
|
std::vector<unsigned> m_name_ID_list;
|
||||||
std::vector<TurnInstruction> origEdgeData_turnInstruction;
|
std::vector<TurnInstruction> m_turn_instruction_list;
|
||||||
|
|
||||||
StaticRTree<EdgeBasedGraphFactory::EdgeBasedNode> * read_only_rtree;
|
StaticRTree<EdgeBasedGraphFactory::EdgeBasedNode> * m_ro_rtree_ptr;
|
||||||
const unsigned number_of_nodes;
|
const unsigned m_number_of_nodes;
|
||||||
const unsigned check_sum;
|
const unsigned m_check_sum;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /*NODEINFORMATIONHELPDESK_H_*/
|
#endif /*NODEINFORMATIONHELPDESK_H_*/
|
||||||
|
@ -24,26 +24,26 @@ SearchEngine::SearchEngine(
|
|||||||
QueryGraph * g,
|
QueryGraph * g,
|
||||||
NodeInformationHelpDesk * nh,
|
NodeInformationHelpDesk * nh,
|
||||||
std::vector<std::string> & n
|
std::vector<std::string> & n
|
||||||
) :
|
) :
|
||||||
_queryData(g, nh, n),
|
_queryData(g, nh, n),
|
||||||
shortestPath(_queryData),
|
shortestPath(_queryData),
|
||||||
alternativePaths(_queryData)
|
alternativePaths(_queryData)
|
||||||
{}
|
{}
|
||||||
SearchEngine::~SearchEngine() {}
|
|
||||||
|
SearchEngine::~SearchEngine() {}
|
||||||
|
|
||||||
void SearchEngine::GetCoordinatesForNodeID(
|
void SearchEngine::GetCoordinatesForNodeID(
|
||||||
NodeID id,
|
NodeID id,
|
||||||
FixedPointCoordinate& result
|
FixedPointCoordinate& result
|
||||||
) const {
|
) const {
|
||||||
result.lat = _queryData.nodeHelpDesk->getLatitudeOfNode(id);
|
result = _queryData.nodeHelpDesk->GetCoordinateOfNode(id);
|
||||||
result.lon = _queryData.nodeHelpDesk->getLongitudeOfNode(id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SearchEngine::FindPhantomNodeForCoordinate(
|
void SearchEngine::FindPhantomNodeForCoordinate(
|
||||||
const FixedPointCoordinate & location,
|
const FixedPointCoordinate & location,
|
||||||
PhantomNode & result,
|
PhantomNode & result,
|
||||||
const unsigned zoomLevel
|
const unsigned zoomLevel
|
||||||
) const {
|
) const {
|
||||||
_queryData.nodeHelpDesk->FindPhantomNodeForCoordinate(
|
_queryData.nodeHelpDesk->FindPhantomNodeForCoordinate(
|
||||||
location,
|
location,
|
||||||
result, zoomLevel
|
result, zoomLevel
|
||||||
@ -53,17 +53,20 @@ void SearchEngine::FindPhantomNodeForCoordinate(
|
|||||||
NodeID SearchEngine::GetNameIDForOriginDestinationNodeID(
|
NodeID SearchEngine::GetNameIDForOriginDestinationNodeID(
|
||||||
const NodeID s,
|
const NodeID s,
|
||||||
const NodeID t
|
const NodeID t
|
||||||
) const {
|
) const {
|
||||||
if(s == t){
|
if(s == t) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
EdgeID e = _queryData.graph->FindEdge(s, t);
|
EdgeID e = _queryData.graph->FindEdge(s, t);
|
||||||
if(e == UINT_MAX) {
|
if(e == UINT_MAX) {
|
||||||
e = _queryData.graph->FindEdge( t, s );
|
e = _queryData.graph->FindEdge( t, s );
|
||||||
}
|
}
|
||||||
|
|
||||||
if(UINT_MAX == e) {
|
if(UINT_MAX == e) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(e != UINT_MAX);
|
assert(e != UINT_MAX);
|
||||||
const QueryEdge::EdgeData ed = _queryData.graph->GetEdgeData(e);
|
const QueryEdge::EdgeData ed = _queryData.graph->GetEdgeData(e);
|
||||||
return ed.id;
|
return ed.id;
|
||||||
@ -86,4 +89,3 @@ SearchEngineHeapPtr SearchEngineData::backwardHeap2;
|
|||||||
|
|
||||||
SearchEngineHeapPtr SearchEngineData::forwardHeap3;
|
SearchEngineHeapPtr SearchEngineData::forwardHeap3;
|
||||||
SearchEngineHeapPtr SearchEngineData::backwardHeap3;
|
SearchEngineHeapPtr SearchEngineData::backwardHeap3;
|
||||||
|
|
||||||
|
@ -22,12 +22,12 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
|||||||
|
|
||||||
void SearchEngineData::InitializeOrClearFirstThreadLocalStorage() {
|
void SearchEngineData::InitializeOrClearFirstThreadLocalStorage() {
|
||||||
if(!forwardHeap.get()) {
|
if(!forwardHeap.get()) {
|
||||||
forwardHeap.reset(new QueryHeap(nodeHelpDesk->getNumberOfNodes()));
|
forwardHeap.reset(new QueryHeap(nodeHelpDesk->GetNumberOfNodes()));
|
||||||
} else {
|
} else {
|
||||||
forwardHeap->Clear();
|
forwardHeap->Clear();
|
||||||
}
|
}
|
||||||
if(!backwardHeap.get()) {
|
if(!backwardHeap.get()) {
|
||||||
backwardHeap.reset(new QueryHeap(nodeHelpDesk->getNumberOfNodes()));
|
backwardHeap.reset(new QueryHeap(nodeHelpDesk->GetNumberOfNodes()));
|
||||||
} else {
|
} else {
|
||||||
backwardHeap->Clear();
|
backwardHeap->Clear();
|
||||||
}
|
}
|
||||||
@ -35,12 +35,12 @@ void SearchEngineData::InitializeOrClearFirstThreadLocalStorage() {
|
|||||||
|
|
||||||
void SearchEngineData::InitializeOrClearSecondThreadLocalStorage() {
|
void SearchEngineData::InitializeOrClearSecondThreadLocalStorage() {
|
||||||
if(!forwardHeap2.get()) {
|
if(!forwardHeap2.get()) {
|
||||||
forwardHeap2.reset(new QueryHeap(nodeHelpDesk->getNumberOfNodes()));
|
forwardHeap2.reset(new QueryHeap(nodeHelpDesk->GetNumberOfNodes()));
|
||||||
} else {
|
} else {
|
||||||
forwardHeap2->Clear();
|
forwardHeap2->Clear();
|
||||||
}
|
}
|
||||||
if(!backwardHeap2.get()) {
|
if(!backwardHeap2.get()) {
|
||||||
backwardHeap2.reset(new QueryHeap(nodeHelpDesk->getNumberOfNodes()));
|
backwardHeap2.reset(new QueryHeap(nodeHelpDesk->GetNumberOfNodes()));
|
||||||
} else {
|
} else {
|
||||||
backwardHeap2->Clear();
|
backwardHeap2->Clear();
|
||||||
}
|
}
|
||||||
@ -48,12 +48,12 @@ void SearchEngineData::InitializeOrClearSecondThreadLocalStorage() {
|
|||||||
|
|
||||||
void SearchEngineData::InitializeOrClearThirdThreadLocalStorage() {
|
void SearchEngineData::InitializeOrClearThirdThreadLocalStorage() {
|
||||||
if(!forwardHeap3.get()) {
|
if(!forwardHeap3.get()) {
|
||||||
forwardHeap3.reset(new QueryHeap(nodeHelpDesk->getNumberOfNodes()));
|
forwardHeap3.reset(new QueryHeap(nodeHelpDesk->GetNumberOfNodes()));
|
||||||
} else {
|
} else {
|
||||||
forwardHeap3->Clear();
|
forwardHeap3->Clear();
|
||||||
}
|
}
|
||||||
if(!backwardHeap3.get()) {
|
if(!backwardHeap3.get()) {
|
||||||
backwardHeap3.reset(new QueryHeap(nodeHelpDesk->getNumberOfNodes()));
|
backwardHeap3.reset(new QueryHeap(nodeHelpDesk->GetNumberOfNodes()));
|
||||||
} else {
|
} else {
|
||||||
backwardHeap3->Clear();
|
backwardHeap3->Clear();
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
|||||||
#ifndef STATICGRAPH_H_INCLUDED
|
#ifndef STATICGRAPH_H_INCLUDED
|
||||||
#define STATICGRAPH_H_INCLUDED
|
#define STATICGRAPH_H_INCLUDED
|
||||||
|
|
||||||
|
#include "../DataStructures/Percent.h"
|
||||||
#include "../Util/SimpleLogger.h"
|
#include "../Util/SimpleLogger.h"
|
||||||
#include "../typedefs.h"
|
#include "../typedefs.h"
|
||||||
|
|
||||||
|
@ -93,7 +93,7 @@ public:
|
|||||||
if(checksumOK && i < routeParameters.hints.size() && "" != routeParameters.hints[i]) {
|
if(checksumOK && i < routeParameters.hints.size() && "" != routeParameters.hints[i]) {
|
||||||
// SimpleLogger().Write() <<"Decoding hint: " << routeParameters.hints[i] << " for location index " << i;
|
// SimpleLogger().Write() <<"Decoding hint: " << routeParameters.hints[i] << " for location index " << i;
|
||||||
DecodeObjectFromBase64(routeParameters.hints[i], phantomNodeVector[i]);
|
DecodeObjectFromBase64(routeParameters.hints[i], phantomNodeVector[i]);
|
||||||
if(phantomNodeVector[i].isValid(nodeHelpDesk->getNumberOfNodes())) {
|
if(phantomNodeVector[i].isValid(nodeHelpDesk->GetNumberOfNodes())) {
|
||||||
// SimpleLogger().Write() << "Decoded hint " << i << " successfully";
|
// SimpleLogger().Write() << "Decoded hint " << i << " successfully";
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -148,7 +148,14 @@ public:
|
|||||||
recursionStack.push(std::make_pair(edge.first, middle));
|
recursionStack.push(std::make_pair(edge.first, middle));
|
||||||
} else {
|
} else {
|
||||||
assert(!ed.shortcut);
|
assert(!ed.shortcut);
|
||||||
unpackedPath.push_back(_PathData(ed.id, _queryData.nodeHelpDesk->getNameIndexFromEdgeID(ed.id), _queryData.nodeHelpDesk->getTurnInstructionFromEdgeID(ed.id), ed.distance) );
|
unpackedPath.push_back(
|
||||||
|
_PathData(
|
||||||
|
ed.id,
|
||||||
|
_queryData.nodeHelpDesk->GetNameIndexFromEdgeID(ed.id),
|
||||||
|
_queryData.nodeHelpDesk->GetTurnInstructionForEdgeID(ed.id),
|
||||||
|
ed.distance
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user