2012-06-15 12:47:27 -04:00
|
|
|
/*
|
|
|
|
|
2013-10-14 07:42:28 -04:00
|
|
|
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without modification,
|
|
|
|
are permitted provided that the following conditions are met:
|
|
|
|
|
|
|
|
Redistributions of source code must retain the above copyright notice, this list
|
|
|
|
of conditions and the following disclaimer.
|
|
|
|
Redistributions in binary form must reproduce the above copyright notice, this
|
|
|
|
list of conditions and the following disclaimer in the documentation and/or
|
|
|
|
other materials provided with the distribution.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
|
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
|
|
|
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
|
|
|
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
*/
|
2012-06-15 12:47:27 -04:00
|
|
|
|
|
|
|
#ifndef BASICROUTINGINTERFACE_H_
|
|
|
|
#define BASICROUTINGINTERFACE_H_
|
|
|
|
|
2013-08-14 07:41:23 -04:00
|
|
|
#include "../DataStructures/RawRouteData.h"
|
2013-09-19 12:53:34 -04:00
|
|
|
#include "../DataStructures/SearchEngineData.h"
|
2014-02-11 05:42:24 -05:00
|
|
|
#include "../DataStructures/TurnInstructions.h"
|
2013-06-24 14:12:34 -04:00
|
|
|
#include "../Util/ContainerUtils.h"
|
2013-08-08 08:17:01 -04:00
|
|
|
#include "../Util/SimpleLogger.h"
|
2013-06-24 14:12:34 -04:00
|
|
|
|
2013-09-20 05:35:59 -04:00
|
|
|
#include <boost/assert.hpp>
|
2014-02-11 05:42:24 -05:00
|
|
|
#include <boost/foreach.hpp>
|
2013-02-03 10:47:32 -05:00
|
|
|
#include <boost/noncopyable.hpp>
|
|
|
|
|
2012-06-15 12:47:27 -04:00
|
|
|
#include <climits>
|
|
|
|
|
2013-06-24 14:12:34 -04:00
|
|
|
#include <stack>
|
2012-06-19 11:26:34 -04:00
|
|
|
|
2013-09-24 03:55:02 -04:00
|
|
|
SearchEngineData::SearchEngineHeapPtr SearchEngineData::forwardHeap;
|
|
|
|
SearchEngineData::SearchEngineHeapPtr SearchEngineData::backwardHeap;
|
|
|
|
SearchEngineData::SearchEngineHeapPtr SearchEngineData::forwardHeap2;
|
|
|
|
SearchEngineData::SearchEngineHeapPtr SearchEngineData::backwardHeap2;
|
|
|
|
SearchEngineData::SearchEngineHeapPtr SearchEngineData::forwardHeap3;
|
|
|
|
SearchEngineData::SearchEngineHeapPtr SearchEngineData::backwardHeap3;
|
|
|
|
|
2013-09-20 05:09:07 -04:00
|
|
|
template<class DataFacadeT>
|
2013-09-20 07:08:18 -04:00
|
|
|
class BasicRoutingInterface : boost::noncopyable {
|
2013-09-24 04:10:50 -04:00
|
|
|
private:
|
|
|
|
typedef typename DataFacadeT::EdgeData EdgeData;
|
2012-06-15 12:47:27 -04:00
|
|
|
protected:
|
2013-09-20 05:09:07 -04:00
|
|
|
DataFacadeT * facade;
|
2012-06-15 12:47:27 -04:00
|
|
|
public:
|
2014-04-16 10:21:16 -04:00
|
|
|
explicit BasicRoutingInterface( DataFacadeT * facade ) : facade(facade) { }
|
2012-06-15 12:47:27 -04:00
|
|
|
virtual ~BasicRoutingInterface(){ };
|
|
|
|
|
2013-09-19 12:53:34 -04:00
|
|
|
inline void RoutingStep(
|
2013-09-20 07:08:18 -04:00
|
|
|
SearchEngineData::QueryHeap & forward_heap,
|
|
|
|
SearchEngineData::QueryHeap & reverse_heap,
|
|
|
|
NodeID * middle_node_id,
|
|
|
|
int * upper_bound,
|
|
|
|
const int edge_expansion_offset,
|
|
|
|
const bool forward_direction
|
2013-09-19 12:53:34 -04:00
|
|
|
) const {
|
2013-09-20 07:08:18 -04:00
|
|
|
const NodeID node = forward_heap.DeleteMin();
|
|
|
|
const int distance = forward_heap.GetKey(node);
|
2014-02-28 11:14:38 -05:00
|
|
|
// SimpleLogger().Write() << (forward_direction ? "fwd" : "rev") << " settled (" << forward_heap.GetData( node ).parent << "," << node << ")=" << distance;
|
2013-09-20 07:08:18 -04:00
|
|
|
if(reverse_heap.WasInserted(node) ){
|
|
|
|
const int new_distance = reverse_heap.GetKey(node) + distance;
|
|
|
|
if(new_distance < *upper_bound ){
|
|
|
|
if( new_distance >= 0 ) {
|
|
|
|
*middle_node_id = node;
|
|
|
|
*upper_bound = new_distance;
|
2012-06-15 12:47:27 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-20 07:11:23 -04:00
|
|
|
if( (distance-edge_expansion_offset) > *upper_bound ){
|
2013-09-20 07:08:18 -04:00
|
|
|
forward_heap.DeleteAll();
|
2012-06-15 12:47:27 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-02-03 10:47:32 -05:00
|
|
|
//Stalling
|
2013-09-19 12:53:34 -04:00
|
|
|
for(
|
2013-09-20 05:09:07 -04:00
|
|
|
EdgeID edge = facade->BeginEdges( node );
|
|
|
|
edge < facade->EndEdges(node);
|
2013-09-19 12:53:34 -04:00
|
|
|
++edge
|
|
|
|
) {
|
2013-09-24 04:10:50 -04:00
|
|
|
const EdgeData & data = facade->GetEdgeData(edge);
|
|
|
|
const bool reverse_flag = (!forward_direction) ? data.forward : data.backward;
|
2013-09-20 07:11:23 -04:00
|
|
|
if( reverse_flag ) {
|
2013-09-20 05:09:07 -04:00
|
|
|
const NodeID to = facade->GetTarget(edge);
|
2013-09-20 07:08:18 -04:00
|
|
|
const int edge_weight = data.distance;
|
2012-06-15 12:47:27 -04:00
|
|
|
|
2013-09-20 07:08:18 -04:00
|
|
|
BOOST_ASSERT_MSG( edge_weight > 0, "edge_weight invalid" );
|
2012-06-15 12:47:27 -04:00
|
|
|
|
2013-09-20 07:08:18 -04:00
|
|
|
if(forward_heap.WasInserted( to )) {
|
|
|
|
if(forward_heap.GetKey( to ) + edge_weight < distance) {
|
2012-06-15 12:47:27 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-24 04:10:50 -04:00
|
|
|
for(
|
|
|
|
EdgeID edge = facade->BeginEdges(node), end_edge = facade->EndEdges(node);
|
|
|
|
edge < end_edge;
|
|
|
|
++edge
|
|
|
|
) {
|
|
|
|
const EdgeData & data = facade->GetEdgeData(edge);
|
2013-09-20 07:08:18 -04:00
|
|
|
bool forward_directionFlag = (forward_direction ? data.forward : data.backward );
|
2013-09-20 07:11:23 -04:00
|
|
|
if( forward_directionFlag ) {
|
2012-06-15 12:47:27 -04:00
|
|
|
|
2013-09-20 05:09:07 -04:00
|
|
|
const NodeID to = facade->GetTarget(edge);
|
2013-09-20 07:08:18 -04:00
|
|
|
const int edge_weight = data.distance;
|
2012-06-15 12:47:27 -04:00
|
|
|
|
2013-09-20 07:08:18 -04:00
|
|
|
BOOST_ASSERT_MSG( edge_weight > 0, "edge_weight invalid" );
|
|
|
|
const int to_distance = distance + edge_weight;
|
2012-06-15 12:47:27 -04:00
|
|
|
|
|
|
|
//New Node discovered -> Add to Heap + Node Info Storage
|
2013-09-20 07:08:18 -04:00
|
|
|
if ( !forward_heap.WasInserted( to ) ) {
|
|
|
|
forward_heap.Insert( to, to_distance, node );
|
2012-06-15 12:47:27 -04:00
|
|
|
}
|
|
|
|
//Found a shorter Path -> Update distance
|
2013-09-20 07:08:18 -04:00
|
|
|
else if ( to_distance < forward_heap.GetKey( to ) ) {
|
|
|
|
forward_heap.GetData( to ).parent = node;
|
|
|
|
forward_heap.DecreaseKey( to, to_distance );
|
2012-06-15 12:47:27 -04:00
|
|
|
//new parent
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-28 11:14:38 -05:00
|
|
|
|
|
|
|
//TODO: refactor parameters to only edge ids for start and end
|
2013-09-20 07:08:18 -04:00
|
|
|
inline void UnpackPath(
|
|
|
|
const std::vector<NodeID> & packed_path,
|
2014-02-28 11:14:38 -05:00
|
|
|
const int fwd_index_offset,
|
|
|
|
const bool start_traversed_in_reverse,
|
|
|
|
const unsigned packed_geometry_id_of_last_edge,
|
|
|
|
const int rev_index_offset,
|
|
|
|
const bool target_traversed_in_reverse,
|
2013-12-08 13:10:10 -05:00
|
|
|
std::vector<PathData> & unpacked_path
|
2013-09-20 07:08:18 -04:00
|
|
|
) const {
|
|
|
|
const unsigned packed_path_size = packed_path.size();
|
|
|
|
std::stack<std::pair<NodeID, NodeID> > recursion_stack;
|
2012-06-15 12:47:27 -04:00
|
|
|
|
|
|
|
//We have to push the path in reverse order onto the stack because it's LIFO.
|
2013-09-20 07:08:18 -04:00
|
|
|
for(unsigned i = packed_path_size-1; i > 0; --i){
|
2013-09-20 12:30:47 -04:00
|
|
|
recursion_stack.push(
|
|
|
|
std::make_pair(packed_path[i-1], packed_path[i])
|
|
|
|
);
|
2012-06-15 12:47:27 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
std::pair<NodeID, NodeID> edge;
|
2013-09-20 07:08:18 -04:00
|
|
|
while(!recursion_stack.empty()) {
|
2014-02-27 13:49:53 -05:00
|
|
|
// bool segment_reversed = false;
|
2013-09-20 07:08:18 -04:00
|
|
|
edge = recursion_stack.top();
|
|
|
|
recursion_stack.pop();
|
2012-06-15 12:47:27 -04:00
|
|
|
|
2014-02-27 13:49:53 -05:00
|
|
|
// facade->FindEdge does not suffice here in case of shortcuts.
|
|
|
|
// The above explanation unclear? Think!
|
|
|
|
EdgeID smaller_edge_id = SPECIAL_EDGEID;
|
|
|
|
int edge_weight = INT_MAX;
|
|
|
|
for(
|
|
|
|
EdgeID edge_id = facade->BeginEdges(edge.first);
|
|
|
|
edge_id < facade->EndEdges(edge.first);
|
|
|
|
++edge_id
|
|
|
|
){
|
|
|
|
const int weight = facade->GetEdgeData(edge_id).distance;
|
|
|
|
if(
|
|
|
|
(facade->GetTarget(edge_id) == edge.second) &&
|
|
|
|
(weight < edge_weight) &&
|
|
|
|
facade->GetEdgeData(edge_id).forward
|
|
|
|
){
|
|
|
|
smaller_edge_id = edge_id;
|
|
|
|
edge_weight = weight;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if( SPECIAL_EDGEID == smaller_edge_id ){
|
|
|
|
for(
|
|
|
|
EdgeID edge_id = facade->BeginEdges(edge.second);
|
|
|
|
edge_id < facade->EndEdges(edge.second);
|
|
|
|
++edge_id
|
|
|
|
){
|
|
|
|
const int weight = facade->GetEdgeData(edge_id).distance;
|
|
|
|
if(
|
|
|
|
(facade->GetTarget(edge_id) == edge.first) &&
|
|
|
|
(weight < edge_weight) &&
|
|
|
|
facade->GetEdgeData(edge_id).backward
|
|
|
|
){
|
|
|
|
smaller_edge_id = edge_id;
|
|
|
|
edge_weight = weight;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
BOOST_ASSERT_MSG(edge_weight != INT_MAX, "edge id invalid");
|
2012-06-15 12:47:27 -04:00
|
|
|
|
2014-02-27 13:49:53 -05:00
|
|
|
|
|
|
|
BOOST_ASSERT( facade->EndEdges(edge.first) != smaller_edge_id );
|
2012-06-15 12:47:27 -04:00
|
|
|
|
2013-09-24 04:10:50 -04:00
|
|
|
const EdgeData& ed = facade->GetEdgeData(smaller_edge_id);
|
2013-09-20 07:13:06 -04:00
|
|
|
if( ed.shortcut ) {//unpack
|
2013-09-20 07:08:18 -04:00
|
|
|
const NodeID middle_node_id = ed.id;
|
2012-06-15 12:47:27 -04:00
|
|
|
//again, we need to this in reversed order
|
2013-09-20 07:08:18 -04:00
|
|
|
recursion_stack.push(std::make_pair(middle_node_id, edge.second));
|
|
|
|
recursion_stack.push(std::make_pair(edge.first, middle_node_id));
|
2012-06-15 12:47:27 -04:00
|
|
|
} else {
|
2014-02-11 05:42:24 -05:00
|
|
|
BOOST_ASSERT_MSG(!ed.shortcut, "original edge flagged as shortcut");
|
|
|
|
unsigned name_index = facade->GetNameIndexFromEdgeID(ed.id);
|
2014-02-26 09:55:04 -05:00
|
|
|
const TurnInstruction turn_instruction = facade->GetTurnInstructionForEdgeID(ed.id);
|
2014-02-21 10:55:41 -05:00
|
|
|
|
2014-02-11 05:42:24 -05:00
|
|
|
if ( !facade->EdgeIsCompressed(ed.id) ){
|
|
|
|
BOOST_ASSERT( !facade->EdgeIsCompressed(ed.id) );
|
|
|
|
unpacked_path.push_back(
|
|
|
|
PathData(
|
|
|
|
facade->GetGeometryIndexForEdgeID(ed.id),
|
|
|
|
name_index,
|
|
|
|
turn_instruction,
|
|
|
|
ed.distance
|
|
|
|
)
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
std::vector<unsigned> id_vector;
|
2014-02-28 11:14:38 -05:00
|
|
|
facade->GetUncompressedGeometry(facade->GetGeometryIndexForEdgeID(ed.id), id_vector);
|
2014-02-11 05:42:24 -05:00
|
|
|
|
2014-02-27 13:49:53 -05:00
|
|
|
const int start_index = ( unpacked_path.empty() ? ( ( start_traversed_in_reverse ) ? id_vector.size() - fwd_index_offset - 1 : fwd_index_offset ) : 0 );
|
|
|
|
const int end_index = id_vector.size();
|
|
|
|
|
|
|
|
BOOST_ASSERT( start_index >= 0 );
|
|
|
|
BOOST_ASSERT( start_index <= end_index );
|
|
|
|
for(
|
|
|
|
unsigned i = start_index;
|
|
|
|
i < end_index;
|
|
|
|
++i
|
|
|
|
) {
|
|
|
|
unpacked_path.push_back(
|
|
|
|
PathData(
|
|
|
|
id_vector[i],
|
|
|
|
name_index,
|
|
|
|
TurnInstructionsClass::NoTurn,
|
|
|
|
0
|
|
|
|
)
|
|
|
|
);
|
2014-02-11 05:42:24 -05:00
|
|
|
}
|
2014-02-27 13:49:53 -05:00
|
|
|
unpacked_path.back().turnInstruction = turn_instruction;
|
|
|
|
unpacked_path.back().durationOfSegment = ed.distance;
|
2014-02-11 05:42:24 -05:00
|
|
|
}
|
2012-06-15 12:47:27 -04:00
|
|
|
}
|
|
|
|
}
|
2014-02-28 11:14:38 -05:00
|
|
|
if(SPECIAL_EDGEID != packed_geometry_id_of_last_edge) {
|
|
|
|
SimpleLogger().Write(logDEBUG) << "unpacking last segment " << packed_geometry_id_of_last_edge;
|
|
|
|
std::vector<unsigned> id_vector;
|
|
|
|
facade->GetUncompressedGeometry(packed_geometry_id_of_last_edge, id_vector);
|
|
|
|
const int start_index = 0;
|
|
|
|
const int end_index = rev_index_offset;
|
|
|
|
|
|
|
|
BOOST_ASSERT( start_index >= 0 );
|
|
|
|
BOOST_ASSERT( start_index <= end_index );
|
|
|
|
for(
|
|
|
|
unsigned i = start_index;
|
|
|
|
i < end_index;
|
|
|
|
++i
|
|
|
|
) {
|
|
|
|
SimpleLogger().Write(logDEBUG) << facade->GetCoordinateOfNode(id_vector[i]);
|
|
|
|
unpacked_path.push_back(
|
|
|
|
PathData(
|
|
|
|
id_vector[i],
|
|
|
|
0,
|
|
|
|
TurnInstructionsClass::NoTurn,
|
|
|
|
0
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2012-06-15 12:47:27 -04:00
|
|
|
}
|
|
|
|
|
2013-09-20 07:08:18 -04:00
|
|
|
inline void UnpackEdge(
|
|
|
|
const NodeID s,
|
|
|
|
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));
|
2012-06-21 06:27:43 -04:00
|
|
|
|
|
|
|
std::pair<NodeID, NodeID> edge;
|
2013-09-20 07:08:18 -04:00
|
|
|
while(!recursion_stack.empty()) {
|
|
|
|
edge = recursion_stack.top();
|
|
|
|
recursion_stack.pop();
|
2012-06-21 06:27:43 -04:00
|
|
|
|
2013-09-20 07:08:18 -04:00
|
|
|
EdgeID smaller_edge_id = SPECIAL_EDGEID;
|
|
|
|
int edge_weight = INT_MAX;
|
2013-09-24 04:10:50 -04:00
|
|
|
for(
|
|
|
|
EdgeID edge_id = facade->BeginEdges(edge.first);
|
|
|
|
edge_id < facade->EndEdges(edge.first);
|
|
|
|
++edge_id
|
|
|
|
){
|
|
|
|
const int weight = facade->GetEdgeData(edge_id).distance;
|
2013-09-20 07:08:18 -04:00
|
|
|
if(
|
2013-09-24 04:10:50 -04:00
|
|
|
(facade->GetTarget(edge_id) == edge.second) &&
|
2013-09-20 07:08:18 -04:00
|
|
|
(weight < edge_weight) &&
|
2013-09-24 04:10:50 -04:00
|
|
|
facade->GetEdgeData(edge_id).forward
|
2013-09-20 07:08:18 -04:00
|
|
|
){
|
2013-09-24 04:10:50 -04:00
|
|
|
smaller_edge_id = edge_id;
|
2013-09-20 07:08:18 -04:00
|
|
|
edge_weight = weight;
|
2012-06-21 06:27:43 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-20 07:11:23 -04:00
|
|
|
if( SPECIAL_EDGEID == smaller_edge_id ){
|
2013-09-24 04:10:50 -04:00
|
|
|
for(
|
|
|
|
EdgeID edge_id = facade->BeginEdges(edge.second);
|
|
|
|
edge_id < facade->EndEdges(edge.second);
|
|
|
|
++edge_id
|
|
|
|
){
|
|
|
|
const int weight = facade->GetEdgeData(edge_id).distance;
|
2013-09-20 07:08:18 -04:00
|
|
|
if(
|
2013-09-24 04:10:50 -04:00
|
|
|
(facade->GetTarget(edge_id) == edge.first) &&
|
2013-09-20 07:08:18 -04:00
|
|
|
(weight < edge_weight) &&
|
2013-09-24 04:10:50 -04:00
|
|
|
facade->GetEdgeData(edge_id).backward
|
2013-09-20 07:08:18 -04:00
|
|
|
){
|
2013-09-24 04:10:50 -04:00
|
|
|
smaller_edge_id = edge_id;
|
2013-09-20 07:08:18 -04:00
|
|
|
edge_weight = weight;
|
2012-06-21 06:27:43 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-09-20 07:08:18 -04:00
|
|
|
BOOST_ASSERT_MSG(edge_weight != INT_MAX, "edge weight invalid");
|
2012-06-21 06:27:43 -04:00
|
|
|
|
2013-09-24 04:10:50 -04:00
|
|
|
const EdgeData& ed = facade->GetEdgeData(smaller_edge_id);
|
2012-06-21 06:27:43 -04:00
|
|
|
if(ed.shortcut) {//unpack
|
2013-09-20 07:08:18 -04:00
|
|
|
const NodeID middle_node_id = ed.id;
|
2012-06-21 06:27:43 -04:00
|
|
|
//again, we need to this in reversed order
|
2013-09-20 07:09:33 -04:00
|
|
|
recursion_stack.push(
|
|
|
|
std::make_pair(middle_node_id, edge.second)
|
|
|
|
);
|
|
|
|
recursion_stack.push(
|
|
|
|
std::make_pair(edge.first, middle_node_id)
|
|
|
|
);
|
2012-06-21 06:27:43 -04:00
|
|
|
} else {
|
2013-09-20 05:35:59 -04:00
|
|
|
BOOST_ASSERT_MSG(!ed.shortcut, "edge must be shortcut");
|
2013-09-20 07:08:18 -04:00
|
|
|
unpacked_path.push_back(edge.first );
|
2012-06-21 06:27:43 -04:00
|
|
|
}
|
|
|
|
}
|
2013-09-20 07:08:18 -04:00
|
|
|
unpacked_path.push_back(t);
|
2012-06-21 06:27:43 -04:00
|
|
|
}
|
|
|
|
|
2013-09-19 12:53:34 -04:00
|
|
|
inline void RetrievePackedPathFromHeap(
|
2014-02-26 09:55:04 -05:00
|
|
|
const SearchEngineData::QueryHeap & forward_heap,
|
|
|
|
const SearchEngineData::QueryHeap & reverse_heap,
|
2013-09-20 07:08:18 -04:00
|
|
|
const NodeID middle_node_id,
|
|
|
|
std::vector<NodeID> & packed_path
|
2013-09-19 12:53:34 -04:00
|
|
|
) const {
|
2013-09-20 07:08:18 -04:00
|
|
|
NodeID current_node_id = middle_node_id;
|
|
|
|
while(current_node_id != forward_heap.GetData(current_node_id).parent) {
|
|
|
|
current_node_id = forward_heap.GetData(current_node_id).parent;
|
|
|
|
packed_path.push_back(current_node_id);
|
2012-06-15 12:47:27 -04:00
|
|
|
}
|
2014-02-28 11:14:38 -05:00
|
|
|
SimpleLogger().Write() << "parent of last node. " << forward_heap.GetData(current_node_id).parent;
|
2013-09-20 07:08:18 -04:00
|
|
|
std::reverse(packed_path.begin(), packed_path.end());
|
|
|
|
packed_path.push_back(middle_node_id);
|
|
|
|
current_node_id = middle_node_id;
|
|
|
|
while (current_node_id != reverse_heap.GetData(current_node_id).parent){
|
|
|
|
current_node_id = reverse_heap.GetData(current_node_id).parent;
|
|
|
|
packed_path.push_back(current_node_id);
|
2012-09-27 13:46:44 -04:00
|
|
|
}
|
2014-02-27 13:49:53 -05:00
|
|
|
|
2014-02-28 11:14:38 -05:00
|
|
|
SimpleLogger().Write(logDEBUG) << "packed path";
|
2014-02-27 13:49:53 -05:00
|
|
|
BOOST_FOREACH(NodeID node, packed_path) {
|
|
|
|
SimpleLogger().Write(logDEBUG) << "node: " << node;
|
|
|
|
}
|
2012-06-15 12:47:27 -04:00
|
|
|
}
|
2013-02-03 10:47:32 -05:00
|
|
|
|
2013-09-20 07:08:18 -04:00
|
|
|
//TODO: reorder parameters
|
|
|
|
inline void RetrievePackedPathFromSingleHeap(
|
|
|
|
SearchEngineData::QueryHeap & search_heap,
|
|
|
|
const NodeID middle_node_id,
|
|
|
|
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);
|
2013-02-03 10:47:32 -05:00
|
|
|
}
|
|
|
|
}
|
2013-09-24 04:57:54 -04:00
|
|
|
|
|
|
|
int ComputeEdgeOffset(const PhantomNode & phantom) const {
|
2014-02-11 05:42:24 -05:00
|
|
|
return phantom.forward_weight + (phantom.isBidirected() ? phantom.reverse_weight : 0);
|
2013-09-24 04:57:54 -04:00
|
|
|
}
|
|
|
|
|
2012-06-15 12:47:27 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* BASICROUTINGINTERFACE_H_ */
|