Refactoring shortest path search variable names
This commit is contained in:
parent
4520e04d37
commit
9812eaaca7
@ -32,27 +32,41 @@ class ShortestPathRouting : public BasicRoutingInterface<DataFacadeT>{
|
|||||||
typedef BasicRoutingInterface<DataFacadeT> super;
|
typedef BasicRoutingInterface<DataFacadeT> super;
|
||||||
typedef SearchEngineData::QueryHeap QueryHeap;
|
typedef SearchEngineData::QueryHeap QueryHeap;
|
||||||
SearchEngineData & engine_working_data;
|
SearchEngineData & engine_working_data;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ShortestPathRouting( DataFacadeT * facade, SearchEngineData & engine_working_data) : super(facade), engine_working_data(engine_working_data) {}
|
ShortestPathRouting(
|
||||||
|
DataFacadeT * facade,
|
||||||
|
SearchEngineData & engine_working_data
|
||||||
|
) :
|
||||||
|
super(facade),
|
||||||
|
engine_working_data(engine_working_data)
|
||||||
|
{}
|
||||||
|
|
||||||
~ShortestPathRouting() {}
|
~ShortestPathRouting() {}
|
||||||
|
|
||||||
void operator()(std::vector<PhantomNodes> & phantomNodesVector, RawRouteData & rawRouteData) const {
|
void operator()(
|
||||||
BOOST_FOREACH(const PhantomNodes & phantomNodePair, phantomNodesVector) {
|
std::vector<PhantomNodes> & phantom_nodes_vector,
|
||||||
if(!phantomNodePair.AtLeastOnePhantomNodeIsUINTMAX()) {
|
RawRouteData & raw_route_data
|
||||||
rawRouteData.lengthOfShortestPath = rawRouteData.lengthOfAlternativePath = INT_MAX;
|
) const {
|
||||||
|
BOOST_FOREACH(
|
||||||
|
const PhantomNodes & phantom_node_pair,
|
||||||
|
phantom_nodes_vector
|
||||||
|
){
|
||||||
|
if(!phantom_node_pair.AtLeastOnePhantomNodeIsUINTMAX()) {
|
||||||
|
raw_route_data.lengthOfShortestPath = INT_MAX;
|
||||||
|
raw_route_data.lengthOfAlternativePath = INT_MAX;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int distance1 = 0;
|
int distance1 = 0;
|
||||||
int distance2 = 0;
|
int distance2 = 0;
|
||||||
|
|
||||||
bool searchFrom1stStartNode = true;
|
bool search_from_1st_node = true;
|
||||||
bool searchFrom2ndStartNode = true;
|
bool search_from_2nd_node = true;
|
||||||
NodeID middle1 = UINT_MAX;
|
NodeID middle1 = UINT_MAX;
|
||||||
NodeID middle2 = UINT_MAX;
|
NodeID middle2 = UINT_MAX;
|
||||||
std::vector<NodeID> packedPath1;
|
std::vector<NodeID> packed_path1;
|
||||||
std::vector<NodeID> packedPath2;
|
std::vector<NodeID> packed_path2;
|
||||||
|
|
||||||
engine_working_data.InitializeOrClearFirstThreadLocalStorage(
|
engine_working_data.InitializeOrClearFirstThreadLocalStorage(
|
||||||
super::facade->GetNumberOfNodes()
|
super::facade->GetNumberOfNodes()
|
||||||
@ -70,139 +84,231 @@ public:
|
|||||||
QueryHeap & reverse_heap2 = *(engine_working_data.backwardHeap2);
|
QueryHeap & reverse_heap2 = *(engine_working_data.backwardHeap2);
|
||||||
|
|
||||||
//Get distance to next pair of target nodes.
|
//Get distance to next pair of target nodes.
|
||||||
BOOST_FOREACH(const PhantomNodes & phantomNodePair, phantomNodesVector) {
|
BOOST_FOREACH(const PhantomNodes & phantom_node_pair, phantom_nodes_vector){
|
||||||
forward_heap1.Clear(); forward_heap2.Clear();
|
forward_heap1.Clear(); forward_heap2.Clear();
|
||||||
reverse_heap1.Clear(); reverse_heap2.Clear();
|
reverse_heap1.Clear(); reverse_heap2.Clear();
|
||||||
int _localUpperbound1 = INT_MAX;
|
int local_upper_bound1 = INT_MAX;
|
||||||
int _localUpperbound2 = INT_MAX;
|
int local_upper_bound2 = INT_MAX;
|
||||||
|
|
||||||
middle1 = UINT_MAX;
|
middle1 = UINT_MAX;
|
||||||
middle2 = UINT_MAX;
|
middle2 = UINT_MAX;
|
||||||
|
|
||||||
//insert new starting nodes into forward heap, adjusted by previous distances.
|
//insert new starting nodes into forward heap, adjusted by previous distances.
|
||||||
if(searchFrom1stStartNode) {
|
if(search_from_1st_node) {
|
||||||
forward_heap1.Insert(phantomNodePair.startPhantom.edgeBasedNode, -phantomNodePair.startPhantom.weight1, phantomNodePair.startPhantom.edgeBasedNode);
|
forward_heap1.Insert(
|
||||||
// INFO("fw1: " << phantomNodePair.startPhantom.edgeBasedNode << "´, w: " << -phantomNodePair.startPhantom.weight1);
|
phantom_node_pair.startPhantom.edgeBasedNode,
|
||||||
forward_heap2.Insert(phantomNodePair.startPhantom.edgeBasedNode, -phantomNodePair.startPhantom.weight1, phantomNodePair.startPhantom.edgeBasedNode);
|
-phantom_node_pair.startPhantom.weight1,
|
||||||
// INFO("fw2: " << phantomNodePair.startPhantom.edgeBasedNode << "´, w: " << -phantomNodePair.startPhantom.weight1);
|
phantom_node_pair.startPhantom.edgeBasedNode
|
||||||
|
);
|
||||||
|
// INFO("fw1: " << phantom_node_pair.startPhantom.edgeBasedNode << "´, w: " << -phantom_node_pair.startPhantom.weight1);
|
||||||
|
forward_heap2.Insert(
|
||||||
|
phantom_node_pair.startPhantom.edgeBasedNode,
|
||||||
|
-phantom_node_pair.startPhantom.weight1,
|
||||||
|
phantom_node_pair.startPhantom.edgeBasedNode
|
||||||
|
);
|
||||||
|
// INFO("fw2: " << phantom_node_pair.startPhantom.edgeBasedNode << "´, w: " << -phantom_node_pair.startPhantom.weight1);
|
||||||
}
|
}
|
||||||
if(phantomNodePair.startPhantom.isBidirected() && searchFrom2ndStartNode) {
|
if(phantom_node_pair.startPhantom.isBidirected() && search_from_2nd_node) {
|
||||||
forward_heap1.Insert(phantomNodePair.startPhantom.edgeBasedNode+1, -phantomNodePair.startPhantom.weight2, phantomNodePair.startPhantom.edgeBasedNode+1);
|
forward_heap1.Insert(
|
||||||
// INFO("fw1: " << phantomNodePair.startPhantom.edgeBasedNode+1 << "´, w: " << -phantomNodePair.startPhantom.weight2);
|
phantom_node_pair.startPhantom.edgeBasedNode+1,
|
||||||
forward_heap2.Insert(phantomNodePair.startPhantom.edgeBasedNode+1, -phantomNodePair.startPhantom.weight2, phantomNodePair.startPhantom.edgeBasedNode+1);
|
-phantom_node_pair.startPhantom.weight2,
|
||||||
// INFO("fw2: " << phantomNodePair.startPhantom.edgeBasedNode+1 << "´, w: " << -phantomNodePair.startPhantom.weight2);
|
phantom_node_pair.startPhantom.edgeBasedNode+1
|
||||||
|
);
|
||||||
|
// INFO("fw1: " << phantom_node_pair.startPhantom.edgeBasedNode+1 << "´, w: " << -phantom_node_pair.startPhantom.weight2);
|
||||||
|
forward_heap2.Insert(
|
||||||
|
phantom_node_pair.startPhantom.edgeBasedNode+1,
|
||||||
|
-phantom_node_pair.startPhantom.weight2,
|
||||||
|
phantom_node_pair.startPhantom.edgeBasedNode+1
|
||||||
|
);
|
||||||
|
// INFO("fw2: " << phantom_node_pair.startPhantom.edgeBasedNode+1 << "´, w: " << -phantom_node_pair.startPhantom.weight2);
|
||||||
}
|
}
|
||||||
|
|
||||||
//insert new backward nodes into backward heap, unadjusted.
|
//insert new backward nodes into backward heap, unadjusted.
|
||||||
reverse_heap1.Insert(phantomNodePair.targetPhantom.edgeBasedNode, phantomNodePair.targetPhantom.weight1, phantomNodePair.targetPhantom.edgeBasedNode);
|
reverse_heap1.Insert(
|
||||||
// INFO("rv1: " << phantomNodePair.targetPhantom.edgeBasedNode << ", w;" << phantomNodePair.targetPhantom.weight1 );
|
phantom_node_pair.targetPhantom.edgeBasedNode,
|
||||||
if(phantomNodePair.targetPhantom.isBidirected() ) {
|
phantom_node_pair.targetPhantom.weight1,
|
||||||
reverse_heap2.Insert(phantomNodePair.targetPhantom.edgeBasedNode+1, phantomNodePair.targetPhantom.weight2, phantomNodePair.targetPhantom.edgeBasedNode+1);
|
phantom_node_pair.targetPhantom.edgeBasedNode
|
||||||
// INFO("rv2: " << phantomNodePair.targetPhantom.edgeBasedNode+1 << ", w;" << phantomNodePair.targetPhantom.weight2 );
|
);
|
||||||
|
// INFO("rv1: " << phantom_node_pair.targetPhantom.edgeBasedNode << ", w;" << phantom_node_pair.targetPhantom.weight1 );
|
||||||
|
if(phantom_node_pair.targetPhantom.isBidirected() ) {
|
||||||
|
reverse_heap2.Insert(
|
||||||
|
phantom_node_pair.targetPhantom.edgeBasedNode+1,
|
||||||
|
phantom_node_pair.targetPhantom.weight2,
|
||||||
|
phantom_node_pair.targetPhantom.edgeBasedNode+1
|
||||||
|
);
|
||||||
|
// INFO("rv2: " << phantom_node_pair.targetPhantom.edgeBasedNode+1 << ", w;" << phantom_node_pair.targetPhantom.weight2 );
|
||||||
}
|
}
|
||||||
const int forward_offset = phantomNodePair.startPhantom.weight1 + (phantomNodePair.startPhantom.isBidirected() ? phantomNodePair.startPhantom.weight2 : 0);
|
const int forward_offset = phantom_node_pair.startPhantom.weight1 + (phantom_node_pair.startPhantom.isBidirected() ? phantom_node_pair.startPhantom.weight2 : 0);
|
||||||
const int reverse_offset = phantomNodePair.targetPhantom.weight1 + (phantomNodePair.targetPhantom.isBidirected() ? phantomNodePair.targetPhantom.weight2 : 0);
|
const int reverse_offset = phantom_node_pair.targetPhantom.weight1 + (phantom_node_pair.targetPhantom.isBidirected() ? phantom_node_pair.targetPhantom.weight2 : 0);
|
||||||
|
|
||||||
//run two-Target Dijkstra routing step.
|
//run two-Target Dijkstra routing step.
|
||||||
while(0 < (forward_heap1.Size() + reverse_heap1.Size() )){
|
while(0 < (forward_heap1.Size() + reverse_heap1.Size() )){
|
||||||
if(0 < forward_heap1.Size()){
|
if( !forward_heap1.Empty()){
|
||||||
super::RoutingStep(forward_heap1, reverse_heap1, &middle1, &_localUpperbound1, forward_offset, true);
|
super::RoutingStep(
|
||||||
|
forward_heap1,
|
||||||
|
reverse_heap1,
|
||||||
|
&middle1,
|
||||||
|
&local_upper_bound1,
|
||||||
|
forward_offset,
|
||||||
|
true
|
||||||
|
);
|
||||||
}
|
}
|
||||||
if(0 < reverse_heap1.Size() ){
|
if( !reverse_heap1.Empty() ){
|
||||||
super::RoutingStep(reverse_heap1, forward_heap1, &middle1, &_localUpperbound1, reverse_offset, false);
|
super::RoutingStep(
|
||||||
|
reverse_heap1,
|
||||||
|
forward_heap1,
|
||||||
|
&middle1,
|
||||||
|
&local_upper_bound1,
|
||||||
|
reverse_offset,
|
||||||
|
false
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(0 < reverse_heap2.Size()) {
|
if( !reverse_heap2.Empty() ) {
|
||||||
while(0 < (forward_heap2.Size() + reverse_heap2.Size() )){
|
while(0 < (forward_heap2.Size() + reverse_heap2.Size() )){
|
||||||
if(0 < forward_heap2.Size()){
|
if( !forward_heap2.Empty() ){
|
||||||
super::RoutingStep(forward_heap2, reverse_heap2, &middle2, &_localUpperbound2, forward_offset, true);
|
super::RoutingStep(
|
||||||
|
forward_heap2,
|
||||||
|
reverse_heap2,
|
||||||
|
&middle2,
|
||||||
|
&local_upper_bound2,
|
||||||
|
forward_offset,
|
||||||
|
true
|
||||||
|
);
|
||||||
}
|
}
|
||||||
if(0 < reverse_heap2.Size()){
|
if( !reverse_heap2.Empty() ){
|
||||||
super::RoutingStep(reverse_heap2, forward_heap2, &middle2, &_localUpperbound2, reverse_offset, false);
|
super::RoutingStep(
|
||||||
|
reverse_heap2,
|
||||||
|
forward_heap2,
|
||||||
|
&middle2,
|
||||||
|
&local_upper_bound2,
|
||||||
|
reverse_offset,
|
||||||
|
false
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//No path found for both target nodes?
|
//No path found for both target nodes?
|
||||||
if((INT_MAX == _localUpperbound1) && (INT_MAX == _localUpperbound2)) {
|
if(
|
||||||
rawRouteData.lengthOfShortestPath = rawRouteData.lengthOfAlternativePath = INT_MAX;
|
(INT_MAX == local_upper_bound1) &&
|
||||||
|
(INT_MAX == local_upper_bound2)
|
||||||
|
) {
|
||||||
|
raw_route_data.lengthOfShortestPath = INT_MAX;
|
||||||
|
raw_route_data.lengthOfAlternativePath = INT_MAX;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(UINT_MAX == middle1) {
|
if(UINT_MAX == middle1) {
|
||||||
searchFrom1stStartNode = false;
|
search_from_1st_node = false;
|
||||||
}
|
}
|
||||||
if(UINT_MAX == middle2) {
|
if(UINT_MAX == middle2) {
|
||||||
searchFrom2ndStartNode = false;
|
search_from_2nd_node = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Was at most one of the two paths not found?
|
//Was at most one of the two paths not found?
|
||||||
assert(!(INT_MAX == distance1 && INT_MAX == distance2));
|
assert(INT_MAX != distance1 || INT_MAX != distance2);
|
||||||
|
|
||||||
//Unpack paths if they exist
|
//Unpack paths if they exist
|
||||||
std::vector<NodeID> temporaryPackedPath1;
|
std::vector<NodeID> temporary_packed_path1;
|
||||||
std::vector<NodeID> temporaryPackedPath2;
|
std::vector<NodeID> temporary_packed_path2;
|
||||||
if(INT_MAX != _localUpperbound1) {
|
if(INT_MAX != local_upper_bound1) {
|
||||||
super::RetrievePackedPathFromHeap(forward_heap1, reverse_heap1, middle1, temporaryPackedPath1);
|
super::RetrievePackedPathFromHeap(
|
||||||
|
forward_heap1,
|
||||||
|
reverse_heap1,
|
||||||
|
middle1,
|
||||||
|
temporary_packed_path1
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(INT_MAX != _localUpperbound2) {
|
if(INT_MAX != local_upper_bound2) {
|
||||||
super::RetrievePackedPathFromHeap(forward_heap2, reverse_heap2, middle2, temporaryPackedPath2);
|
super::RetrievePackedPathFromHeap(
|
||||||
|
forward_heap2,
|
||||||
|
reverse_heap2,
|
||||||
|
middle2,
|
||||||
|
temporary_packed_path2
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
//if one of the paths was not found, replace it with the other one.
|
//if one of the paths was not found, replace it with the other one.
|
||||||
if(0 == temporaryPackedPath1.size()) {
|
if( temporary_packed_path1.empty() ) {
|
||||||
temporaryPackedPath1.insert(temporaryPackedPath1.end(), temporaryPackedPath2.begin(), temporaryPackedPath2.end());
|
temporary_packed_path1.insert(
|
||||||
_localUpperbound1 = _localUpperbound2;
|
temporary_packed_path1.end(),
|
||||||
|
temporary_packed_path2.begin(),
|
||||||
|
temporary_packed_path2.end()
|
||||||
|
);
|
||||||
|
local_upper_bound1 = local_upper_bound2;
|
||||||
}
|
}
|
||||||
if(0 == temporaryPackedPath2.size()) {
|
if( temporary_packed_path2.empty() ) {
|
||||||
temporaryPackedPath2.insert(temporaryPackedPath2.end(), temporaryPackedPath1.begin(), temporaryPackedPath1.end());
|
temporary_packed_path2.insert(
|
||||||
_localUpperbound2 = _localUpperbound1;
|
temporary_packed_path2.end(),
|
||||||
|
temporary_packed_path1.begin(),
|
||||||
|
temporary_packed_path1.end()
|
||||||
|
);
|
||||||
|
local_upper_bound2 = local_upper_bound1;
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(0 < temporaryPackedPath1.size() && 0 < temporaryPackedPath2.size());
|
assert(temporary_packed_path1.empty() && temporary_packed_path2.empty());
|
||||||
|
|
||||||
//Plug paths together, s.t. end of packed path is begin of temporary packed path
|
//Plug paths together, s.t. end of packed path is begin of temporary packed path
|
||||||
if(0 < packedPath1.size() && 0 < packedPath2.size() ) {
|
if( !packed_path1.empty() && !packed_path2.empty() ) {
|
||||||
if( *(temporaryPackedPath1.begin()) == *(temporaryPackedPath2.begin())) {
|
if( temporary_packed_path1.front() == temporary_packed_path2.front() ) {
|
||||||
//both new route segments start with the same node, thus one of the packedPath must go.
|
//both new route segments start with the same node, thus one of the packedPath must go.
|
||||||
assert( (packedPath1.size() == packedPath2.size() ) || (*(packedPath1.end()-1) != *(packedPath2.end()-1)) );
|
assert( (packed_path1.size() == packed_path2.size() ) || (*(packed_path1.end()-1) != *(packed_path2.end()-1)) );
|
||||||
if( *(packedPath1.end()-1) == *(temporaryPackedPath1.begin())) {
|
if( packed_path1.back() == temporary_packed_path1.front()) {
|
||||||
packedPath2.clear();
|
packed_path2.clear();
|
||||||
packedPath2.insert(packedPath2.end(), packedPath1.begin(), packedPath1.end());
|
packed_path2.insert(
|
||||||
|
packed_path2.end(),
|
||||||
|
packed_path1.begin(),
|
||||||
|
packed_path1.end()
|
||||||
|
);
|
||||||
distance2 = distance1;
|
distance2 = distance1;
|
||||||
} else {
|
} else {
|
||||||
packedPath1.clear();
|
packed_path1.clear();
|
||||||
packedPath1.insert(packedPath1.end(), packedPath2.begin(), packedPath2.end());
|
packed_path1.insert(
|
||||||
|
packed_path1.end(),
|
||||||
|
packed_path2.begin(),
|
||||||
|
packed_path2.end()
|
||||||
|
);
|
||||||
distance1 = distance2;
|
distance1 = distance2;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
//packed paths 1 and 2 may need to switch.
|
//packed paths 1 and 2 may need to switch.
|
||||||
if(*(packedPath1.end()-1) != *(temporaryPackedPath1.begin())) {
|
if(packed_path1.back() != temporary_packed_path1.front()) {
|
||||||
packedPath1.swap(packedPath2);
|
packed_path1.swap(packed_path2);
|
||||||
std::swap(distance1, distance2);
|
std::swap(distance1, distance2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
packedPath1.insert(packedPath1.end(), temporaryPackedPath1.begin(), temporaryPackedPath1.end());
|
packed_path1.insert(
|
||||||
packedPath2.insert(packedPath2.end(), temporaryPackedPath2.begin(), temporaryPackedPath2.end());
|
packed_path1.end(),
|
||||||
|
temporary_packed_path1.begin(),
|
||||||
|
temporary_packed_path1.end()
|
||||||
|
);
|
||||||
|
packed_path2.insert(
|
||||||
|
packed_path2.end(),
|
||||||
|
temporary_packed_path2.begin(),
|
||||||
|
temporary_packed_path2.end()
|
||||||
|
);
|
||||||
|
|
||||||
if( (packedPath1.back() == packedPath2.back()) && phantomNodePair.targetPhantom.isBidirected() ) {
|
if(
|
||||||
|
(packed_path1.back() == packed_path2.back()) &&
|
||||||
NodeID lastNodeID = packedPath2.back();
|
phantom_node_pair.targetPhantom.isBidirected()
|
||||||
searchFrom1stStartNode &= !(lastNodeID == phantomNodePair.targetPhantom.edgeBasedNode+1);
|
) {
|
||||||
searchFrom2ndStartNode &= !(lastNodeID == phantomNodePair.targetPhantom.edgeBasedNode);
|
NodeID last_node_id = packed_path2.back();
|
||||||
|
search_from_1st_node &= !(last_node_id == phantom_node_pair.targetPhantom.edgeBasedNode+1);
|
||||||
|
search_from_2nd_node &= !(last_node_id == phantom_node_pair.targetPhantom.edgeBasedNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
distance1 += _localUpperbound1;
|
distance1 += local_upper_bound1;
|
||||||
distance2 += _localUpperbound2;
|
distance2 += local_upper_bound2;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(distance1 > distance2){
|
if( distance1 > distance2 ){
|
||||||
std::swap(packedPath1, packedPath2);
|
std::swap( packed_path1, packed_path2 );
|
||||||
}
|
}
|
||||||
remove_consecutive_duplicates_from_vector(packedPath1);
|
remove_consecutive_duplicates_from_vector(packed_path1);
|
||||||
super::UnpackPath(packedPath1, rawRouteData.computedShortestPath);
|
super::UnpackPath(packed_path1, raw_route_data.computedShortestPath);
|
||||||
rawRouteData.lengthOfShortestPath = std::min(distance1, distance2);
|
raw_route_data.lengthOfShortestPath = std::min(distance1, distance2);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user