further refactoring of variable names

This commit is contained in:
Dennis Luxen 2013-09-20 13:08:18 +02:00
parent c85f6c1228
commit 0ef4f36d44

View File

@ -36,37 +36,36 @@ or see http://www.gnu.org/licenses/agpl.txt.
#include <stack> #include <stack>
template<class DataFacadeT> template<class DataFacadeT>
class BasicRoutingInterface : boost::noncopyable{ class BasicRoutingInterface : boost::noncopyable {
protected: protected:
DataFacadeT * facade; DataFacadeT * facade;
public: public:
BasicRoutingInterface(DataFacadeT * facade) : facade(facade) { } BasicRoutingInterface( DataFacadeT * facade ) : facade(facade) { }
virtual ~BasicRoutingInterface(){ }; virtual ~BasicRoutingInterface(){ };
inline void RoutingStep( inline void RoutingStep(
SearchEngineData::QueryHeap & _forwardHeap, SearchEngineData::QueryHeap & forward_heap,
SearchEngineData::QueryHeap & _backwardHeap, SearchEngineData::QueryHeap & reverse_heap,
NodeID *middle, NodeID * middle_node_id,
int *_upperbound, int * upper_bound,
const int edgeBasedOffset, const int edge_expansion_offset,
const bool forwardDirection const bool forward_direction
) const { ) const {
const NodeID node = _forwardHeap.DeleteMin(); const NodeID node = forward_heap.DeleteMin();
const int distance = _forwardHeap.GetKey(node); const int distance = forward_heap.GetKey(node);
//SimpleLogger().Write() << "Settled (" << _forwardHeap.GetData( node ).parent << "," << node << ")=" << distance; //SimpleLogger().Write() << "Settled (" << forward_heap.GetData( node ).parent << "," << node << ")=" << distance;
if(_backwardHeap.WasInserted(node) ){ if(reverse_heap.WasInserted(node) ){
const int newDistance = _backwardHeap.GetKey(node) + distance; const int new_distance = reverse_heap.GetKey(node) + distance;
if(newDistance < *_upperbound ){ if(new_distance < *upper_bound ){
if(newDistance>=0 ) { if( new_distance >= 0 ) {
*middle = node; *middle_node_id = node;
*_upperbound = newDistance; *upper_bound = new_distance;
} else {
} }
} }
} }
if(distance-edgeBasedOffset > *_upperbound){ if( (distance-edge_expansion_offset) > *upper_bound){
_forwardHeap.DeleteAll(); forward_heap.DeleteAll();
return; return;
} }
@ -77,15 +76,15 @@ public:
++edge ++edge
) { ) {
const typename DataFacadeT::EdgeData & data = facade->GetEdgeData(edge); const typename DataFacadeT::EdgeData & data = facade->GetEdgeData(edge);
bool backwardDirectionFlag = (!forwardDirection) ? data.forward : data.backward; bool backwardDirectionFlag = (!forward_direction) ? data.forward : data.backward;
if(backwardDirectionFlag) { if(backwardDirectionFlag) {
const NodeID to = facade->GetTarget(edge); const NodeID to = facade->GetTarget(edge);
const int edgeWeight = data.distance; const int edge_weight = data.distance;
BOOST_ASSERT_MSG( edgeWeight > 0, "edgeWeight invalid" ); BOOST_ASSERT_MSG( edge_weight > 0, "edge_weight invalid" );
if(_forwardHeap.WasInserted( to )) { if(forward_heap.WasInserted( to )) {
if(_forwardHeap.GetKey( to ) + edgeWeight < distance) { if(forward_heap.GetKey( to ) + edge_weight < distance) {
return; return;
} }
} }
@ -94,73 +93,84 @@ public:
for ( EdgeID edge = facade->BeginEdges( node ); edge < facade->EndEdges(node); ++edge ) { for ( EdgeID edge = facade->BeginEdges( node ); edge < facade->EndEdges(node); ++edge ) {
const typename DataFacadeT::EdgeData & data = facade->GetEdgeData(edge); const typename DataFacadeT::EdgeData & data = facade->GetEdgeData(edge);
bool forwardDirectionFlag = (forwardDirection ? data.forward : data.backward ); bool forward_directionFlag = (forward_direction ? data.forward : data.backward );
if(forwardDirectionFlag) { if(forward_directionFlag) {
const NodeID to = facade->GetTarget(edge); const NodeID to = facade->GetTarget(edge);
const int edgeWeight = data.distance; const int edge_weight = data.distance;
BOOST_ASSERT_MSG( edgeWeight > 0, "edgeWeight invalid" ); BOOST_ASSERT_MSG( edge_weight > 0, "edge_weight invalid" );
const int toDistance = distance + edgeWeight; const int to_distance = distance + edge_weight;
//New Node discovered -> Add to Heap + Node Info Storage //New Node discovered -> Add to Heap + Node Info Storage
if ( !_forwardHeap.WasInserted( to ) ) { if ( !forward_heap.WasInserted( to ) ) {
_forwardHeap.Insert( to, toDistance, node ); forward_heap.Insert( to, to_distance, node );
} }
//Found a shorter Path -> Update distance //Found a shorter Path -> Update distance
else if ( toDistance < _forwardHeap.GetKey( to ) ) { else if ( to_distance < forward_heap.GetKey( to ) ) {
_forwardHeap.GetData( to ).parent = node; forward_heap.GetData( to ).parent = node;
_forwardHeap.DecreaseKey( to, toDistance ); forward_heap.DecreaseKey( to, to_distance );
//new parent //new parent
} }
} }
} }
} }
inline void UnpackPath(const std::vector<NodeID> & packedPath, std::vector<_PathData> & unpackedPath) const { inline void UnpackPath(
const unsigned sizeOfPackedPath = packedPath.size(); const std::vector<NodeID> & packed_path,
std::stack<std::pair<NodeID, NodeID> > recursionStack; std::vector<_PathData> & unpacked_path
) const {
const unsigned packed_path_size = packed_path.size();
std::stack<std::pair<NodeID, NodeID> > recursion_stack;
//We have to push the path in reverse order onto the stack because it's LIFO. //We have to push the path in reverse order onto the stack because it's LIFO.
for(unsigned i = sizeOfPackedPath-1; i > 0; --i){ for(unsigned i = packed_path_size-1; i > 0; --i){
recursionStack.push(std::make_pair(packedPath[i-1], packedPath[i])); recursion_stack.push(std::make_pair(packed_path[i-1], packed_path[i]));
} }
std::pair<NodeID, NodeID> edge; std::pair<NodeID, NodeID> edge;
while(!recursionStack.empty()) { while(!recursion_stack.empty()) {
edge = recursionStack.top(); edge = recursion_stack.top();
recursionStack.pop(); recursion_stack.pop();
EdgeID smallestEdge = SPECIAL_EDGEID; EdgeID smaller_edge_id = SPECIAL_EDGEID;
int smallestWeight = INT_MAX; int edge_weight = INT_MAX;
for(EdgeID eit = facade->BeginEdges(edge.first);eit < facade->EndEdges(edge.first);++eit){ for(EdgeID eit = facade->BeginEdges(edge.first);eit < facade->EndEdges(edge.first);++eit){
const int weight = facade->GetEdgeData(eit).distance; const int weight = facade->GetEdgeData(eit).distance;
if(facade->GetTarget(eit) == edge.second && weight < smallestWeight && facade->GetEdgeData(eit).forward){ if(
smallestEdge = eit; (facade->GetTarget(eit) == edge.second) &&
smallestWeight = weight; (weight < edge_weight) &&
facade->GetEdgeData(eit).forward
){
smaller_edge_id = eit;
edge_weight = weight;
} }
} }
if(smallestEdge == SPECIAL_EDGEID){ if(smaller_edge_id == SPECIAL_EDGEID){
for(EdgeID eit = facade->BeginEdges(edge.second);eit < facade->EndEdges(edge.second);++eit){ for(EdgeID eit = facade->BeginEdges(edge.second); eit < facade->EndEdges(edge.second); ++eit){
const int weight = facade->GetEdgeData(eit).distance; const int weight = facade->GetEdgeData(eit).distance;
if(facade->GetTarget(eit) == edge.first && weight < smallestWeight && facade->GetEdgeData(eit).backward){ if(
smallestEdge = eit; (facade->GetTarget(eit) == edge.first) &&
smallestWeight = weight; (weight < edge_weight) &&
facade->GetEdgeData(eit).backward
){
smaller_edge_id = eit;
edge_weight = weight;
} }
} }
} }
BOOST_ASSERT_MSG(smallestWeight != INT_MAX, "edge id invalid"); BOOST_ASSERT_MSG(edge_weight != INT_MAX, "edge id invalid");
const typename DataFacadeT::EdgeData& ed = facade->GetEdgeData(smallestEdge); const typename DataFacadeT::EdgeData& ed = facade->GetEdgeData(smaller_edge_id);
if(ed.shortcut) {//unpack if(ed.shortcut) {//unpack
const NodeID middle = ed.id; const NodeID middle_node_id = ed.id;
//again, we need to this in reversed order //again, we need to this in reversed order
recursionStack.push(std::make_pair(middle, edge.second)); recursion_stack.push(std::make_pair(middle_node_id, edge.second));
recursionStack.push(std::make_pair(edge.first, middle)); recursion_stack.push(std::make_pair(edge.first, middle_node_id));
} else { } else {
BOOST_ASSERT_MSG(!ed.shortcut, "edge must be a shortcut"); BOOST_ASSERT_MSG(!ed.shortcut, "edge must be a shortcut");
unpackedPath.push_back( unpacked_path.push_back(
_PathData( _PathData(
ed.id, ed.id,
facade->GetNameIndexFromEdgeID(ed.id), facade->GetNameIndexFromEdgeID(ed.id),
@ -172,79 +182,95 @@ public:
} }
} }
inline void UnpackEdge(const NodeID s, const NodeID t, std::vector<NodeID> & unpackedPath) const { inline void UnpackEdge(
std::stack<std::pair<NodeID, NodeID> > recursionStack; const NodeID s,
recursionStack.push(std::make_pair(s,t)); const NodeID t,
std::vector<NodeID> & unpacked_path
) const {
std::stack<std::pair<NodeID, NodeID> > recursion_stack;
recursion_stack.push(std::make_pair(s,t));
std::pair<NodeID, NodeID> edge; std::pair<NodeID, NodeID> edge;
while(!recursionStack.empty()) { while(!recursion_stack.empty()) {
edge = recursionStack.top(); edge = recursion_stack.top();
recursionStack.pop(); recursion_stack.pop();
EdgeID smallestEdge = SPECIAL_EDGEID; EdgeID smaller_edge_id = SPECIAL_EDGEID;
int smallestWeight = INT_MAX; int edge_weight = INT_MAX;
for(EdgeID eit = facade->BeginEdges(edge.first);eit < facade->EndEdges(edge.first);++eit){ for(EdgeID eit = facade->BeginEdges(edge.first);eit < facade->EndEdges(edge.first);++eit){
const int weight = facade->GetEdgeData(eit).distance; const int weight = facade->GetEdgeData(eit).distance;
if(facade->GetTarget(eit) == edge.second && weight < smallestWeight && facade->GetEdgeData(eit).forward){ if(
smallestEdge = eit; (facade->GetTarget(eit) == edge.second) &&
smallestWeight = weight; (weight < edge_weight) &&
facade->GetEdgeData(eit).forward
){
smaller_edge_id = eit;
edge_weight = weight;
} }
} }
if(smallestEdge == SPECIAL_EDGEID){ if(smaller_edge_id == SPECIAL_EDGEID){
for(EdgeID eit = facade->BeginEdges(edge.second);eit < facade->EndEdges(edge.second);++eit){ for(EdgeID eit = facade->BeginEdges(edge.second);eit < facade->EndEdges(edge.second);++eit){
const int weight = facade->GetEdgeData(eit).distance; const int weight = facade->GetEdgeData(eit).distance;
if(facade->GetTarget(eit) == edge.first && weight < smallestWeight && facade->GetEdgeData(eit).backward){ if(
smallestEdge = eit; (facade->GetTarget(eit) == edge.first) &&
smallestWeight = weight; (weight < edge_weight) &&
facade->GetEdgeData(eit).backward
){
smaller_edge_id = eit;
edge_weight = weight;
} }
} }
} }
BOOST_ASSERT_MSG(smallestWeight != INT_MAX, "edge weight invalid"); BOOST_ASSERT_MSG(edge_weight != INT_MAX, "edge weight invalid");
const typename DataFacadeT::EdgeData& ed = facade->GetEdgeData(smallestEdge); const typename DataFacadeT::EdgeData& ed = facade->GetEdgeData(smaller_edge_id);
if(ed.shortcut) {//unpack if(ed.shortcut) {//unpack
const NodeID middle = ed.id; const NodeID middle_node_id = ed.id;
//again, we need to this in reversed order //again, we need to this in reversed order
recursionStack.push(std::make_pair(middle, edge.second)); recursion_stack.push(std::make_pair(middle_node_id, edge.second));
recursionStack.push(std::make_pair(edge.first, middle)); recursion_stack.push(std::make_pair(edge.first, middle_node_id));
} else { } else {
BOOST_ASSERT_MSG(!ed.shortcut, "edge must be shortcut"); BOOST_ASSERT_MSG(!ed.shortcut, "edge must be shortcut");
unpackedPath.push_back(edge.first ); unpacked_path.push_back(edge.first );
} }
} }
unpackedPath.push_back(t); unpacked_path.push_back(t);
} }
inline void RetrievePackedPathFromHeap( inline void RetrievePackedPathFromHeap(
SearchEngineData::QueryHeap & _fHeap, SearchEngineData::QueryHeap & forward_heap,
SearchEngineData::QueryHeap & _bHeap, SearchEngineData::QueryHeap & reverse_heap,
const NodeID middle, const NodeID middle_node_id,
std::vector<NodeID> & packedPath std::vector<NodeID> & packed_path
) const { ) const {
NodeID pathNode = middle; NodeID current_node_id = middle_node_id;
while(pathNode != _fHeap.GetData(pathNode).parent) { while(current_node_id != forward_heap.GetData(current_node_id).parent) {
pathNode = _fHeap.GetData(pathNode).parent; current_node_id = forward_heap.GetData(current_node_id).parent;
packedPath.push_back(pathNode); packed_path.push_back(current_node_id);
} }
std::reverse(packedPath.begin(), packedPath.end()); std::reverse(packed_path.begin(), packed_path.end());
packedPath.push_back(middle); packed_path.push_back(middle_node_id);
pathNode = middle; current_node_id = middle_node_id;
while (pathNode != _bHeap.GetData(pathNode).parent){ while (current_node_id != reverse_heap.GetData(current_node_id).parent){
pathNode = _bHeap.GetData(pathNode).parent; current_node_id = reverse_heap.GetData(current_node_id).parent;
packedPath.push_back(pathNode); packed_path.push_back(current_node_id);
} }
} }
inline void RetrievePackedPathFromSingleHeap(SearchEngineData::QueryHeap & search_heap, const NodeID middle, std::vector<NodeID>& packed_path) const { //TODO: reorder parameters
NodeID pathNode = middle; inline void RetrievePackedPathFromSingleHeap(
while(pathNode != search_heap.GetData(pathNode).parent) { SearchEngineData::QueryHeap & search_heap,
pathNode = search_heap.GetData(pathNode).parent; const NodeID middle_node_id,
packed_path.push_back(pathNode); std::vector<NodeID>& packed_path
) const {
NodeID current_node_id = middle_node_id;
while(current_node_id != search_heap.GetData(current_node_id).parent) {
current_node_id = search_heap.GetData(current_node_id).parent;
packed_path.push_back(current_node_id);
} }
} }
}; };
#endif /* BASICROUTINGINTERFACE_H_ */ #endif /* BASICROUTINGINTERFACE_H_ */