minor simplification of code

This commit is contained in:
Dennis Luxen 2013-09-24 10:10:50 +02:00
parent 0977cabc79
commit 226dad651b
2 changed files with 53 additions and 31 deletions

View File

@ -372,7 +372,7 @@ private:
} }
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 EdgeData & data = facade->GetEdgeData(edge);
bool forwardDirectionFlag = (forwardDirection ? data.forward : data.backward ); bool forwardDirectionFlag = (forwardDirection ? data.forward : data.backward );
if(forwardDirectionFlag) { if(forwardDirectionFlag) {
@ -462,7 +462,7 @@ private:
EdgeID edgeIDInViaPath = facade->FindEdgeInEitherDirection(viaPathEdge.first, viaPathEdge.second); EdgeID edgeIDInViaPath = facade->FindEdgeInEitherDirection(viaPathEdge.first, viaPathEdge.second);
if(UINT_MAX == edgeIDInViaPath) if(UINT_MAX == edgeIDInViaPath)
return false; return false;
typename DataFacadeT::EdgeData currentEdgeData = facade->GetEdgeData(edgeIDInViaPath); EdgeData currentEdgeData = facade->GetEdgeData(edgeIDInViaPath);
bool IsViaEdgeShortCut = currentEdgeData.shortcut; bool IsViaEdgeShortCut = currentEdgeData.shortcut;
if (IsViaEdgeShortCut) { if (IsViaEdgeShortCut) {
const NodeID middleOfViaPath = currentEdgeData.id; const NodeID middleOfViaPath = currentEdgeData.id;
@ -503,7 +503,7 @@ private:
EdgeID edgeIDInViaPath = facade->FindEdgeInEitherDirection(viaPathEdge.first, viaPathEdge.second); EdgeID edgeIDInViaPath = facade->FindEdgeInEitherDirection(viaPathEdge.first, viaPathEdge.second);
if(UINT_MAX == edgeIDInViaPath) if(UINT_MAX == edgeIDInViaPath)
return false; return false;
typename DataFacadeT::EdgeData currentEdgeData = facade->GetEdgeData(edgeIDInViaPath); EdgeData currentEdgeData = facade->GetEdgeData(edgeIDInViaPath);
const bool IsViaEdgeShortCut = currentEdgeData.shortcut; const bool IsViaEdgeShortCut = currentEdgeData.shortcut;
if (IsViaEdgeShortCut) { if (IsViaEdgeShortCut) {
const NodeID middleOfViaPath = currentEdgeData.id; const NodeID middleOfViaPath = currentEdgeData.id;

View File

@ -4,7 +4,7 @@
This program is free software; you can redistribute it and/or modify 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 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 the Free Software Foundation; edge_idher version 3 of the License, or
any later version. any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
@ -44,6 +44,8 @@ SearchEngineData::SearchEngineHeapPtr SearchEngineData::backwardHeap3;
template<class DataFacadeT> template<class DataFacadeT>
class BasicRoutingInterface : boost::noncopyable { class BasicRoutingInterface : boost::noncopyable {
private:
typedef typename DataFacadeT::EdgeData EdgeData;
protected: protected:
DataFacadeT * facade; DataFacadeT * facade;
public: public:
@ -82,8 +84,8 @@ public:
edge < facade->EndEdges(node); edge < facade->EndEdges(node);
++edge ++edge
) { ) {
const typename DataFacadeT::EdgeData & data = facade->GetEdgeData(edge); const EdgeData & data = facade->GetEdgeData(edge);
bool reverse_flag = (!forward_direction) ? data.forward : data.backward; const bool reverse_flag = (!forward_direction) ? data.forward : data.backward;
if( reverse_flag ) { if( reverse_flag ) {
const NodeID to = facade->GetTarget(edge); const NodeID to = facade->GetTarget(edge);
const int edge_weight = data.distance; const int edge_weight = data.distance;
@ -98,8 +100,12 @@ public:
} }
} }
for ( EdgeID edge = facade->BeginEdges( node ); edge < facade->EndEdges(node); ++edge ) { for(
const typename DataFacadeT::EdgeData & data = facade->GetEdgeData(edge); EdgeID edge = facade->BeginEdges(node), end_edge = facade->EndEdges(node);
edge < end_edge;
++edge
) {
const EdgeData & data = facade->GetEdgeData(edge);
bool forward_directionFlag = (forward_direction ? data.forward : data.backward ); bool forward_directionFlag = (forward_direction ? data.forward : data.backward );
if( forward_directionFlag ) { if( forward_directionFlag ) {
@ -144,34 +150,42 @@ public:
EdgeID smaller_edge_id = SPECIAL_EDGEID; EdgeID smaller_edge_id = SPECIAL_EDGEID;
int edge_weight = INT_MAX; int edge_weight = INT_MAX;
for(EdgeID eit = facade->BeginEdges(edge.first);eit < facade->EndEdges(edge.first);++eit){ for(
const int weight = facade->GetEdgeData(eit).distance; EdgeID edge_id = facade->BeginEdges(edge.first);
edge_id < facade->EndEdges(edge.first);
++edge_id
){
const int weight = facade->GetEdgeData(edge_id).distance;
if( if(
(facade->GetTarget(eit) == edge.second) && (facade->GetTarget(edge_id) == edge.second) &&
(weight < edge_weight) && (weight < edge_weight) &&
facade->GetEdgeData(eit).forward facade->GetEdgeData(edge_id).forward
){ ){
smaller_edge_id = eit; smaller_edge_id = edge_id;
edge_weight = weight; edge_weight = weight;
} }
} }
if( SPECIAL_EDGEID == smaller_edge_id ){ if( SPECIAL_EDGEID == smaller_edge_id ){
for(EdgeID eit = facade->BeginEdges(edge.second); eit < facade->EndEdges(edge.second); ++eit){ for(
const int weight = facade->GetEdgeData(eit).distance; EdgeID edge_id = facade->BeginEdges(edge.second);
edge_id < facade->EndEdges(edge.second);
++edge_id
){
const int weight = facade->GetEdgeData(edge_id).distance;
if( if(
(facade->GetTarget(eit) == edge.first) && (facade->GetTarget(edge_id) == edge.first) &&
(weight < edge_weight) && (weight < edge_weight) &&
facade->GetEdgeData(eit).backward facade->GetEdgeData(edge_id).backward
){ ){
smaller_edge_id = eit; smaller_edge_id = edge_id;
edge_weight = weight; edge_weight = weight;
} }
} }
} }
BOOST_ASSERT_MSG(edge_weight != INT_MAX, "edge id invalid"); BOOST_ASSERT_MSG(edge_weight != INT_MAX, "edge id invalid");
const typename DataFacadeT::EdgeData& ed = facade->GetEdgeData(smaller_edge_id); const EdgeData& ed = facade->GetEdgeData(smaller_edge_id);
if( ed.shortcut ) {//unpack if( ed.shortcut ) {//unpack
const NodeID middle_node_id = 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
@ -206,34 +220,42 @@ public:
EdgeID smaller_edge_id = SPECIAL_EDGEID; EdgeID smaller_edge_id = SPECIAL_EDGEID;
int edge_weight = INT_MAX; int edge_weight = INT_MAX;
for(EdgeID eit = facade->BeginEdges(edge.first);eit < facade->EndEdges(edge.first);++eit){ for(
const int weight = facade->GetEdgeData(eit).distance; EdgeID edge_id = facade->BeginEdges(edge.first);
edge_id < facade->EndEdges(edge.first);
++edge_id
){
const int weight = facade->GetEdgeData(edge_id).distance;
if( if(
(facade->GetTarget(eit) == edge.second) && (facade->GetTarget(edge_id) == edge.second) &&
(weight < edge_weight) && (weight < edge_weight) &&
facade->GetEdgeData(eit).forward facade->GetEdgeData(edge_id).forward
){ ){
smaller_edge_id = eit; smaller_edge_id = edge_id;
edge_weight = weight; edge_weight = weight;
} }
} }
if( SPECIAL_EDGEID == smaller_edge_id ){ if( SPECIAL_EDGEID == smaller_edge_id ){
for(EdgeID eit = facade->BeginEdges(edge.second);eit < facade->EndEdges(edge.second);++eit){ for(
const int weight = facade->GetEdgeData(eit).distance; EdgeID edge_id = facade->BeginEdges(edge.second);
edge_id < facade->EndEdges(edge.second);
++edge_id
){
const int weight = facade->GetEdgeData(edge_id).distance;
if( if(
(facade->GetTarget(eit) == edge.first) && (facade->GetTarget(edge_id) == edge.first) &&
(weight < edge_weight) && (weight < edge_weight) &&
facade->GetEdgeData(eit).backward facade->GetEdgeData(edge_id).backward
){ ){
smaller_edge_id = eit; smaller_edge_id = edge_id;
edge_weight = weight; edge_weight = weight;
} }
} }
} }
BOOST_ASSERT_MSG(edge_weight != INT_MAX, "edge weight invalid"); BOOST_ASSERT_MSG(edge_weight != INT_MAX, "edge weight invalid");
const typename DataFacadeT::EdgeData& ed = facade->GetEdgeData(smaller_edge_id); const EdgeData& ed = facade->GetEdgeData(smaller_edge_id);
if(ed.shortcut) {//unpack if(ed.shortcut) {//unpack
const NodeID middle_node_id = 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