Routing datastructure more seperated from data of original edges
This commit is contained in:
+14
-13
@@ -93,38 +93,39 @@ public:
|
||||
EdgeBasedEdge(const EdgeT & myEdge ) :
|
||||
_source(myEdge.source),
|
||||
_target(myEdge.target),
|
||||
_via(myEdge.data.via),
|
||||
_nameID1(myEdge.data.nameID),
|
||||
_edgeID(myEdge.data.via),
|
||||
// _nameID1(myEdge.data.nameID),
|
||||
_weight(myEdge.data.distance),
|
||||
_forward(myEdge.data.forward),
|
||||
_backward(myEdge.data.backward),
|
||||
_turnInstruction(myEdge.data.turnInstruction) { }
|
||||
_backward(myEdge.data.backward)//,
|
||||
// _turnInstruction(myEdge.data.turnInstruction)
|
||||
{ }
|
||||
|
||||
/** Default constructor. target and weight are set to 0.*/
|
||||
EdgeBasedEdge() :
|
||||
_source(0), _target(0), _via(0), _nameID1(0), _weight(0), _forward(0), _backward(0), _turnInstruction(0) { assert(false); } //shall not be used.
|
||||
_source(0), _target(0), _edgeID(0)/*, _nameID1(0)*/, _weight(0), _forward(0), _backward(0)/*, _turnInstruction(0)*/ { assert(false); } //shall not be used.
|
||||
|
||||
explicit EdgeBasedEdge(NodeID s, NodeID t, NodeID v, unsigned n1, EdgeWeight w, bool f, bool b, short ty) :
|
||||
_source(s), _target(t), _via(v), _nameID1(n1), _weight(w), _forward(f), _backward(b), _turnInstruction(ty) { assert(ty >= 0); }
|
||||
explicit EdgeBasedEdge(NodeID s, NodeID t, NodeID v, /*unsigned n1,*/ EdgeWeight w, bool f, bool b/*, short ty*/) :
|
||||
_source(s), _target(t), _edgeID(v), /*_nameID1(n1),*/ _weight(w), _forward(f), _backward(b)/*, _turnInstruction(ty)*/ { assert(ty >= 0); }
|
||||
|
||||
NodeID target() const {return _target; }
|
||||
NodeID source() const {return _source; }
|
||||
EdgeWeight weight() const {return _weight; }
|
||||
NodeID via() const { return _via; }
|
||||
short turnInstruction() const { assert(_turnInstruction >= 0); return _turnInstruction; }
|
||||
NodeID id() const { return _edgeID; }
|
||||
// short turnInstruction() const { assert(_turnInstruction >= 0); return _turnInstruction; }
|
||||
bool isBackward() const { return _backward; }
|
||||
bool isForward() const { return _forward; }
|
||||
|
||||
unsigned getNameIDOfTurnTarget() const { return _nameID1; }
|
||||
// unsigned getNameIDOfTurnTarget() const { return _nameID1; }
|
||||
|
||||
NodeID _source;
|
||||
NodeID _target;
|
||||
NodeID _via;
|
||||
unsigned _nameID1;
|
||||
NodeID _edgeID;
|
||||
// unsigned _nameID1;
|
||||
EdgeWeight _weight;
|
||||
bool _forward;
|
||||
bool _backward;
|
||||
short _turnInstruction;
|
||||
// short _turnInstruction;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
||||
#include <vector>
|
||||
|
||||
#include "../typedefs.h"
|
||||
#include "../DataStructures/QueryEdge.h"
|
||||
#include "NNGrid.h"
|
||||
#include "PhantomNodes.h"
|
||||
|
||||
@@ -44,27 +45,51 @@ public:
|
||||
~NodeInformationHelpDesk() {
|
||||
delete readOnlyGrid;
|
||||
}
|
||||
void initNNGrid(std::ifstream& in) {
|
||||
void initNNGrid(std::ifstream& nodesInstream, std::ifstream& edgesInStream) {
|
||||
INFO("Loading node data");
|
||||
NodeInfo b;
|
||||
while(!in.eof()) {
|
||||
in.read((char *)&b, sizeof(NodeInfo));
|
||||
while(!nodesInstream.eof()) {
|
||||
nodesInstream.read((char *)&b, sizeof(NodeInfo));
|
||||
coordinateVector.push_back(_Coordinate(b.lat, b.lon));
|
||||
}
|
||||
std::vector<_Coordinate>(coordinateVector).swap(coordinateVector);
|
||||
numberOfNodes = coordinateVector.size();
|
||||
in.close();
|
||||
readOnlyGrid->OpenIndexFiles();
|
||||
nodesInstream.close();
|
||||
|
||||
INFO("Loading edge data");
|
||||
unsigned numberOfOrigEdges(0);
|
||||
edgesInStream.read((char*)&numberOfOrigEdges, sizeof(unsigned));
|
||||
origEdgeData.resize(numberOfOrigEdges);
|
||||
edgesInStream.read((char*)&(origEdgeData[0]), numberOfOrigEdges*sizeof(OriginalEdgeData));
|
||||
edgesInStream.close();
|
||||
INFO("Loaded " << numberOfOrigEdges << " orig edges");
|
||||
INFO("Opening NN indices");
|
||||
readOnlyGrid->OpenIndexFiles();
|
||||
}
|
||||
|
||||
void initNNGrid() {
|
||||
readOnlyGrid->OpenIndexFiles();
|
||||
}
|
||||
|
||||
inline int getLatitudeOfNode(const NodeID node) const { return coordinateVector.at(node).lat; }
|
||||
inline int getLatitudeOfNode(const unsigned id) const {
|
||||
const NodeID node = origEdgeData.at(id).viaNode;
|
||||
return coordinateVector.at(node).lat;
|
||||
}
|
||||
|
||||
inline int getLongitudeOfNode(const NodeID node) const { return coordinateVector.at(node).lon; }
|
||||
inline int getLongitudeOfNode(const unsigned id) const {
|
||||
const NodeID node = origEdgeData.at(id).viaNode;
|
||||
return coordinateVector.at(node).lon;
|
||||
}
|
||||
|
||||
inline NodeID getNumberOfNodes() const { return numberOfNodes; }
|
||||
inline unsigned getNameIndexFromEdgeID(const unsigned id) const {
|
||||
return origEdgeData.at(id).nameID;
|
||||
}
|
||||
|
||||
inline short getTurnInstructionFromEdgeID(const unsigned id) const {
|
||||
return origEdgeData.at(id).turnInstruction;
|
||||
}
|
||||
|
||||
inline NodeID getNumberOfNodes() const { return numberOfNodes; }
|
||||
inline NodeID getNumberOfNodes2() const { return coordinateVector.size(); }
|
||||
|
||||
inline void FindNearestNodeCoordForLatLon(const _Coordinate& coord, _Coordinate& result) const {
|
||||
@@ -88,6 +113,8 @@ public:
|
||||
|
||||
private:
|
||||
std::vector<_Coordinate> coordinateVector;
|
||||
std::vector<OriginalEdgeData> origEdgeData;
|
||||
|
||||
ReadOnlyGrid * readOnlyGrid;
|
||||
unsigned numberOfNodes;
|
||||
unsigned checkSum;
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
open source routing machine
|
||||
Copyright (C) Dennis Luxen, others 2010
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU AFFERO General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
or see http://www.gnu.org/licenses/agpl.txt.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#ifndef QUERYEDGE_H_
|
||||
#define QUERYEDGE_H_
|
||||
|
||||
#include <climits>
|
||||
|
||||
#include "../typedefs.h"
|
||||
|
||||
struct OriginalEdgeData{
|
||||
explicit OriginalEdgeData(NodeID v, unsigned n, short t) : viaNode(v), nameID(n), turnInstruction(t) {}
|
||||
OriginalEdgeData() : viaNode(UINT_MAX), nameID(UINT_MAX), turnInstruction(SHRT_MAX) {}
|
||||
NodeID viaNode;
|
||||
unsigned nameID;
|
||||
short turnInstruction;
|
||||
};
|
||||
|
||||
struct QueryEdge {
|
||||
NodeID source;
|
||||
NodeID target;
|
||||
struct EdgeData {
|
||||
NodeID id;
|
||||
int distance;
|
||||
bool shortcut:1;
|
||||
bool forward:1;
|
||||
bool backward:1;
|
||||
} data;
|
||||
bool operator<( const QueryEdge& right ) const {
|
||||
if ( source != right.source )
|
||||
return source < right.source;
|
||||
return target < right.target;
|
||||
}
|
||||
|
||||
//sorts by source and other attributes
|
||||
static bool CompareBySource( const QueryEdge& left, const QueryEdge& right ) {
|
||||
if ( left.source != right.source )
|
||||
return left.source < right.source;
|
||||
int l = ( left.data.forward ? -1 : 0 ) + ( left.data.backward ? -1 : 0 );
|
||||
int r = ( right.data.forward ? -1 : 0 ) + ( right.data.backward ? -1 : 0 );
|
||||
if ( l != r )
|
||||
return l < r;
|
||||
if ( left.target != right.target )
|
||||
return left.target < right.target;
|
||||
return left.data.distance < right.data.distance;
|
||||
}
|
||||
|
||||
bool operator== ( const QueryEdge& right ) const {
|
||||
return ( source == right.source && target == right.target && data.distance == right.data.distance &&
|
||||
data.shortcut == right.data.shortcut && data.forward == right.data.forward && data.backward == right.data.backward
|
||||
&& data.id == right.data.id
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* QUERYEDGE_H_ */
|
||||
@@ -28,6 +28,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
||||
#include <boost/thread.hpp>
|
||||
|
||||
#include "BinaryHeap.h"
|
||||
#include "NodeInformationHelpDesk.h"
|
||||
#include "PhantomNodes.h"
|
||||
#include "../Util/StringUtil.h"
|
||||
#include "../typedefs.h"
|
||||
@@ -376,8 +377,9 @@ public:
|
||||
return ed.via;
|
||||
}
|
||||
|
||||
inline std::string GetEscapedNameForNameID(const NodeID nameID) const {
|
||||
return ((nameID >= _names.size() || nameID == 0) ? std::string("") : HTMLEntitize(_names.at(nameID)));
|
||||
inline std::string GetEscapedNameForNameID(const unsigned nameID) const {
|
||||
INFO("Getting name for ID: " << nameID);
|
||||
return ((nameID >= _names.size() || nameID == 0) ? std::string("") : HTMLEntitize(_names.at(nameID)));
|
||||
}
|
||||
|
||||
inline std::string GetEscapedNameForEdgeBasedEdgeID(const unsigned edgeID) const {
|
||||
@@ -517,13 +519,14 @@ private:
|
||||
|
||||
const EdgeData& ed = _graph->GetEdgeData(smallestEdge);
|
||||
if(ed.shortcut) {//unpack
|
||||
const NodeID middle = ed.via;
|
||||
const NodeID middle = ed.id;
|
||||
//again, we need to this in reversed order
|
||||
recursionStack.push(std::make_pair(middle, edge.second));
|
||||
recursionStack.push(std::make_pair(edge.first, middle));
|
||||
} else {
|
||||
assert(!ed.shortcut);
|
||||
unpackedPath.push_back(_PathData(ed.via, ed.nameID, ed.turnInstruction, ed.distance) );
|
||||
//TODO: Hier die lookups in den nodehelpdeks machen
|
||||
unpackedPath.push_back(_PathData(ed.id, nodeHelpDesk->getNameIndexFromEdgeID(ed.id), nodeHelpDesk->getTurnInstructionFromEdgeID(ed.id), ed.distance) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user